public AnimalController() { var context = new AnimalHouseDbContext(); var kennelProcessor = new KennelProcessor(context); _animalProcessor = new AnimalProcessor(context, kennelProcessor); }
public async Task RestructureFailsByOvercapacityAsyncTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); //set capacity for each kennel to 1, which should force the business logic to fail _kennelData.ForEach(k => k.maxLimit = 1); var wasRestructureSuccess = await animalProcessor.ReorganizeAnimalsToAppropriateKennelsAsync(); Assert.IsFalse(wasRestructureSuccess); }
public async Task NoAnimalLeftBehindAsyncTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); //remove medium and large kennels, then try to restucture _kennelData.Remove(_kennelData.Where(k => k.kennelId == 2).First()); _kennelData.Remove(_kennelData.Where(k => k.kennelId == 3).First()); var wasRestructureSuccess = await animalProcessor.ReorganizeAnimalsToAppropriateKennelsAsync(); Assert.IsFalse(wasRestructureSuccess); }
public async Task RemoveAnimalByNameAndTypeAndSizeAsyncTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); var wasAnimalRemoved = await animalProcessor.RemoveAnimalByNameAndTypeAndSizeAsync("Fido", "Dog", 12); Assert.IsTrue(wasAnimalRemoved); var shouldBeNull = _animalData.Where(a => a.animalId == 1).FirstOrDefault(); Assert.IsTrue(shouldBeNull == null); }
public async Task ReorganizeAnimalsTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); var animalController = new AnimalController(animalProcessor); animalController.Request = new HttpRequestMessage(); animalController.Configuration = new HttpConfiguration(); var response = await animalController.ReorganizeAnimalsAsync(); Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK); }
public async Task AddAnimalToShelterAsyncTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); var animalToAdd = new Animal() { name = "Bingo", type = "Dog", sizeInLbs = 26 }; var wasAminalAdded = await animalProcessor.AddAnimalToShelterAsync(animalToAdd); Assert.IsTrue(wasAminalAdded); }
public async Task RemoveAnimalByIdTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); var animalController = new AnimalController(animalProcessor); animalController.Request = new HttpRequestMessage(); animalController.Configuration = new HttpConfiguration(); var goodResponse = await animalController.RemoveByIdAsync(1); Assert.IsTrue(goodResponse.StatusCode == System.Net.HttpStatusCode.OK); var badResponse = await animalController.RemoveByIdAsync(367); //does not exist Assert.IsFalse(badResponse.IsSuccessStatusCode); }
public async Task RejectAnimalIfKennelFullAsyncTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); _animalData.Add(new Animal { kennelId = 2 }); var animalToAdd = new Animal() { name = "Bingo", type = "Dog", sizeInLbs = 26 }; var wasAminalAdded = await animalProcessor.AddAnimalToShelterAsync(animalToAdd); Assert.IsFalse(wasAminalAdded); }
public async Task AddAnimalTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); var animalController = new AnimalController(animalProcessor); animalController.Request = new HttpRequestMessage(); animalController.Configuration = new HttpConfiguration(); var animalToAdd = new AnimalModel { name = "fluffy", type = "dog", sizeInLbs = 32.1 }; var goodResponse = await animalController.AddAsync(animalToAdd); Assert.IsTrue(goodResponse.StatusCode == System.Net.HttpStatusCode.OK); var badResponse = await animalController.AddAsync(null); Assert.IsFalse(badResponse.IsSuccessStatusCode); }
public async Task RestructureAsyncTest() { var kennelProcessor = new KennelProcessor(_mockContext.Object); var animalProcessor = new AnimalProcessor(_mockContext.Object, kennelProcessor); //test that the count of animals in small kennel is 2 before the restructure var smallAnimalsBeforeRestructure = await animalProcessor.GetAnimalsInKennelAsync(1); //reorganizing the kennel sizes //increase small size definition to be less than than 30 lbs //increase medium size definition to be greater than 30 lbs _kennelData.Where(k => k.name == "small").ToList().ForEach(k => k.maxAminalSize = 30); _kennelData.Where(k => k.name == "medium").ToList().ForEach(k => k.minAnimalSize = 30); var wasRestructureSuccess = await animalProcessor.ReorganizeAnimalsToAppropriateKennelsAsync(); var smallAnimalsAfterRestructure = await animalProcessor.GetAnimalsInKennelAsync(1); Assert.IsTrue(wasRestructureSuccess); Assert.IsTrue(smallAnimalsBeforeRestructure.Count == 2); Assert.IsTrue(smallAnimalsAfterRestructure.Count == 3); }
public AnimalController(AnimalProcessor animalProcessor) { _animalProcessor = animalProcessor; }