public void DogControllerEditDogTest() { // Arrange var dogController = new DogsController(); dogController.Clear(); Dog addDog1 = new Dog("bulldog", "Some Description"); Dog addDog2 = new Dog("sheepdog", "Some Description"); Dog editDogName = new Dog("bulldog_edited", "Some Description"); Dog editDogDescription = new Dog("bulldog_edited", "Some Description Edited"); Dog editDogNameAndDescription = new Dog("bulldog_edited_2", "Some Description Edited Twice"); Dog editInvalidDogName = new Dog("sheepdog", "Some Description"); Dog editDogWithNoDetails = new Dog(); Dog editDogWithNoDescription = new Dog() { Name = "sheepdog" }; var addDog1Result = dogController.AddDog(addDog1); var addDog2Result = dogController.AddDog(addDog2); var editDogNameResult = dogController.EditDog("bulldog", editDogName); var editDogDescriptionResult = dogController.EditDog("bulldog_edited", editDogDescription); var editDogNameAndDescriptionResult = dogController.EditDog("bulldog_edited", editDogNameAndDescription); var editInvalidDogNameResult = dogController.EditDog("bulldog_edited_2", editInvalidDogName); var editDogNoDetatilsResult = dogController.EditDog("sheepdog", editDogWithNoDetails); var editDogWithNoDescriptionResult = dogController.EditDog("sheepdog", editDogWithNoDescription); var dogCollectionResult = dogController.GetAllDogs(); var okObjectResult = dogCollectionResult as OkObjectResult; Dictionary <string, Dog> dogCollection = okObjectResult.Value as Dictionary <string, Dog>; Dog editedDog = dogCollection[editDogWithNoDescription.Name]; // Assert Assert.AreEqual(typeof(OkResult), addDog1Result.GetType()); Assert.AreEqual(typeof(OkResult), addDog2Result.GetType()); Assert.AreEqual(typeof(OkResult), editDogNameResult.GetType()); Assert.AreEqual(typeof(OkResult), editDogDescriptionResult.GetType()); Assert.AreEqual(typeof(OkResult), editDogNameAndDescriptionResult.GetType()); Assert.AreEqual(typeof(BadRequestResult), editInvalidDogNameResult.GetType()); Assert.AreEqual(typeof(BadRequestResult), editDogNoDetatilsResult.GetType()); Assert.AreEqual(typeof(OkResult), editDogWithNoDescriptionResult.GetType()); Assert.AreEqual(typeof(OkObjectResult), dogCollectionResult.GetType()); Assert.IsTrue(dogCollection.ContainsKey(editDogNameAndDescription.Name)); Assert.IsTrue(dogCollection.ContainsKey(editDogWithNoDescription.Name)); Assert.IsFalse(dogCollection.ContainsValue(addDog1)); Assert.IsFalse(dogCollection.ContainsValue(addDog2)); Assert.IsFalse(dogCollection.ContainsValue(editDogName)); Assert.IsFalse(dogCollection.ContainsValue(editDogDescription)); Assert.IsFalse(dogCollection.ContainsValue(editInvalidDogName)); Assert.IsFalse(dogCollection.ContainsValue(editDogWithNoDetails)); Assert.IsTrue(editedDog.Description.Equals("No Description.")); }
public void DogControllerDeleteDogTest() { // Arrange var dogController = new DogsController(); dogController.Clear(); _dogTestCollection = new Dictionary <string, Dog>(); PopulateTestCollection(); var addDog1Result = dogController.AddDog(_dogTestCollection["Bulldog"]); var addDog2Result = dogController.AddDog(_dogTestCollection["Chihuahua"]); var deleteDog1Result = dogController.DeleteDog("Bulldog"); var deleteDog2Result = dogController.DeleteDog("Chihuahua"); var deleteDog3Result = dogController.DeleteDog("Sheepdog"); var deleteEmptyDog = dogController.DeleteDog(""); // Assert Assert.AreEqual(typeof(OkResult), addDog1Result.GetType()); Assert.AreEqual(typeof(OkResult), addDog2Result.GetType()); Assert.AreEqual(typeof(OkResult), deleteDog1Result.GetType()); Assert.AreEqual(typeof(OkResult), deleteDog2Result.GetType()); Assert.AreEqual(typeof(BadRequestResult), deleteDog3Result.GetType()); Assert.AreEqual(typeof(BadRequestResult), deleteEmptyDog.GetType()); }
public void DogControllerAddDogTest() { // Arrange var dogController = new DogsController(); dogController.Clear(); Dog testDog = new Dog("Test Name", "Test Description"); Dog testDog2 = new Dog("Test Name", "Test Description Edited"); Dog testDog3 = new Dog("Test Name Edited", "Test Description"); Dog testDog4 = new Dog(); var result = dogController.AddDog(testDog); var result2 = dogController.AddDog(testDog); var result3 = dogController.AddDog(testDog2); var result4 = dogController.AddDog(testDog3); var result5 = dogController.AddDog(testDog4); testDog4.Name = "a"; var result6 = dogController.AddDog(testDog4); var dogCollectionResult = dogController.GetAllDogs(); var okObjectResult = dogCollectionResult as OkObjectResult; Dictionary <string, Dog> dogCollection = okObjectResult.Value as Dictionary <string, Dog>; Dog addedDog = dogCollection[testDog4.Name]; // Assert Assert.AreEqual(typeof(OkResult), result.GetType()); Assert.AreEqual(typeof(BadRequestResult), result2.GetType()); Assert.AreEqual(typeof(BadRequestResult), result3.GetType()); Assert.AreEqual(typeof(OkResult), result4.GetType()); Assert.AreEqual(typeof(BadRequestResult), result5.GetType()); Assert.AreEqual(typeof(OkResult), result6.GetType()); Assert.AreEqual(typeof(OkObjectResult), dogCollectionResult.GetType()); Assert.IsTrue(dogCollection.ContainsKey(testDog.Name)); Assert.IsFalse(dogCollection.ContainsValue(testDog2)); Assert.IsTrue(dogCollection.ContainsKey(testDog3.Name)); Assert.IsTrue(dogCollection.ContainsKey(testDog4.Name)); Assert.IsTrue(addedDog.Description.Equals("No Description.")); }