我愿意开始为我的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;
}
你对我能写什么样的测试有一些想法吗?我应该模拟一些组件吗?
答案 0 :(得分:2)
您的方法只做两件事,更新crmServiceObject中的一些值,然后执行update语句。由于没有任何特定于CRM(除了crmServiceObject是由CRM定义的类型)来更新对象的单元测试,我将跳过它的那一部分。
就CRM调用禁用实体而言,您有两种单元测试选项。验证CRM是否执行了禁用,或模拟IOrganizationService并断言是否已执行Execute调用。这取决于你。
This question也可能有用,虽然它与插件有关。
答案 1 :(得分:0)
点击下面的链接。并且,赠送给此YouTube页面的原始所有者。 http://www.youtube.com/watch?v=2obtHBx07tc
希望有所帮助。 欢呼声。