public void TestMergeCollections() { TestAttributeForCollT1 a1 = new TestAttributeForCollT1(1); TestAttributeForCollT2 a2 = new TestAttributeForCollT2(2); TestAttributeForCollT3 a3 = new TestAttributeForCollT3(3); TestAttributeForCollT4 a4 = new TestAttributeForCollT4(4); TestAttributeForCollT5 a5 = new TestAttributeForCollT5(5); AttributeExtCollection testColl1 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a1, a2 }); AttributeExtCollection testColl2 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a3, a4, a5 }); AttributeExtCollection merged1 = testColl1.MergeAttributeCollections(testColl2); Assert.AreEqual(a3, merged1.GetAttributeAt(0), "wrong merged"); Assert.AreEqual(a4, merged1.GetAttributeAt(1), "wrong merged"); Assert.AreEqual(a5, merged1.GetAttributeAt(2), "wrong merged"); Assert.AreEqual(a1, merged1.GetAttributeAt(3), "wrong merged"); Assert.AreEqual(a2, merged1.GetAttributeAt(4), "wrong merged"); Assert.AreEqual(5, merged1.Count, "result length"); AttributeExtCollection merged2 = testColl2.MergeAttributeCollections(testColl1); Assert.AreEqual(a1, merged2.GetAttributeAt(0), "wrong merged"); Assert.AreEqual(a2, merged2.GetAttributeAt(1), "wrong merged"); Assert.AreEqual(a3, merged2.GetAttributeAt(2), "wrong merged"); Assert.AreEqual(a4, merged2.GetAttributeAt(3), "wrong merged"); Assert.AreEqual(a5, merged2.GetAttributeAt(4), "wrong merged"); Assert.AreEqual(5, merged2.Count, "result length"); }
public void TestRemoveElement() { TestAttributeForCollT1 a1 = new TestAttributeForCollT1(1); TestAttributeForCollT2 a2 = new TestAttributeForCollT2(2); TestAttributeForCollT3 a3 = new TestAttributeForCollT3(3); TestAttributeForCollT4 a4 = new TestAttributeForCollT4(4); TestAttributeForCollT5 a5 = new TestAttributeForCollT5(5); Attribute removed; AttributeExtCollection testColl1 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a1, a2, a3, a4, a5 }); AttributeExtCollection result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT1), out removed); Assert.AreEqual(a1, removed, "wrong removed"); Assert.AreEqual(a2, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a3, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a4, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a5, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT2), out removed); Assert.AreEqual(a2, removed, "wrong removed"); Assert.AreEqual(a1, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a3, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a4, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a5, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT3), out removed); Assert.AreEqual(a3, removed, "wrong removed"); Assert.AreEqual(a1, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a2, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a4, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a5, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT4), out removed); Assert.AreEqual(a4, removed, "wrong removed"); Assert.AreEqual(a1, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a2, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a3, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a5, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT5), out removed); Assert.AreEqual(a5, removed, "wrong removed"); Assert.AreEqual(a1, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a2, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a3, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a4, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); // start with one elem coll AttributeExtCollection testColl2 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a1 }); AttributeExtCollection result2 = testColl2.RemoveAttributeOfType(typeof(TestAttributeForCollT1), out removed); Assert.AreEqual(a1, removed, "wrong removed"); Assert.AreEqual(0, result2.Count, "result length"); // start with two elem coll AttributeExtCollection testColl3 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a1, a2 }); AttributeExtCollection result3 = testColl3.RemoveAttributeOfType(typeof(TestAttributeForCollT1), out removed); Assert.AreEqual(a1, removed, "wrong removed"); Assert.AreEqual(a2, result3.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(1, result3.Count, "result length"); result3 = testColl3.RemoveAttributeOfType(typeof(TestAttributeForCollT2), out removed); Assert.AreEqual(a2, removed, "wrong removed"); Assert.AreEqual(a1, result3.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(1, result3.Count, "result length"); }