Inheritance: IComposite
Example #1
0
        public void CompositesWithArraysCanBeClonedAndCompared()
        {
            var tricycle = new MultyCycle
            {
                Name = "Lightning",
                Wheels = new [] { new Wheel { Brand = "Dunlop" }, new Wheel { Brand = "Dunlop" }, new Wheel { Brand = "Noname" } }
            };

            var clone = tricycle.Clone(deep: true);
            Assert.IsTrue(tricycle.EqualsByValue(clone));
        }
Example #2
0
        public void CompositesWithListsOfDifferentLenghtsAreNotEqual()
        {
            var tricycle = new MultyCycle
            {
                Name = "Lightning",
                Wheels = new List<Wheel> { new Wheel { Brand = "Dunlop" }, new Wheel { Brand = "Dunlop" }, new Wheel { Brand = "Noname" } }
            };

            var clone = tricycle.Clone(deep: true); // deep clone!

            Assert.AreNotSame(tricycle, clone);
            Assert.AreNotSame(tricycle.Wheels, clone.Wheels);
            Assert.AreEqual(tricycle.Wheels.Count(), clone.Wheels.Count());

            // compare the whole bike with the clone including wheels
            Assert.IsTrue(tricycle.EqualsByValue(clone));

            ((IList<Wheel>)clone.Wheels).RemoveAt(2);
            Assert.IsFalse(tricycle.EqualsByValue(clone));
        }
Example #3
0
 public void EmptyCompositesAreEqual()
 {
     var bike = new MultyCycle();
     var clone = bike.Clone(deep: true);
     Assert.IsTrue(bike.EqualsByValue(clone));
 }
Example #4
0
        public void CompositeWithSetOfPartsCompare()
        {
            var unicycle = new MultyCycle
            {
                Name = "Lightning",
                Wheels = new List<Wheel> { new Wheel { Brand = "Dunlop" }}
            };

            var clone = unicycle.Clone(deep: true); // deep clone!

            Assert.AreNotSame(unicycle, clone);
            Assert.AreNotSame(unicycle.Wheels, clone.Wheels);
            Assert.AreNotSame(unicycle.Wheels.First(), clone.Wheels.First());
            Assert.AreEqual(unicycle.Wheels.First().Brand, clone.Wheels.First().Brand);

            // compare the whole bike with the clone including wheels
            Assert.IsTrue(unicycle.EqualsByValue(clone));

            clone.Wheels.First().Brand = "Noname";
            Assert.IsFalse(unicycle.EqualsByValue(clone));
        }