I am creating a unit test for some older code and need to instantiate and return the ExecuteMultipleResponse object. While I'm able to get the object created, the internal Responses is null and I can't return any failure info for the request. How can I properly create ExecuteMultipleResponse?
*This post is locked for comments
figured this out and updating to share the solution. The Responses property is just looking at Results for the key "Responses".
From Microsoft.Xrm.Sdk.Messages -
if (!base.Results.Contains("Responses"))
{
return null;
}
return (ExecuteMultipleResponseItemCollection)base.Results["Responses"]
So to make this work, you only need to create the response collection (ExecuteMultipleResponseItemCollection) and then add it to the Results with the key "Responses"
ExecuteMultipleResponse response = new ExecuteMultipleResponse();
ExecuteMultipleResponseItemCollection responseItemCollection =
new ExecuteMultipleResponseItemCollection();
response.Results.Add("Responses", responseItemCollection);
Thanks Scott. I'm using VS Fakes and I'm trying to do this from my ExecuteOrganizationRequest method within the fake. I check if the request is an ExecuteMultipleRequest and then look at the contents of the requests in the Requests collection. Now I'm trying to create the Responses collection but that doesn't have a setter. I tried to just add to the Responses collection (Responses.Add()) but since the collection is null, that doesn't work. Seems when I call new on ExecuteMultipleResponse, it doesn't create the full object.
Below is the concept. Here I was calling clear instead (just in case I was adding the wrong type and causing an issue that way). Since Responses is null, still won't work.
if (r is ExecuteMultipleRequest)
{
ExecuteMultipleResponse response = new ExecuteMultipleResponse();
response.Responses.Clear();
You will need to use a mocking framework such as Rhino Mocks or Fakes in Visual studio.
See www.develop1.net/.../Unit-Testing-Dynamics-CRM2011-Pipeline-Plugins-using-Rhino-Mocks.aspx
Hope this helps,
Scott
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156