Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing Db4oTool Instrumentation (Collections)

Tags:

db4o

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");

Reference: http://community.versant.com/Documentation/Reference/db4o-8.0/net35/reference/Content/basics/transparentpersistence/ta_enhanced_example.htm

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>)));
like image 672
Travis Avatar asked Feb 23 '26 13:02

Travis


1 Answers

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

like image 55
Vagaus Avatar answered Feb 27 '26 02:02

Vagaus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!