public async void PostEditNegativeId() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(-1, new Breed(-1, string.Empty)); CheckMessage(result, $"The Breed ID must be between 1 and {int.MaxValue}."); } }
public async void PostEditNotFound() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(50, new Breed(50, "Test Breed 6 Modified")); CheckMessage(result, "The selected Breed could not be found."); } }
public async void PostEditNoName() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(1, new Breed(1, string.Empty)); CheckMessage(result, "A Breed must have a name."); } }
public async void PostEditMismatchedIds() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(7, new Breed(6)); CheckMessage(result, "The Breed ID provided doesn't match the Breed being updated."); } }
public async void PostEditParentBreedNegative() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Breed with Negative Parent Breed", BreedId = -1 }); CheckMessage(result, $"The Parent Breed ID cannot be negative or greater than {int.MaxValue}."); } }
public async void PostEditParentSetAsOwnParent() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Breed with Null Parent Breed", BreedId = 1 }); CheckMessage(result, "A breed cannot be set as it's own Parent Breed."); } }
public async void GetEditZeroId() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(0); CheckMessage(result, $"The Breed ID must be between 1 and {int.MaxValue}."); } }
public async void GetEditNullId() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(null); CheckMessage(result, "The Breed ID provided was invalid."); } }
public async void PostEditParentBreedDoesntExist() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Breed with Invalid Parent Breed", BreedId = 500 }); BreedViewModel viewModel = CheckViewModel(result); CheckMessage(result, "The parent Breed selected could not be found."); } }
public async void GetEditFound() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(2); BreedViewModel viewModel = CheckViewModel(result); Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Id == 2); Assert.Equal(2, viewModel.Breed.Id); Assert.Equal(breed.Name, viewModel.Breed.Name); } }
public async void PostEditParentBreedZero() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Modified Breed with Zero Parent Breed", BreedId = 0 }); RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirect.ActionName); Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Name == "Test Modified Breed with Zero Parent Breed"); Assert.Equal(1, breed.Id); } }
public async void PostEditParentBreedNull() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(10, new Breed { Id = 10, Name = "Test Breed with Null Parent Breed", BreedId = null }); RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirect.ActionName); Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Id == 10); Assert.Equal("Test Breed with Null Parent Breed", breed.Name); } }
public async void PostEditSuccess() { using (var database = new TestDb()) { var controller = new BreedsController(database.Context); IActionResult result = await controller.Edit(6, new Breed(6, "Modified Breed")); RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirect.ActionName); Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Id == 6); Assert.Equal("Modified Breed", breed.Name); } }