public void PCBasicTest() { var coll = new PredicateCollection(); var pred = Predicates.ElementTypePredicate <int>(); // Invalid element Assert.ThrowsException <InvalidElementException>(() => coll.Add(pred, "")); // New predicate and element, ok coll.Add(pred, 1); Assert.AreEqual(1, coll.Get(pred)); // Existing predicate and element, ignored coll.Add(pred, 1); Assert.AreEqual(1, coll.Get(pred)); // New predicate, existing element, element ignored coll.Add((Predicate)((obj) => obj.GetType() != typeof(char)), 1); // Match querying by each predicate Assert.AreEqual(coll.Get(pred), coll.Get((obj) => obj.GetType() != typeof(char))); // Existing predicate, new element, not ok Assert.ThrowsException <ExistingElementException>(() => coll.Add(pred, 2)); }
public void PCReferenceTypeTest() { var coll = new PredicateCollection(); var pred = Predicates.ElementTypePredicate <string>(); Assert.ThrowsException <InvalidElementException>(() => coll.Add(pred, 1)); string elem = "a"; coll.Add(pred, elem); Assert.AreSame(elem, coll.Get(pred)); Assert.ThrowsException <ExistingElementException>(() => coll.Add(pred, "b")); Assert.IsTrue(coll.Valid()); }