Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Mock an OrganizationRequest

Betim Beja edited this page Aug 1, 2019 · 1 revision

If a fake message executor has not been implemented yet or if you would like to fake the response to simplify a test case you can use one of the following ways to mock the response of your Organization Request:

Method 1:

public void Test() 
{
    var context = new XrmFakedContext();

    context.AddExecutionMock<CalculateRollupFieldRequest>(request => 
    {
        var req = request as CalculateRollupFieldRequest; 
        var account = new Entity("account") { 
            ["accountid"] = Guid.NewGuid(), 
            ["pl_actualamount"] = new Microsoft.Xrm.Sdk.Money(123) 
        }; 
        
        var results = new ParameterCollection {{"Entity", account}}; 
        var response = new CalculateRollupFieldResponse() { 
            ResponseName = "CalculateRollupField",
            Results = results
        };
        return response;
     });
}

Method 2:

context.AddFakeMessageExecutor<Request>(new YourOwnFakeMessageExecutorForThatRequest())
Clone this wiki locally