Пример #1
0
        public void Map_NoExcludedProperties_ReturnsSameObject()
        {
            // Arrange
            Mapper <AnimalDTO, Animal> mapper = new Mapper <AnimalDTO, Animal>();
            AnimalDTO rattlenakeDTO           = new RattlesnakeDTO()
            {
                Name        = "Name",
                Length      = 10.0,
                IsPoisonous = true,
                Skill       = SpecialSkill.ROLLOVER
            };
            Animal expectedRattlesnake = new Rattlesnake("", 0.0, false, SpecialSkill.BITE);
            Animal actualRattlesnake;

            // Act
            actualRattlesnake   = (Rattlesnake)mapper.Map(rattlenakeDTO, expectedRattlesnake);
            expectedRattlesnake = new Rattlesnake("", 0.0, false, SpecialSkill.BITE);

            // Assert
            foreach (PropertyInfo property in actualRattlesnake.GetType().GetProperties())
            {
                object expectedValue = expectedRattlesnake
                                       .GetType()
                                       .GetProperty(property.Name)
                                       .GetValue(expectedRattlesnake);

                object actualValue = property
                                     .GetValue(actualRattlesnake);

                Assert.AreEqual(expectedValue, actualValue, $"{property.Name} is not as expected");
            }
        }
Пример #2
0
        public void CanOverrideMethod()
        {
            Rattlesnake rattles = new Rattlesnake();
            Dog         fluffy  = new Dog();

            Assert.Equal(0, rattles.HasLegs);
            Assert.Equal(4, fluffy.HasLegs);
        }
        public static void InitializeEntitiesAndDTOs(TestContext testContext)
        {
            animalDTOBase = new PigeonDTO()
            {
                Name        = "Pidgey",
                MaxAltitude = 100,
                IsReal      = true,
                Skill       = SpecialSkill.FLY
            };
            animalBase = new Pigeon("Pidgey", 100, true, 0, SpecialSkill.FLY);

            foreach (int value in Enumerable.Range(1, 10))
            {
                Animal pigeon      = new Pigeon($"PidgeyNo.{value}", value * 100, false, value - 1, SpecialSkill.FLY);
                Animal hawk        = new Hawk($"FearowNo.{value}", value * 200, false, value - 1, SpecialSkill.FLY, (Bird)pigeon);
                Animal rattlesnake = new Rattlesnake($"RattlesnakeNo.{value}", value * 10, true, SpecialSkill.BITE);

                animalsBase.Add(pigeon);
                animalsBase.Add(hawk);
                animalsBase.Add(rattlesnake);

                AnimalDTO pigeonDTO = new PigeonDTO()
                {
                    Name        = $"PidgeyNo.{value}",
                    MaxAltitude = value * 100,
                    IsReal      = false,
                    Skill       = SpecialSkill.FLY
                };

                AnimalDTO hawkDTO = new HawkDTO()
                {
                    Name          = $"FearowNo.{value}",
                    MaxAltitude   = value * 200,
                    IsReal        = false,
                    Skill         = SpecialSkill.FLY,
                    FlyingPartner = (Bird)pigeon
                };

                AnimalDTO rattlesnakeDTO = new RattlesnakeDTO()
                {
                    Name        = $"RattlesnakeNo.{value}",
                    Length      = value * 10,
                    IsPoisonous = true,
                    Skill       = SpecialSkill.BITE
                };

                animalDTOsBase.Add(pigeonDTO);
                animalDTOsBase.Add(hawkDTO);
                animalDTOsBase.Add(rattlesnakeDTO);
            }
        }
Пример #4
0
        public void GenerateConstructorArguments_ConstructorHasNoArgs_ReturnsEmptyArray()
        {
            // Arrange
            Mapper <Animal, AnimalDTO> mapper = new Mapper <Animal, AnimalDTO>();
            Animal rattlenake = new Rattlesnake("", 0.0, false, SpecialSkill.BITE);

            object[] expectedArgs = new object[0];
            object[] actualArgs;

            // Act
            actualArgs = mapper.GenerateConstructorArguments(rattlenake);

            // Assert
            CollectionAssert.AreEqual(expectedArgs, actualArgs, "Constructor args were not generated as expected");
        }
Пример #5
0
        /// <summary>
        /// This just tests that the classes inherit properties
        /// </summary>
        static void Proof()
        {
            ChannelCatfish   channelCatfish   = new ChannelCatfish();
            FlatheadCatfish  flatheadCatfish  = new FlatheadCatfish();
            TigerShark       tigerShark       = new TigerShark();
            GreatWhiteShark  greatWhiteShark  = new GreatWhiteShark();
            EmperorPenguin   emperorPenguin   = new EmperorPenguin();
            GalapagosPenguin galapagosPenguin = new GalapagosPenguin();
            Mallard          mallard          = new Mallard();
            MandarinDuck     mandarinDuck     = new MandarinDuck();
            PrairieFalcon    prairieFalcon    = new PrairieFalcon();
            Gyrfalcon        gyrfalcon        = new Gyrfalcon();
            Dragon           dragon           = new Dragon();
            KomodoDragon     komodoDragon     = new KomodoDragon();
            Anaconda         anaconda         = new Anaconda();
            Rattlesnake      rattlesnake      = new Rattlesnake();
            Dhole            dhole            = new Dhole();
            TundraWolf       tundraWolf       = new TundraWolf();
            HouseCat         houseCat         = new HouseCat();
            Jaguar           jaguar           = new Jaguar();

            Console.WriteLine($"channel catfish gets food: {channelCatfish.FoodAquisition()}");
            Console.WriteLine($"flathead catfish habitat: {flatheadCatfish.Habitat}");
            Console.WriteLine($"great white shark cares for young?: {greatWhiteShark.CaresForYoung}");
            Console.WriteLine($"tiger shark move: {tigerShark.FastestMovement()}");
            Console.WriteLine($"emperor penguin swims?: {emperorPenguin.Sing()}");
            Console.WriteLine($"galapagos penguin moves: {galapagosPenguin.FastestMovement()}");
            Console.WriteLine($"mallard sound: {mallard.Sound()}");
            Console.WriteLine($"mandarin duck does barrel roll?: {mandarinDuck.BarrelRoll()}");
            Console.WriteLine($"gyrfalcon does barrel roll?: {gyrfalcon.BarrelRoll()}");
            Console.WriteLine($"prairie falcon sound: {prairieFalcon.Sound()}");
            Console.WriteLine($"dragon does barrel roll?: {dragon.BarrelRoll()}");
            Console.WriteLine($"komodo dragon birth: {komodoDragon.Birth()}");
            Console.WriteLine($" anaconda swims?: {anaconda.Sing()}");
            Console.WriteLine($" rattlesnake gets food: {rattlesnake.FoodAquisition()}");
            Console.WriteLine($"dhole gets food: {dhole.FoodAquisition()}");
            Console.WriteLine($"dhole birth: {dhole.Birth()}");
            Console.WriteLine($"tundra wolf move: {tundraWolf.FastestMovement()}");
            Console.WriteLine($"house cat gets food: {houseCat.FoodAquisition()}");
            Console.WriteLine($"jaguar can climb?: {jaguar.CanClimb}");
        }
Пример #6
0
        public void Map_HasExcludedProperties_ReturnsUpdatedObject()
        {
            // Arrange
            Mapper <Animal, AnimalDTO> mapper = new Mapper <Animal, AnimalDTO>();
            AnimalDTO expectedRattlesnakeDTO  = new RattlesnakeDTO()
            {
                Name        = "Name",
                Length      = 10.0,
                IsPoisonous = true,
                Skill       = SpecialSkill.BITE
            };
            Animal    rattlesnake = new Rattlesnake("Name", 10.0, true, SpecialSkill.BITE);
            AnimalDTO actualRattlesnakeDTO;

            // Act
            actualRattlesnakeDTO   = (RattlesnakeDTO)mapper.Map(rattlesnake, expectedRattlesnakeDTO);
            expectedRattlesnakeDTO = new RattlesnakeDTO()
            {
                Name        = "Name",
                Length      = 10.0,
                IsPoisonous = true,
                Skill       = SpecialSkill.BITE
            };

            // Assert
            foreach (PropertyInfo property in actualRattlesnakeDTO.GetType().GetProperties())
            {
                object expectedValue = expectedRattlesnakeDTO
                                       .GetType()
                                       .GetProperty(property.Name)
                                       .GetValue(expectedRattlesnakeDTO);

                object actualValue = property
                                     .GetValue(actualRattlesnakeDTO);

                Assert.AreEqual(expectedValue, actualValue, $"{property.Name} is not as expected");
            }
        }
        public void ConvertCollection_CollectionOfDTOs_ReturnsCollectionOfEntities()
        {
            // Arrange
            Producer <AnimalDTO, Animal> producer   = new Producer <AnimalDTO, Animal>();
            IList <AnimalDTO>            animalDTOs = animalDTOsBase;
            IList <Animal> expectedAnimals          = animalsBase;
            IList <Animal> animals;

            // Act
            animals = producer.ConvertCollection(animalDTOs);

            // Assert
            foreach (Animal animal in animals)
            {
                int    index    = animals.IndexOf(animal);
                Animal expected = expectedAnimals[index];

                switch (animal)
                {
                case Pigeon _:
                {
                    Pigeon pigeon         = animal as Pigeon;
                    Pigeon expectedPigeon = expected as Pigeon;
                    foreach (PropertyInfo property in pigeon.GetType().GetProperties())
                    {
                        Assert.AreEqual(
                            expectedPigeon.GetType().GetProperty(property.Name),
                            pigeon.GetType().GetProperty(property.Name),
                            $"{property.Name} does not match.");
                    }
                }
                break;

                case Hawk _:
                {
                    Hawk hawk         = animal as Hawk;
                    Hawk expectedHawk = expected as Hawk;
                    foreach (PropertyInfo property in hawk.GetType().GetProperties())
                    {
                        Assert.AreEqual(
                            expectedHawk.GetType().GetProperty(property.Name),
                            hawk.GetType().GetProperty(property.Name),
                            $"{property.Name} does not match.");
                    }
                }
                break;

                case Rattlesnake _:
                {
                    Rattlesnake rattlesnake         = animal as Rattlesnake;
                    Rattlesnake expectedRattleSnake = expected as Rattlesnake;
                    foreach (PropertyInfo property in rattlesnake.GetType().GetProperties())
                    {
                        Assert.AreEqual(
                            expectedRattleSnake.GetType().GetProperty(property.Name),
                            rattlesnake.GetType().GetProperty(property.Name),
                            $"{property.Name} does not match.");
                    }
                }
                break;
                }
            }
        }