Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to Mock OrganizationServiceContext in dynamics 365 workflow

Posted on by Microsoft Employee

I have used LINQ query to fetch the records in workflow using OrganizationServiceContext. So now I wanted to Mock the OrganizationServiceContext using MOQ DLL. Has anyone done this before? 

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How to Mock OrganizationServiceContext in dynamics 365 workflow

    Hi,

    Please see the link below. It describes how to mock OrganizationServiceContext using Moq.dll for unit testing of plugins or workflows.

    alexanderdevelopment.net/.../unit-testing-custom-microsoft-dynamics-crm-code-part-5

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to Mock OrganizationServiceContext in dynamics 365 workflow

    Thanks for the reply but I want to Mock the OrganizationServiceContext for unit testing of workflow.

  • shivaram Profile Picture
    shivaram 3,315 on at
    RE: How to Mock OrganizationServiceContext in dynamics 365 workflow

    hi,

    You need to Add Microsoft.xrm.sdk.client Reference first and then Initialize OrgContext like following

    OrganizationServiceContext orgServiceContext = new OrganizationServiceContext(service);

    Hope it helps you,

    Thanks.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans