我正在使用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>)));发布于 2012-01-10 01:24:04
您可以检查具体类型的EnergyTags
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版本中发生变化。
最好的
https://stackoverflow.com/questions/8795487
复制相似问题