Esempio n. 1
0
        public void RespectSameReferences()
        {
            var majkl = new Person {
                Name = "Majkl"
            };

            var village = new Village(
                new House
            {
                Age       = 15,
                FrontDoor = new Door().Lock(),
                Owner     = majkl
            },
                new House
            {
                Age       = 75,
                FrontDoor = new Door(),
                Owner     = majkl
            });

            var copyService = new CopyService();
            var villageCopy = copyService.Copy(village);

            Assert.NotSame(villageCopy, village);
            Assert.Equal(2, villageCopy.Count());
            Assert.True(villageCopy.HousesHaveSameOwner);
        }
Esempio n. 2
0
        public void DoNotCopyEventsRegistrations()
        {
            var copyService = new CopyService();

            var count = 0;
            var has   = new HasEvents();

            has.Raised += delegate { count++; };
            has.Raise();

            var hasCopy = copyService.Copy(has);

            hasCopy.Raise();

            Assert.Equal(1, count);
        }
Esempio n. 3
0
        public void CopyInherited()
        {
            var triceratops = new BabyTriceratops
            {
                Age            = 3,
                HasBeenVaxined = true,
                NumOfHorns     = 5
            };

            var copyService     = new CopyService();
            var triceratopsCopy = copyService.Copy(triceratops);


            Assert.NotSame(triceratops, triceratopsCopy);
            Assert.Equal(triceratops.Age, triceratopsCopy.Age);
            Assert.Equal(triceratops.NumOfHorns, triceratopsCopy.NumOfHorns);
            Assert.Equal(triceratops.HasBeenVaxined, triceratopsCopy.HasBeenVaxined);
        }