chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi,
I have been trying for days / weeks now to be able to unit test a SharePoint Workflow.
Here is the difficulty.

Dll: Microsoft.SharePoint
I need to mock the Microsoft.SharePoint.Workflow.ISharePointService and it's events. In order to "raise" the event, I need to produce the proper EventArg, namely SPActivationEventArgs

One of the hurdles I have encountered, the object I am trying to Mock has this signature
public class SPActivationEventArgs : ExternalDataEventArgs
{
internal SPActivationEventArgs(SPWinOeWorkflow workflow, SPWorkflowEvent workflowEvent, IPendingWork workHandler, object workItem) : base(workflow.InstanceId, workHandler, workItem)
}

The base class actually has 3 contructors, on of them which interest me is base(Guid instanceId)

Is there a way to "override" the call the constructor or call the base ctor of my choice ?

Thanks in advanced
asked by bobbyangers (2.1k points)

2 Answers

0 votes
Hi,

I'm not sure i fully understood,
but if what you want is to create a "fake" SPActivationEventArgs object.
the isolator can do it easily:
SPActivationEventArgs target = RecorderManager.CreateMockedObject<SPActivationEventArgs>();


This will also allow you to define the behavior you wont out of this instance (just record the needed expectations) and pass it to the methods which need to be used.

:!: when you create an object in such a way its real constructor is not activated. so trying to use it normally can result in unexpected behavior.

I hope this is what you need, so if its not just let me know and we shall try to find a different solution.

Note that you can click the following link to learn more on How to use sharepoint!
answered by lior (13.2k points)
0 votes
This is a great question. 8)

Here is how Typemock works. (When creating a sealed class)
:arrow: By Default when creating a mocked sealed object Typemock will call the constructor with the least arguments
:arrow: Nulls and default values will be passed to that constructor
:arrow: The actual constructor code will be faked

In order to override this behavior, use the explicit API of CreateMockedObject:
Guid guidForTest = ...;

SPActivationEventArgs fakeEventArgs = 
  RecorderManager.CreateMockedObject<SPActivationEventArgs>(
    Constructor.NotMocked,        // Call the real constructor
    guidForTest                   // pass first arg to constuctor
  );
answered by eli (5.7k points)
...