public void SendAnimalToShelterTest() { var shelter = new ShelterRepository(1); var logic = new ShelterLogic(shelter); var cat = new Animal { Name = "cat", AgeInHumanYears = 2 }; shelter.AddAnimal(cat); var person = new Person { Name = "John", Age = 18, Money = 9.99, OwnedAnimals = new Dictionary <string, Animal> { { cat.Name, cat } } }; Rabbit rabbit = new Rabbit { Name = "rabbit", AgeInHumanYears = 2 }; logic.SendAnimalToShelter(rabbit, person); }
public IHttpActionResult GetAllShelters() { try { return(Ok(ShelterLogic.GetAllShelters())); } catch (Exception ex) { return(BadRequest()); } }
public IHttpActionResult GetNearestShelter(double lat, double lng) { try { return(Ok(ShelterLogic.GetNearestShelter(lat, lng))); } catch (Exception ex) { return(BadRequest()); } }
public IHttpActionResult UpdateAmountPPLInShelter([FromBody] AmountPeopleInShelterDTO amountPeopleInShelter, [FromUri] string addressToUpdateAmountPPL) { try { return(Ok(ShelterLogic.UpdateAmountPPLInShelter(amountPeopleInShelter, addressToUpdateAmountPPL))); } catch (Exception ex) { return(BadRequest()); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="shelter">Shelter</param> /// <param name="identifier">Kind of animal</param> public Animal BuyAnimal <T>(ShelterLogic shelter, string identifier) { if (this.IsOldEnoughToBuyAnimal()) { return(shelter.BuyAnimal <T>(this, identifier)); } else { throw new Exception($"{this.Name} is not old enough to buy a pet."); } }
public void GetNumberOfAnimalsInShelterTest1() { var shelter = new ShelterRepository(1); var logic = new ShelterLogic(shelter); var cat = new Cat { Name = "cat", AgeInHumanYears = 2 }; shelter.AddAnimal(cat); logic.GetNumberOfAnimalsInShelter("alligator"); }
public void GetNumberOfAnimalsInShelterTest_String() { var shelter = new ShelterRepository(1); var logic = new ShelterLogic(shelter); var cat = new Cat { Name = "cat", AgeInHumanYears = 2 }; shelter.AddAnimal(cat); var expected = "1 cat(s) in the shelter"; var actual = logic.GetNumberOfAnimalsInShelter(cat.GetType().Name.ToLower()); Assert.AreEqual(expected, actual); }
public void IsShelterFullTest() { ShelterRepository shelter = new ShelterRepository(1); ShelterLogic logic = new ShelterLogic(shelter); Rabbit rabbit2 = new Rabbit { Name = "rabbit2", AgeInHumanYears = 8 }; shelter.AddAnimal(rabbit2); var expected = true; var actual = shelter.IsShelterFull(); Assert.AreEqual(expected, actual); }
public void GetNumberOfAnimalsInShelterTest() { var shelter = new ShelterRepository(1); var logic = new ShelterLogic(shelter); var cat = new Cat { Name = "cat", AgeInHumanYears = 2 }; shelter.AddAnimal(cat); var expected = "1 cat(s) in the shelter\n0 dog(s) in the shelter\n0 snake(s) in the shelter" + $"\n0 hamster(s) in the shelter\n0 rabbit(s) in the shelter"; var actual = logic.GetNumberOfAnimalsInShelter(); Assert.AreEqual(expected, actual); }
public void PurchaseAnimal_NullShelterTest() { var shelter = new ShelterRepository(0); var logic = new ShelterLogic(shelter); var person = new Person { Name = "John", Age = 18, Money = 29.99, OwnedAnimals = new Dictionary <string, Animal>() }; Animal expected = null; var actual = person.BuyAnimal <Cat>(logic); Assert.AreEqual(expected, actual); }
public void BuyAnimalTest2() { var shelter = new ShelterRepository(1); var logic = new ShelterLogic(shelter); var cat = new Animal { Name = "cat", AgeInHumanYears = 2 }; shelter.AddAnimal(cat); var person = new Person { Name = "John", Age = 18, Money = 9.99, OwnedAnimals = new Dictionary <string, Animal>() }; logic.BuyAnimal <Animal>(person, cat.Name); }
public void PurchaseAnimal_NotEnoughMoney() { var shelter = new ShelterRepository(1); var logic = new ShelterLogic(shelter); var cat = new Cat { Name = "cat1", AgeInHumanYears = 3, Price = 13.20 }; shelter.AddAnimal(cat); var person = new Person { Name = "John", Age = 18, Money = 9.99, OwnedAnimals = new Dictionary <string, Animal>() }; person.BuyAnimal <Cat>(logic); }
public void BuyAnimalTest1() { var shelter = new ShelterRepository(1); var logic = new ShelterLogic(shelter); var cat = new Cat { Name = "cat", AgeInHumanYears = 2 }; var person = new Person { Name = "John", Age = 18, Money = 9.99, OwnedAnimals = new Dictionary <string, Animal>() }; Animal expected = null; var actual = logic.BuyAnimal <Cat>(person, cat.Name); Assert.AreEqual(expected, actual); }
public IHttpActionResult UpdateShelter(ShelterDTO updatedShelter) { string message = ""; ShelterDTO updateShelter = ShelterLogic.UpdateShelter(updatedShelter, ref message); if (updateShelter != null) { return(Ok(updateShelter)); } if (message != "") { return(BadRequest(message)); } var error = new { message = "העדכון נכשל" }; return(Content(HttpStatusCode.BadRequest, error)); }
public IHttpActionResult AddShelter(ShelterDTO newShelter) { string message = ""; ShelterDTO addShelter = ShelterLogic.AddNewShelter(newShelter, ref message); if (addShelter != null) { return(Ok(addShelter)); } if (message != "") { return(BadRequest(message)); } var error = new { message = "ההוספה נכשלה" }; return(Content(HttpStatusCode.BadRequest, error)); }
public void BuyAnimalTest_NoAnimalInitialized() { int maxNumberOfAnimals = 5; Rabbit rabbit2 = new Rabbit { Name = "rabbit2", AgeInHumanYears = 8, Price = 5 }; ShelterRepository shelterRepository = new ShelterRepository(maxNumberOfAnimals); shelterRepository.AddAnimal(rabbit2); ShelterLogic logic = new ShelterLogic(shelterRepository); Person person = new Person { Name = "John", Age = 18, Money = 29.99, OwnedAnimals = new Dictionary <string, Animal>() }; person.BuyAnimal <Rabbit>(logic); }
public void SendAnimalToShelter_NullShelter_ThrowsException() { //Arrange ShelterLogic logic = new ShelterLogic(new ShelterRepository(0)); var cat = new Animal { Name = "cat1", AgeInHumanYears = 3, Price = 13.20 }; var person = new Person { Name = "John", Age = 18, Money = 29.99, OwnedAnimals = new Dictionary <string, Animal>() { { cat.Name, cat } } }; //Act logic.SendAnimalToShelter(cat, person); //Assert }
public void SendAnimalToShelter(ShelterLogic shelter, Animal animal) { shelter.SendAnimalToShelter(animal, this); }
public bool UpdateAmountPPLInShelter(AmountPeopleInShelterDTO amountPPL) { return(ShelterLogic.UpdateAmountPPLInShelter(amountPPL)); }