I am using the db4oTool to instrument my classes for transparent activation/persistence. I am using the -ta and -collections switches.
I know how to check that the classes themselves are being properly instrumented by the following test.
Assert.IsTrue(typeof(IActivatable).IsAssignableFrom(typeof(Machine)), "Machine class not instrumented");
However I do not know how to check that my collections are being instrumented correctly.
Given the following machine class:
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);
}
}
How would I test that the EnergyTags collection was properly instrumented?
Edit:
Solution:
var machine = new Machine();
Assert.IsTrue(machine.EnergyTags.GetType().Equals(typeof(ActivatableList<EnergyTag>)));
You can check the concrete type of 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);
}
}
Will output something like:
Type: Db4objects.Db4o.Collections.ActivatableList`1[[Item, ActivatableCollections, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
So you can either check by name (if you don't have a reference to db4o assemblies in your model) or by type otherwise.
Keep in mind that this name (ActivatableList) is an implementation detail and may change in future db4o releases.
Best