public virtual void Remove_TwinToContainedItem_DependsOnSemantics() { if (!CanContainTwins) { return; } foreach (var twins in CreateTwinItems()) { var item1 = twins.Item1; var item2 = twins.Item2; if (!ObjectTestHelper.AreTwins((object)item1, (object)item2)) { Assert.Fail("Test fail. Items are not twins."); } foreach (var collection in CreateEmpty()) { collection.Add(item1); collection.Add(item2); var result = collection.Remove(item2); CollectionAssert.Contains(collection.ToList(), item1); Assert.AreEqual(1, collection.Count); Assert.IsTrue(result); } } }
public virtual void Contains_TwinToContainedItem_DependsOnSemantics() { if (!CanContainTwins) { return; } foreach (var twins in CreateTwinItems()) { var item1 = twins.Item1; var item2 = twins.Item2; if (!ObjectTestHelper.AreTwins((object)item1, (object)item2)) { Assert.Fail("Test fail. Items are not twins."); } foreach (var collection in CreateEmpty()) { collection.Add(item1); collection.Add(item2); var result1 = collection.Contains(item1); var result2 = collection.Contains(item2); Assert.IsTrue(result1); Assert.IsTrue(result2); } } }
public virtual void Add_Twins_DependsOnSemantics() { foreach (var collection in CreateEmpty()) { foreach (var twins in CreateTwinItems()) { var item1 = twins.Item1; var item2 = twins.Item2; collection.Add(item1); if (ObjectTestHelper.AreTwins(item1, item2)) { try { collection.Add(item2); } catch (Exception ex) { // muze obsahovat twins, ale vyhazuje vyjimku if (CanContainTwins) { Assert.Fail("Can contains twin instances but throws exception!", ex); } else // nemuze obsahovat twins a spravne vyhazuje vyjimku { CollectionAssert.DoesNotContain(collection.ToList(), item2); Assert.AreEqual(1, collection.Count); } return; } // muze obsahovat twins if (CanContainTwins) { CollectionAssert.Contains(collection.ToList(), item2); Assert.AreEqual(2, collection.Count); } else // nemuze obsahovat twins ale nevyhazuje vyjimku { Assert.Fail("Cannot contain twin instances and does not throw exception!"); } } } } }