Exemple #1
0
        public void ItemEqualityTest()
        {
            // Arrange
            var itemDef = new ItemDefinition(Guid.NewGuid());
            var item    = new ItemInstance(Guid.NewGuid(), itemDef);

            var item2 = new ItemInstance(Guid.NewGuid(), itemDef);

            var itemDef3 = new ItemDefinition(Guid.NewGuid());
            var item3    = new ItemInstance(Guid.NewGuid(), itemDef3);


            var instanceComparer   = EqualityComparer <IItemInstance> .Default;
            var definitionComparer = EqualityComparer <ItemDefinition> .Default;

            // Act


            // Assert
            // Item - Item2 comparision (equal)
            Assert.AreEqual(item, item2); // Items should be equal, because they're based on the same definition.
            Assert.IsTrue(instanceComparer.Equals(item, item2));
            Assert.IsTrue(item == item2);
            Assert.IsFalse(item != item2);
            Assert.IsTrue(item.Equals(item2));

            // Item - Item3 comparision (not equal)
            Assert.AreNotEqual(item, item3);
            Assert.IsFalse(instanceComparer.Equals(item, item3));
            Assert.IsFalse(item == item3);
            Assert.IsTrue(item != item3);
            Assert.IsFalse(item.Equals(item3));

            // Definition comparision (not equal)
            Assert.IsFalse(definitionComparer.Equals(itemDef, itemDef3));
            Assert.IsFalse(itemDef == itemDef3);
            Assert.IsTrue(itemDef != itemDef3);
            Assert.IsFalse(itemDef.Equals(itemDef3));
        }