我想根据相关对象中的属性加载单个Business对象。在这种情况下,有一个ExtendedMaterial与Material和Plant有一个关系。
此方法位于AppServer类上。
当我使用此代码运行附加测试时,我得到正确的结果和通过测试但是如果我取消注释该行
Broker.GetBusinessObject<ExtendedMaterial>("Plant.PlantCode LIKE " + plantCode);
然后我得到了例外Habanero.Base.Exceptions.InvalidPropertyNameException : The given property name 'PlantCode' does not exist in the collection of properties for the class 'ExtendedMaterial'
我做错了什么?
public ExtendedMaterial GetExtendedMaterial(string materialCode, string plantCode)
{
// return Broker.GetBusinessObject<ExtendedMaterial>("Plant.PlantCode LIKE " + plantCode);
return Broker.GetBusinessObjectCollection<ExtendedMaterial>("Plant.PlantCode LIKE " + plantCode).FirstOrDefault();
}
[Test]
public void GetExtendedMaterial_WhenExists_ShouldReturnExtendedMaterial()
{
//---------------Set up test pack-------------------
var material = CreateSavedMaterial();
var plant = GetBOTestFactory<Plant>().CreateSavedBusinessObject();
var extendedMaterial = CreateSavedExtendedMaterial(plant, material);
IAppServer appServer = new AppServer(CreateDeviceManagerWithDevice());
//---------------Assert Precondition----------------
Assert.AreSame(plant, extendedMaterial.Plant);
Assert.AreSame(material, extendedMaterial.Material);
//---------------Execute Test ----------------------
var actualExtendedMaterial = appServer.GetExtendedMaterial(material.Code, plant.PlantCode);
//---------------Test Result -----------------------
Assert.AreSame(extendedMaterial, actualExtendedMaterial);
}
答案 0 :(得分:3)
如果你的DataAccessor是一个DataAccessorDB,这确实有效,但我最近在一些单元测试中注意到它对DataAccessorInMemory不起作用。尝试使用数据库进行测试,看看是否有效。如果没有,请在http://redmine.habanerowiki.com/
上记录错误