public async void ReturnValidModelForCorrectId(int?id) { var result = await sut.Edit(id); var vr = Assert.IsType <ViewResult>(result); fixture.repositoryWrapper.Verify(y => y.Address.GetAddressByIdAsync(id), Times.Once); Assert.Equal("Edit", vr.ViewName); Assert.IsAssignableFrom <AddressDTO>(vr.Model); }
public void Edit_Get_Action_Calls_EditRecord() { //Arrange _addressServiceMock.Setup(x => x.EditRecord(It.IsAny <Address>())); //Act var result = (RedirectToRouteResult)objController.Edit(listAddressVM[0]); //Assert _addressServiceMock.Verify(x => x.EditRecord(It.IsAny <Address>()), Times.Once); Assert.Equal(Constant.Controller.Index, result.RouteValues[Constant.Controller.Action]); }
public void ReturnViewResult_WhenAddressIsNull() { var cityServiceMock = new Mock <ICityService>(); var addressServiceMock = new Mock <IAddressService>(); var addressWithCityMock = new Mock <AddressWithCityModel>(); addressServiceMock.Setup(x => x.GetByIdWithCity(It.IsAny <int>())).Returns(addressWithCityMock.Object); var controller = new AddressController(cityServiceMock.Object, addressServiceMock.Object); var result = controller.Edit(1) as ViewResult; Assert.AreEqual("NotFound", result.ViewName); }
public void ReturnEditView_WhenUpdateReturnsFalse() { var cityServiceMock = new Mock <ICityService>(); var addressServiceMock = new Mock <IAddressService>(); var addressModelMock = new Mock <AddressModel>(); var controller = new AddressController(cityServiceMock.Object, addressServiceMock.Object); addressServiceMock.Setup(x => x.Update(addressModelMock.Object)).Returns(false); var result = controller.Edit(addressModelMock.Object) as ViewResult; Assert.AreEqual("Edit", result.ViewName); }
public void ReturnIndexView_WhenUpdateReturnsTrue() { var cityServiceMock = new Mock <ICityService>(); var addressServiceMock = new Mock <IAddressService>(); var addressModelMock = new Mock <AddressModel>(); var controller = new AddressController(cityServiceMock.Object, addressServiceMock.Object); addressServiceMock.Setup(x => x.Update(addressModelMock.Object)).Returns(true); var result = controller.Edit(addressModelMock.Object) as RedirectToRouteResult; Assert.AreEqual(result.RouteValues["Action"], "Index"); }
public void ReturnProperView_WhenIvokedWithId() { var cityServiceMock = new Mock <ICityService>(); var addressServiceMock = new Mock <IAddressService>(); var addressModelMock = new Mock <AddressModel>(); addressServiceMock.Setup(x => x.GetById(It.IsAny <int>())).Returns(addressModelMock.Object); var controller = new AddressController(cityServiceMock.Object, addressServiceMock.Object); var result = controller.Edit(1) as ViewResult; Assert.AreEqual("Edit", result.ViewName); }
public void AddressUpdateTest() { //setup var id = 1; var address = new Address { Id = id }; var repo = new Mock <IGenericRepository <Address> >(); repo.Setup(x => x.Update(address)); _addressController = new AddressController(repo.Object); //execute _addressController.Edit(address); //assert repo.Verify(x => x.Update(address), Times.Once); }
public void Edit_Post_Redirect_To_Index() { var result = _adressController.Edit(ResourceData.Addresses[0]) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); }