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); } }
public void CreateObject_NewDTOObject_ReturnsDTO() { // Arrange HawkDTO hawkDTO = new HawkDTO(); // Act Factory <HawkDTO> factory = new Factory <HawkDTO>(); factory.map["HawkDTO"] = typeof(HawkDTO); HawkDTO newHawkDTO = factory.CreateObject("HawkDTO"); // Assert Assert.AreEqual(hawkDTO.Name, newHawkDTO.Name, "Name does not match"); Assert.AreEqual(hawkDTO.MaxAltitude, newHawkDTO.MaxAltitude, "MaxAltitude does not match"); Assert.AreEqual(hawkDTO.IsReal, newHawkDTO.IsReal, "IsReal does not match"); Assert.AreEqual(hawkDTO.Skill, newHawkDTO.Skill, "Skill does not match"); Assert.AreEqual(hawkDTO.FlyingPartner, newHawkDTO.FlyingPartner, "FlyingPartner does not match"); }
public void ConvertCollection_CollectionOfEntities_ReturnsCollectionOfDTOs() { // Arrange Producer <Animal, AnimalDTO> producer = new Producer <Animal, AnimalDTO>(); IList <Animal> animals = animalsBase; IList <AnimalDTO> expectedAnimalDTOs = animalDTOsBase; IList <AnimalDTO> animalDTOs; // Act animalDTOs = producer.ConvertCollection(animals); // Assert foreach (AnimalDTO animalDTO in animalDTOs) { int index = animalDTOs.IndexOf(animalDTO); AnimalDTO expected = expectedAnimalDTOs[index]; switch (animalDTO) { case PigeonDTO _: { PigeonDTO pigeon = animalDTO as PigeonDTO; PigeonDTO expectedPigeon = expected as PigeonDTO; 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 HawkDTO _: { HawkDTO hawk = animalDTO as HawkDTO; HawkDTO expectedHawk = expected as HawkDTO; 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 RattlesnakeDTO _: { RattlesnakeDTO rattlesnake = animalDTO as RattlesnakeDTO; RattlesnakeDTO expectedRattleSnake = expected as RattlesnakeDTO; 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; } } }
public static void InitializeEntityAndDTO(TestContext testContext) { entity1 = new Pigeon("Pidgey", 100, false, 0, SpecialSkill.FETCH); entity2 = new Hawk("Fearow", 200, true, 0, SpecialSkill.FLY, entity1); dto = new HawkDTO(); }