我愿意开始为我的 CRM 2011 代码编写单元测试。我对单元测试的经验很少,所以我需要一些帮助。
我想测试的方法是:
public Proxy.custom_serviceobject PopulateServiceObject(Proxy.custom_serviceobject crmServiceObject, serviceobject irisServiceObject, Guid locationId)
{
//set the reference to the location the order is connected to
crmServiceObject.custom_location = new EntityReference("custom_location", locationId);
//add the reference to the product in the serviceobject
crmServiceObject.custom_product = new EntityReference("product", new Guid(irisServiceObject.ItemId));
//convert the errorid to an int
Int32 errorId;
var success = Int32.TryParse(irisServiceObject.ErrorId, out errorId);
crmServiceObject.custom_errorclassOptionSetValue = success ? new OptionSetValue(errorId) : new OptionSetValue(Int32.MinValue);
crmServiceObject.custom_serviceobjecttype =
new EntityReference("custom_serviceobjecttype", new Guid(irisServiceObject.ObjectType.Id));
crmServiceObject.custom_placement = irisServiceObject.SortId;
crmServiceObject.custom_yearofinstallationOptionSetValue = new OptionSetValue(irisServiceObject.AuditYear);
crmServiceObject.custom_yearofmanufactureOptionSetValue = new OptionSetValue(irisServiceObject.ProductionYear);
crmServiceObject.custom_location = new EntityReference("custom_location", new Guid(irisServiceObject.Location));
crmServiceObject.custom_quantity = irisServiceObject.Qty;
crmServiceObject.custom_remark = irisServiceObject.ExternalNote;
crmServiceObject.custom_internalremark = irisServiceObject.InternalNote;
if (irisServiceObject.Cancelled)
{
var setStateRequest = new SetStateRequest
{
EntityMoniker = new EntityReference
{
Id = crmServiceObject.Id,
LogicalName = "custom_serviceobject"
},
State = new OptionSetValue(StatusInactive),
Status = new OptionSetValue(StatusReasonInactive)
};
Service.Execute(setStateRequest);
}
return crmServiceObject;
}
你对我可以写什么样的测试有一些想法吗?我应该模拟一些组件吗?