public async Task Delete_ReturnPartialViewAndUnitName_ByPassingBrandId() { // Arrange var brandId = 1; var unit = GetListOfUnit().First(x => x.Id == brandId); mockUnitRepo.Setup(x => x.GetByIdAsync(It.IsAny <int?>())).ReturnsAsync(unit); mockUOW.Setup(x => x.Repository <Unit>()).Returns(mockUnitRepo.Object); var controller = new UnitsController(mockUOW.Object); // Act var result = await controller.DeleteUnit(brandId); // Assert var viewResult = Assert.IsType <PartialViewResult>(result); var model = Assert.IsAssignableFrom <string>(viewResult.ViewData.Model); Assert.Equal(unit.Name, model); }
public async Task DeletePost_RedirectAndDeleteUnit_ByPassingBrandId() { // Arrange var brandId = 1; var Unit = GetListOfUnit().First(x => x.Id == brandId); mockUnitRepo.Setup(x => x.GetByIdAsync(It.IsAny <int?>())).ReturnsAsync(Unit); mockUnitRepo.Setup(x => x.DeleteAsync(It.IsAny <Unit>())).Returns(Task.FromResult(It.IsAny <int>())).Verifiable(); mockUOW.Setup(x => x.Repository <Unit>()).Returns(mockUnitRepo.Object); var controller = new UnitsController(mockUOW.Object); // Act var result = await controller.DeleteUnit(brandId, It.IsAny <IFormCollection>()); // Assert var redirectResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectResult.ControllerName); Assert.Equal("Index", redirectResult.ActionName); mockUnitRepo.Verify(); }