public void AccountController_Create_ExpectCreateAccount() { //Arrange Account account = GetValidAccount(); var controller = new ModelStateTestController(); var isValid = controller.TestTryValidateModel(account); //If account model state is not valid, force an error on model state so it takes the right code //in controllers action method. if(!isValid) { _accountController.ViewData.ModelState.AddModelError("Name", "Field is required"); } //Act ActionResult result = _accountController.Create(account); //Assert _mockIAccountRepo.Verify(x => x.InsertAccount(account)); Assert.IsInstanceOfType(result, typeof(ActionResult)); }
public void AccountController_Edit_ExpectUpdateAccount() { //Arrange Account account = GetValidAccount(); var controller = new ModelStateTestController(); var isValid = controller.TestTryValidateModel(account); _mockIAccountRepo.Setup(x => x.VerifyUserRegistration(It.IsAny<int>(), It.IsAny<int>())).Returns(true); //If account model state is not valid, force an error on model state so it takes the right code //in controllers action method. if (!isValid) { _accountController.ViewData.ModelState.AddModelError("Name", "Field is required"); } //Act ActionResult result = _accountController.Edit(account); //Assert _mockIAccountRepo.Verify(x => x.UpdateAccount(account)); Assert.IsInstanceOfType(result, typeof(ActionResult)); }
public void AccountController_Delete_ExpectDeleteAccountFail() { //Arrange Account account = GetInvalidAccount(); account.Id = -1; var controller = new ModelStateTestController(); var isValid = controller.TestTryValidateModel(account); //If account model state is not valid, force an error on model state so it takes the right code //in controllers action method. if (!isValid) { _accountController.ViewData.ModelState.AddModelError("Name", "Field is required"); } //Act ActionResult result = _accountController.Delete(account.Id); //Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); }