public string AddAstronaut(string type, string astronautName) { string result; IAstronaut astronaut; if (type == "Biologist") { astronaut = new Biologist(astronautName); result = string.Format(Utilities.Messages.OutputMessages.AstronautAdded, type, astronautName); astronauts.Add((Astronaut)astronaut); } else if (type == "Geodesist") { astronaut = new Geodesist(astronautName); result = string.Format(Utilities.Messages.OutputMessages.AstronautAdded, type, astronautName); astronauts.Add((Astronaut)astronaut); } else if (type == "Meteorologist") { astronaut = new Meteorologist(astronautName); result = string.Format(Utilities.Messages.OutputMessages.AstronautAdded, type, astronautName); astronauts.Add((Astronaut)astronaut); } else { result = Utilities.Messages.ExceptionMessages.InvalidAstronautType; } return(result); }
public string AddAstronaut(string type, string astronautName) { if (type != nameof(Biologist) && type != nameof(Geodesist) && type != nameof(Meteorologist)) { throw new InvalidOperationException("Astronaut type doesn't exists!"); } IAstronaut astronaut = null; if (type == "Biologist") { astronaut = new Biologist(astronautName); } else if (type == "Geodesist") { astronaut = new Geodesist(astronautName); } else if (type == "Meteorologist") { astronaut = new Meteorologist(astronautName); } this.astronautRepository.Add(astronaut); return($"Successfully added {astronaut.GetType().Name}: {astronaut.Name}!"); }
public string AddAstronaut(string type, string astronautName) { IAstronaut astronaut; switch (type) { case "Biologist": astronaut = new Biologist(astronautName); break; case "Geodesist": astronaut = new Geodesist(astronautName); break; case "Meteorologist": astronaut = new Meteorologist(astronautName); break; default: astronaut = null; break; } if (astronaut is null) { throw new InvalidOperationException("Astronaut type doesn't exists!"); } this.astronauts.Add(astronaut); return($"Successfully added {type}: {astronautName}!"); }
public string AddAstronaut(string type, string astronautName) { IAstronaut astronaut; if (type == nameof(Biologist)) { astronaut = new Biologist(astronautName); } else if (type == nameof(Geodesist)) { astronaut = new Geodesist(astronautName); } else if (type == nameof(Meteorologist)) { astronaut = new Meteorologist(astronautName); } else { throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); } this.astronauts.Add(astronaut); string result = string.Format(OutputMessages.AstronautAdded, type, astronautName); return(result); }
public string AddAstronaut(string type, string astronautName) { IAstronaut astronaut; if (type == "Biologist") { astronaut = new Biologist(astronautName); } else if (type == "Geodesist") { astronaut = new Geodesist(astronautName); } else if (type == "Meteorologist") { astronaut = new Meteorologist(astronautName); } else { throw new InvalidOperationException("Astronaut type doesn't exists!"); } astronauts.Add(astronaut); return($"Successfully added {type}: {astronautName}!"); }
public string AddAstronaut(string type, string astronautName) { string result = string.Empty; if (type == nameof(Biologist)) { IAstronaut bio = new Biologist(astronautName); astronautRepository.Add(bio); result = $"Successfully added {type}: {astronautName}!"; } else if (type == nameof(Geodesist)) { IAstronaut geo = new Geodesist(astronautName); astronautRepository.Add(geo); result = $"Successfully added {type}: {astronautName}!"; } else if (type == nameof(Meteorologist)) { IAstronaut meteo = new Meteorologist(astronautName); astronautRepository.Add(meteo); result = $"Successfully added {type}: {astronautName}!"; } else { throw new InvalidOperationException("Astronaut type doesn't exists!"); } return(result); }
public string AddAstronaut(string type, string astronautName) { IAstronaut astronaut = null; switch (type) { case "Biologist": astronaut = new Biologist(astronautName); break; case "Geodesist": astronaut = new Geodesist(astronautName); break; case "Meteorologist": astronaut = new Meteorologist(astronautName); break; default: throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidAstronautType)); } astronautRepository.Add(astronaut); return(string.Format(OutputMessages.AstronautAdded, type, astronautName)); }
public void AddAnimalTest() { // expected List <string> reports = new List <string>(); Mock.Arrange(() => Biologist.habitat.Add(Arg.IsAny <Animal>())).Returns("Тварину заселено."); // actual reports.Add(Biologist.AddAnimal("Щось", "xenomorph", "середнє")); reports.Add(Biologist.AddAnimal("Боніфацій", "лев", "ч")); reports.Add(Biologist.AddAnimal("Шерхан", "тигр", "ч")); reports.Add(Biologist.AddAnimal("Вова", "вовк", "ч")); reports.Add(Biologist.AddAnimal("Моська", "кіт", "ж")); reports.Add(Biologist.AddAnimal("Мурка", "собака", "ж")); reports.Add(Biologist.AddAnimal("Ромашка", "кінь", "ж")); reports.Add(Biologist.AddAnimal("Олень", "олень", "ч")); reports.Add(Biologist.AddAnimal("Щось", "xenomorph", "ч")); Assert.AreEqual("Неможливо визначити стать, будь ласка, використовуйте букви \"ч\" або \"ж\".", reports[0]); for (int i = 1; i < 8; i++) { Assert.AreEqual("Тварину заселено.", reports[i]); } Assert.AreEqual("Неможливо визначити вид. Будь ласка, використовуйте слова \"лев\", " + "\"тигр\", \"вовк\", \"собака\", \"кiт\", \"олень\", \"кiнь\".", reports[8]); }
//------------- Methods --------------- public string AddAstronaut(string type, string astronautName) { IAstronaut astronaut; switch (type) { case "Biologist": astronaut = new Biologist(astronautName); break; case "Geodesist": astronaut = new Geodesist(astronautName); break; case "Meteorologist": astronaut = new Meteorologist(astronautName); break; default: throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); } this.astronautRepository.Add(astronaut); return($"Successfully added {type}: {astronautName}!"); }
public string AddAstronaut(string type, string astronautName) { if (type == "Biologist") { Biologist biologist = new Biologist(astronautName); AstronautRepository.Add(biologist); return($"Successfully added {type}: {astronautName}!"); } else if (type == "Geodesist") { Geodesist geodesist = new Geodesist(astronautName); AstronautRepository.Add(geodesist); return($"Successfully added {type}: {astronautName}!"); } else if (type == "Meteorologist") { Meteorologist meteorologist = new Meteorologist(astronautName); AstronautRepository.Add(meteorologist); return($"Successfully added {type}: {astronautName}!"); } else { return(null); } }
public string AddAstronaut(string type, string astronautName) { //if (type != nameof(Biologist) || type != nameof(Geodesist) || type != nameof(Meteorologist)) //{ // throw new InvalidOperationException("Astronaut type doesn't exists!"); //} IAstronaut astronautNew = null; string returnMessage = string.Empty; switch (type) { case nameof(Biologist): astronautNew = new Biologist(astronautName); returnMessage = $"Successfully added {type}: {astronautName}!"; break; case nameof(Geodesist): astronautNew = new Geodesist(astronautName); returnMessage = $"Successfully added {type}: {astronautName}!"; break; case nameof(Meteorologist): astronautNew = new Meteorologist(astronautName); returnMessage = $"Successfully added {type}: {astronautName}!"; break; default: throw new InvalidOperationException("Astronaut type doesn't exists!"); } this.astronuatRepository.Add(astronautNew); return(returnMessage); }
public string AddAstronaut(string type, string astronautName) { IAstronaut astronaut = null; if (type == "Meteorologist") { astronaut = new Meteorologist(astronautName); } else if (type == "Geodesist") { astronaut = new Geodesist(astronautName); } else if (type == "Biologist") { astronaut = new Biologist(astronautName); } else { throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); } this.astronautRepository.Add(astronaut); return(string.Format(OutputMessages.AstronautAdded, type, astronautName)); }
public void CalculateAvgFoodTest() { double expected = 2.0; Mock.Arrange(() => Biologist.habitat.GetAvgFood()).Returns(expected); double actual = Biologist.CalculateAvgFood(); Assert.AreEqual(expected, actual); }
public void TimeChangeTest() { bool called = false; Mock.SetupStatic(typeof(Case)); Mock.Arrange(() => Case.dayTime.Change()).DoInstead(() => called = true); Biologist.Change(); Assert.IsTrue(called); }
public void CallEveryoneTest() { //expected bool called = false; Mock.SetupStatic(typeof(Case)); Mock.Arrange(() => Case.dayTime.CallEveryone(Arg.IsAny <List <string> >())).DoInstead(() => called = true); // actual Biologist.CallEveryone(); Assert.IsTrue(called); }
public string AddAstronaut(string astronautType, string astronautName) { IAstronaut astronaut; switch (astronautType) { case "Biologist": astronaut = new Biologist(astronautName); break; case "Geodesist": astronaut = new Geodesist(astronautName); break; case "Meteorologist": astronaut = new Meteorologist(astronautName); break; default: throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); } //Assembly assembly = Assembly.GetExecutingAssembly(); //var type = assembly // .GetTypes() // .FirstOrDefault(t => t.Name == astronautType); //if (type == null) //{ // throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); //} //var astronaut = (IAstronaut)Activator.CreateInstance(type, astronautName); this.astronautRepository.Add(astronaut); return(string.Format(OutputMessages.AstronautAdded, astronaut.GetType().Name, astronaut.Name)); }
public void CallByNameTest() { //expected bool called = false; List <string> expectedList = new List <string> { "Кузьма" }; string nameCat = "Кузьма"; string nameHorse = "Буцефал"; Mock.SetupStatic(typeof(Case)); Mock.Arrange(() => Case.room.Call(nameCat)).Returns(expectedList); // Припустимо, що у нас є кіт Кузьма. Mock.Arrange(() => Case.room.Call(nameHorse)).Returns(new List <string>()); // А коня в нас немає. Mock.Arrange(() => Case.pasture.Call(Arg.AnyString)).Returns(new List <string>()); // actual List <string> actualList1 = Biologist.CallByName(nameCat); List <string> actualList2 = Biologist.CallByName(nameHorse); Assert.AreEqual(expectedList[0], actualList1[0]); Assert.AreEqual("На жаль, такої тварини немає.", actualList2[0]); }
public string AddAstronaut(string type, string astronautName) { IAstronaut astronaut; if (type == "Biologist") { astronaut = new Biologist(astronautName); } else if (type == "Geodesist") { astronaut = new Geodesist(astronautName); } else if (type == "Meteorologist") { astronaut = new Meteorologist(astronautName); } else { throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); } astronautRepository.Add(astronaut); return($"Successfully added {type}: {astronautName}!"); }
public IAstronaut CreateAstronaut(string type, string astronautName) { IAstronaut astronaut; if (type == "Biologist") { astronaut = new Biologist(astronautName); } else if (type == "Geodesist") { astronaut = new Geodesist(astronautName); } else if (type == "Meteorologist") { astronaut = new Meteorologist(astronautName); } else { throw new InvalidOperationException( ExceptionMessages.InvalidAstronautType); } return(astronaut); }
public Astronaut Create(string type, string astronautName) { Astronaut astronaut = null; switch (type) { case "Biologist": astronaut = new Biologist(astronautName); break; case "Geodesist": astronaut = new Geodesist(astronautName); break; case "Meteorologist": astronaut = new Meteorologist(astronautName); break; default: break; } return(astronaut); }