fake-xrm-easy icon indicating copy to clipboard operation
fake-xrm-easy copied to clipboard

Unable to Intialize service.RetrieveMultiple(new FetchExpression(_fetchQuery)) from XRM Fake Easy

Open Venkateshpilla08 opened this issue 4 years ago • 5 comments

Hi Team,

I am able to Initialize service.RetrieveMultiple(query) where query is a QueryExpression, however I have another service.RetrieveMultiple(new FetchExpression(_fetchQuery)) method here I am passing query in the format of FetchExpression

I am able to create a fake for Query Expression but unable to create fake for FetchExpression using below code snippet.

Working:

image

image

fakecontext.Initialize(new List<Entity>() { configEntity });

Not Working: image

image fakecontext.Initialize(new List<Entity>() { configEntity,userEntity });

Could you please advice me to how to go ahead and create a fake for RetrieveMultiple methods have Fetch Expression as a parameter.

Venkateshpilla08 avatar Oct 28 '19 13:10 Venkateshpilla08

Hi, Can anyone help me here??

Venkateshpilla08 avatar Oct 30 '19 05:10 Venkateshpilla08

Hello @Venkateshpilla08 , to be honest I don't understand your question, if you don't know how to build a test case that uses FetchXml I can tell you that there are a lot of unit tests for FakeXrmEasy that use FetchXml (some tests can be found here.

Best regards, Betim.

BetimBeja avatar Oct 30 '19 06:10 BetimBeja

Hi BetimBeja,

Thanks for your reply. What I understood from the given link is, if we have a fetchxml in our plugin or workflow it has to be copied into the test class and run the test method.

Is my understanding correct??

Venkateshpilla08 avatar Oct 30 '19 06:10 Venkateshpilla08

Think of FakeXrmEasy as an in-memory representation of your CRM Instance... It offers you various ways to write your unit tests, you can test your plugins/workflows or you can use the XrmFakedContext.GetOrganizationService() to have a local IOrganizationService implementation. Please take a closer look to all the unit tests that are written to validate the functionality that FakeXrmEasy offers, so that you can understand the different types of tests you can write with the help of FakeXrmEasy.

Betim.

BetimBeja avatar Oct 30 '19 06:10 BetimBeja

There are some very clear examples of how to write unit tests using QueryExpression, FetchXML or Linq on this page: https://dynamicsvalue.com/get-started/queries. To answer your last question, if you are just wanting to test a query, then you would use the examples in the link above. If you want to test the execution of a plugin or a workflow, then there are plenty of examples in the github project, but also a couple here https://dynamicsvalue.com/get-started/plugins and here https://dynamicsvalue.com/get-started/codeactivities As @BetimBeja said, the best way to really understand it is to download the source code from GitHub (https://github.com/jordimontana82/fake-xrm-easy) and look through the project - there are over 4000 tests in this project which show you how you can test pretty much every imaginable scenario.

bwmodular avatar Oct 30 '19 09:10 bwmodular