public static void Init(TestContext context) { Property.BuildILPropertyGetters(new PropertyReference(typeof(UIMTestObject), "StringProperty"), new PropertyReference(typeof(UIMTestObject), "StringProperty"), new PropertyReference(typeof(UIMTestObject), "Referenced")); UnifiedSystem.AllowReferences = true; UnifiedSystem.AllowIndexes = true; UnifiedSystem.CreateReferenceIndexes = true; MongoProvider provider = new MongoProvider(new MongoSettings("127.0.0.1", "LogicReincDataTests")); UIMTestObject.SetProvider(provider); UIMTestObject2.SetProvider(provider); if (InitialSet) { for (int i = 0; i < 10000; i++) { new UIMTestObject() { IntegerProperty = i, StringProperty = (i % 2 == 0) ? "SomeString" : "Testing", }.Insert(); } } }
public void ReferenceTest() { UIMTestObject.ClearDatabase(); UIMTestObject2.ClearDatabase(); UIMTestObject parent1 = new UIMTestObject() { IntegerProperty = 1 }; UIMTestObject parent2 = new UIMTestObject() { IntegerProperty = 2 }; parent1.Insert(); parent2.Insert(); List <UIMTestObject2> items = new List <UIMTestObject2>(); for (int i = 0; i < 10; i++) { UIMTestObject2 child = new UIMTestObject2(); if (i % 2 == 0) { child.IntegerProperty = 1; child.StringProperty = "Was 1"; } else { child.IntegerProperty = 2; child.StringProperty = "Was 2"; } child.InitialIndex = i; child.Insert(); items.Add(child); } Assert.AreEqual(5, parent1.Referenced.Count); Assert.AreEqual(5, parent2.Referenced.Count); for (int i = 0; i < items.Count; i++) { List <IUnifiedIMObject> refs = items[i].GetReferences(); Assert.AreEqual(1, refs.Count); if (i % 2 == 0) { Assert.IsTrue(parent1.Referenced.Contains(items[i])); Assert.AreEqual(parent1, refs[0]); } else { Assert.IsTrue(parent2.Referenced.Contains(items[i])); Assert.AreEqual(parent2, refs[0]); } } System.Console.WriteLine("Initial References"); System.Console.WriteLine("Parent1: " + string.Join(" ", parent1.Referenced.Select(x => x.InitialIndex).ToArray())); System.Console.WriteLine("Parent2: " + string.Join(" ", parent2.Referenced.Select(x => x.InitialIndex).ToArray())); for (int i = 0; i < 10; i++) { UIMTestObject2 child = items[i]; if (i % 2 == 0) { child.IntegerProperty = 2; } else { child.IntegerProperty = 1; } child.Update(); } Assert.AreEqual(5, parent1.Referenced.Count); Assert.AreEqual(5, parent2.Referenced.Count); for (int i = 0; i < items.Count; i++) { List <IUnifiedIMObject> refs = items[i].GetReferences(); Assert.AreEqual(1, refs.Count); if (i % 2 == 0) { Assert.IsTrue(parent2.Referenced.Contains(items[i])); Assert.AreEqual(parent2, refs[0]); } else { Assert.IsTrue(parent1.Referenced.Contains(items[i])); Assert.AreEqual(parent1, refs[0]); } } System.Console.WriteLine("After exchanging the ids (On targets)"); System.Console.WriteLine("Parent1: " + string.Join(" ", parent1.Referenced.Select(x => x.InitialIndex).ToArray())); System.Console.WriteLine("Parent2: " + string.Join(" ", parent2.Referenced.Select(x => x.InitialIndex).ToArray())); parent1.IntegerProperty = 2; parent1.Update(); Assert.AreEqual(5, parent1.Referenced.Count); for (int i = 0; i < items.Count; i++) { if (i % 2 == 0) { Assert.IsTrue(parent1.Referenced.Contains(items[i])); } } System.Console.WriteLine("After changing the id of parent 1 to parent 2"); System.Console.WriteLine("Parent1: " + string.Join(" ", parent1.Referenced.Select(x => x.InitialIndex).ToArray())); System.Console.WriteLine("Parent2: " + string.Join(" ", parent2.Referenced.Select(x => x.InitialIndex).ToArray())); foreach (UIMTestObject2 child in items) { child.Delete(); Assert.AreEqual(0, child.GetReferences().Count); } Assert.AreEqual(0, parent1.Referenced.Count); Assert.AreEqual(0, parent2.Referenced.Count); System.Console.WriteLine("After deletion of all targets"); System.Console.WriteLine("Parent1: " + string.Join(" ", parent1.Referenced.Select(x => x.InitialIndex).ToArray())); System.Console.WriteLine("Parent2: " + string.Join(" ", parent2.Referenced.Select(x => x.InitialIndex).ToArray())); }
public static void CleanUp() { UIMTestObject.ClearDatabase(); UIMTestObject2.ClearDatabase(); }