web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Custom workflow Unit test using Rhino mocks

(0) ShareShare
ReportReport
Posted on by 570

Hi All,

Can some one help me in unit testing custom workflow using Rhino mocks.

1. How to mock CodeActivityContext?

2. How to call Protected Execute method()?

When I try to mock CodeActivityContext, I got error as

"Can not instantiate proxy of class: System.Activities.CodeActivityContext.

Could not find a parameterless constructor."

If you have any related blogs please let me know.

Regards

Krishna

 

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    You don't actually need to call the Execute - you can use the WorkflowInvoker class with WorkflowInvoker.Invoke(inputArgs)

    The CodeActivityContext is then created for you. You can add the Tracing, Factor and WorkflowContext to the Extensions:

    // IWorkflowContext

    WorkflowContext = MockRepository.GenerateStub<IWorkflowContext>();

    WorkflowContext.Stub(x => x.Depth).Return(depth);

    // Workflow Invoker

    WorkFlowInvoker = new WorkflowInvoker(wf);

    WorkFlowInvoker.Extensions.Add<ITracingService>(() => TracingService);

    WorkFlowInvoker.Extensions.Add<IOrganizationServiceFactory>(() => Factory);

    WorkFlowInvoker.Extensions.Add<IWorkflowContext>(() => WorkflowContext);

  • Suggested answer
    JordiMontana Profile Picture
    326 on at

    Did you try FakeXrmEasy? It will save you some precious time cause it mocks codeactivity and plugin execution for you, queries, and many CRM messages. You can literally execute a codeactivity in one line of code.

    github.com/.../fake-xrm-easy

  • Community Member Profile Picture
    on at

    Hello Bala

    I would like to recommend Tenfold for this integration.

    Our company Tenfold supports integration for MS Dynamics. Our CTI solution offers various functions to help you automate your sales call workflow like click to dial, call logging, easy task creation, among others. You can read more about the benefits of a Tenfold integration here: www.tenfold.com/.../dynamics

  • balakrishna uppala Profile Picture
    570 on at

    Thanks Jordi for ur reply!!

    In my project we are using Rhino mocks, so I cannot use this.

  • Suggested answer
    balakrishna uppala Profile Picture
    570 on at

    Thanks Scott, its working.

  • Community Member Profile Picture
    on at

    If I am passing the code activity context to a class constructor how to mock the code activity context ??

  • JordiMontana Profile Picture
    326 on at

    Rahul, if helps, this is an example with FakeXrmEasy where CodeActivityContext is already mocked for you and you just have to execute it in one line of code:

    github.com/.../FakeContextTestCodeActivities.cs

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans