Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Custom workflow Unit test using Rhino mocks

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

  • JordiMontana Profile Picture
    JordiMontana 326 on at
    RE: Custom workflow Unit test using Rhino mocks

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom workflow Unit test using Rhino mocks

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

  • Suggested answer
    balakrishna uppala Profile Picture
    balakrishna uppala 570 on at
    RE: Custom workflow Unit test using Rhino mocks

    Thanks Scott, its working.

  • balakrishna uppala Profile Picture
    balakrishna uppala 570 on at
    RE: Custom workflow Unit test using Rhino mocks

    Thanks Jordi for ur reply!!

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom workflow Unit test using Rhino mocks

    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

  • Suggested answer
    JordiMontana Profile Picture
    JordiMontana 326 on at
    RE: Custom workflow Unit test using Rhino mocks

    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

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: Custom workflow Unit test using Rhino mocks

    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);

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans