Exemplo n.º 1
0
        public void CompositesWithListsOfDifferentOrderAreNotEqual()
        {
            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));

            var list  = ((IList <Wheel>)clone.Wheels);
            var first = list.First();

            list.Remove(first);
            list.Add(first);
            Assert.AreEqual(tricycle.Wheels.Count(), clone.Wheels.Count());

            Assert.IsFalse(tricycle.EqualsByValue(clone));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public void EmptyCompositesAreEqual()
        {
            var bike  = new MultyCycle();
            var clone = bike.Clone(deep: true);

            Assert.IsTrue(bike.EqualsByValue(clone));
        }
Exemplo n.º 4
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));
        }