我正在使用db4oTool来检测类的透明激活/持久性。
我正在使用-ta和-collections开关。
我知道如何通过以下测试检查类本身是否已正确检测。
Assert.IsTrue(typeof(IActivatable).IsAssignableFrom(typeof(Machine)), "Machine class not instrumented");
参考:http://community.versant.com/Documentation/Reference/db4o-8.0/net35/reference/Content/basics/transparentpersistence/ta_enhanced_example.htm
但是,我不知道如何检查我的集合是否被正确检测。
给定以下机器类:
public class Machine : DomainBase
{
private string _machineId;
public string MachineId
{
get { return _machineId; }
set { _machineId = value; }
}
public IList<EnergyTag> EnergyTags { get; set; }
public void AddEnergyTag(EnergyTag energyTag)
{
if (energyTag.Machine == null)
energyTag.Machine = this;
if (EnergyTags == null)
EnergyTags = new List<EnergyTag>();
EnergyTags.Add(energyTag);
}
}
我如何测试EnergyTags集合是否已正确检测?
编辑:
解:
var machine = new Machine();
Assert.IsTrue(machine.EnergyTags.GetType().Equals(typeof(ActivatableList<EnergyTag>)));
最佳答案
您可以检查EnergyTag的具体类型:
using System.Collections.Generic;
public class Item
{
private IList<Item> l = new List<Item>();
public IList<Item> Items
{
get { return l; }
set { l = value; }
}
public static void Main()
{
System.Console.WriteLine("Type: {0}", new Item().Items.GetType().FullName);
}
}
将输出类似:
类型:Db4objects.Db4o.Collections.ActivatableList`1 [[Item,ActivatableCollections,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = null]]
因此,您可以按名称检查(如果您的模型中没有对db4o程序集的引用),也可以按类型检查。
请记住,此名称(ActivatableList)是实现细节,在将来的db4o发行版中可能会更改。
最好
关于db4o - 单元测试Db4oTool仪器(集合),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8795487/