public async void Edit_ExistedId_ReturnViewResultProduct(int id) { var customer = new Supermarket { Name = "Rozetka2", Address = "Petrovka district2", Id = id }; var option = new DbContextOptionsBuilder <ShoppingContext>(). UseInMemoryDatabase(databaseName: "testsEdit3").Options; var context = new ShoppingContext(option); SampleData.Initialize(context); var mock = new Mock <SupermarketsService>(context); var controller = new SupermarketsController(mock.Object); var resultView = await controller.Edit(id, customer); var viewResult = Assert.IsType <RedirectToActionResult>(resultView); var actionName = Assert.IsAssignableFrom <string>(viewResult.ActionName); var resultViewDetails = await controller.Details(id); var viewResultDetails = Assert.IsType <ViewResult>(resultViewDetails); var model = Assert.IsAssignableFrom <Supermarket>(viewResultDetails.Model); Assert.Equal("Index", actionName); Assert.Equal(model, customer); }
public async Task EditPOST_Returns_BadRequestResult() { int id = 4; var market = GetSupermarkets().FirstOrDefault(p => p.Id == id); //Arrange mock.Setup(repo => repo.EditAsync(market)) .ThrowsAsync(new Exception()); controller = new SupermarketsController(mock.Object); //Act var result = await controller.Edit(id, market); //Assert var badRequestResult = Assert.IsType <BadRequestResult>(result); }
public async Task Edit_Returns_ProductInfoForEditing() { int id = 4; var market = GetSupermarkets().FirstOrDefault(p => p.Id == id); //Arrange mock .Setup(repo => repo.GetByIdAsync(market.Id)).ReturnsAsync(market); controller = new SupermarketsController(mock.Object); //Act var result = await controller.Edit(market.Id); //Assert var viewResult = Assert.IsType <ViewResult>(result); }
public async Task EditPOST_Returns_RedirectToActionResult() { int id = 4; var market = GetSupermarkets().FirstOrDefault(p => p.Id == id); //Arrange mock.Setup(repo => repo.EditAsync(market)); controller = new SupermarketsController(mock.Object); //Act var result = await controller.Edit(id, market); //Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); mock.Verify(r => r.EditAsync(market)); }