public void AnimalsWithoutPlacementCantHaveTreatments() { // Arrange Mock <IAnimalRepository> animalRepository = new Mock <IAnimalRepository>(); Mock <ITreatmentRepository> treatmentRepository = new Mock <ITreatmentRepository>(); ITreatmentService treatmentService = new TreatmentService(treatmentRepository.Object, animalRepository.Object); Animal newDog = new Animal { ID = 1, Name = "Doggo", Birthdate = new DateTime(2018, 10, 18), Age = 2, Description = "Good boi", AnimalType = AnimalType.Dog, Race = "Beautiful Doggos", Picture = "Goodboi.png", DateOfDeath = new DateTime(2021, 01, 10), Castrated = true, ChildFriendly = ChildFriendly.Yes, ReasonGivenAway = "Too good a boi", }; Lodging dogGroupLocation = new Lodging { ID = 1, LodgingType = LodgingType.Group, MaxCapacity = 100, CurrentCapacity = 10, AnimalType = AnimalType.Dog, Stays = new List <Stay>() { }, }; Treatment smallOperation = new Treatment { ID = 1, Description = "Small operation to help recovery", TreatmentType = TreatmentType.Operation, Costs = 100, RequiredAge = 1, DoneBy = "Barry", // TODO: This needs a relation to the user Date = new DateTime(2020, 12, 30), }; animalRepository.Setup(e => e.FindByID(newDog.ID)) .Returns(newDog); var ex = Assert.Throws <InvalidOperationException>(() => treatmentService.Add(smallOperation)); Assert.Equal("AS_Services", ex.Source); // Make sure the error is actually thrown in the service, not somewhere else Assert.Equal("Animal needs to be placed", ex.Message); }
public void ChippingTreatmentShouldHaveDescription() { // Arrange Mock <IAnimalRepository> animalRepository = new Mock <IAnimalRepository>(); Mock <ITreatmentRepository> treatmentRepository = new Mock <ITreatmentRepository>(); ITreatmentService treatmentService = new TreatmentService(treatmentRepository.Object, animalRepository.Object); Animal dog = new Animal { ID = 1, Name = "Doggo", Birthdate = new DateTime(2018, 10, 18), Age = 2, Description = "Good boi", AnimalType = AnimalType.Dog, Race = "Beautiful Doggos", Picture = "Goodboi.png", DateOfDeath = null, Castrated = true, ChildFriendly = ChildFriendly.Yes, ReasonGivenAway = "Too good a boi", }; Lodging dogGroupLocation = new Lodging { ID = 1, LodgingType = LodgingType.Group, MaxCapacity = 100, CurrentCapacity = 10, AnimalType = AnimalType.Dog, Stays = new List <Stay>() { }, }; Stay stay = new Stay { ID = 1, Animal = dog, AnimalID = dog.ID, ArrivalDate = new DateTime(2019, 10, 18), AdoptionDate = null, CanBeAdopted = true, AdoptedBy = null, LodgingLocation = dogGroupLocation, LodgingLocationID = dogGroupLocation.ID, Comments = new List <Comment>(), Treatments = new List <Treatment>(), }; Treatment vaccination = new Treatment { ID = 1, TreatmentType = TreatmentType.Chipping, Costs = 100, RequiredAge = 1, DoneBy = "Barry", Date = new DateTime(2020, 12, 30), StayID = 1, Stay = stay, }; animalRepository.Setup(e => e.FindByID(dog.ID)) .Returns(dog); // Act var ex = Assert.Throws <InvalidOperationException>(() => treatmentService.Add(vaccination)); // Assert Assert.Equal("AS_Services", ex.Source); // Make sure the error is actually thrown in the service, not somewhere else Assert.Equal("Add", ex.TargetSite.Name); // Make sure the error is thrown by the Add method; not something else Assert.Equal("Chipping needs a description", ex.Message); }
public void ProperTreatmentCanBeAddedToAnimal() { // Arrange Mock <IAnimalRepository> animalRepository = new Mock <IAnimalRepository>(); Mock <ITreatmentRepository> treatmentRepository = new Mock <ITreatmentRepository>(); ITreatmentService treatmentService = new TreatmentService(treatmentRepository.Object, animalRepository.Object); Animal dog = new Animal { ID = 1, Name = "Doggo", Birthdate = new DateTime(2018, 10, 18), Age = 2, Description = "Good boi", AnimalType = AnimalType.Dog, Race = "Beautiful Doggos", Picture = "Goodboi.png", DateOfDeath = null, Castrated = true, ChildFriendly = ChildFriendly.Yes, ReasonGivenAway = "Too good a boi", }; Lodging dogGroupLocation = new Lodging { ID = 1, LodgingType = LodgingType.Group, MaxCapacity = 100, CurrentCapacity = 10, AnimalType = AnimalType.Dog, Stays = new List <Stay>() { }, }; Stay stay = new Stay { ID = 1, Animal = dog, AnimalID = dog.ID, ArrivalDate = new DateTime(2019, 10, 18), AdoptionDate = null, CanBeAdopted = true, AdoptedBy = null, LodgingLocation = dogGroupLocation, LodgingLocationID = dogGroupLocation.ID, Comments = new List <Comment>(), Treatments = new List <Treatment>(), }; Treatment smallOperation = new Treatment { ID = 1, Description = "Small operation to help recovery", TreatmentType = TreatmentType.Operation, Costs = 100, RequiredAge = 1, DoneBy = "Barry", // TODO: This needs a relation to the user Date = new DateTime(2020, 12, 30), StayID = 1, Stay = stay, }; animalRepository.Setup(e => e.FindByID(dog.ID)) .Returns(dog); //Act treatmentService.Add(smallOperation); //Assert treatmentRepository.Verify(x => x.Add(smallOperation), Times.Once()); treatmentRepository.Verify(x => x.Add(smallOperation)); }