Hi,
Recently we wrote a plugin that was using RetrieveResponse class to get the information of an n – n relationship using Relationship class.
The issue that we faced over here is that the Entity property of RetrieveResponse is read only, we cannot set it. The option was to write the wrapper class over it and use the same wrapper class in the code and the unit test.
/// <summary> /// Wrapper class for retrieve response /// </summary> [DataContract(Namespace = "http://schemas.microsoft.com/xrm/2011/Contracts")] public class RetrieveResponseWrapper : OrganizationResponse { /// <summary> /// The _entity /// </summary> private Entity entity; /// <summary> /// Initializes a new instance of the <see cref="RetrieveResponseWrapper"/> class. /// </summary> /// <param name="response">The response.</param> public RetrieveResponseWrapper(OrganizationResponse response) { try { this.entity = ((RetrieveResponseWrapper)response).Entity; } catch { this.entity = ((RetrieveResponse)response).Entity; } } /// <summary> /// Gets or sets the entity. /// </summary> /// <value> /// The entity. /// </value> public Entity Entity { get { return this.entity; } set { this.entity = value; } } }
Check out this post for more details
http://www.alexanderdevelopment.net/post/2013/01/13/How-to-unit-test-C-Dynamics-CRM-interface-code-part-III
Hope it helps.