public void EditGetActionWithIdReturnsEditViewWithProperVM() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, mockRecipientService.Object); //act var result = controller.Edit(1) as ViewResult; //assert mockBillService.Verify(m => m.GetBill(It.IsAny <int>()), Times.Once); Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM)); }
public void EditGetActionWithoutIdDoesntInvokeService() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, mockRecipientService.Object); //act int?nullValue = null; var result = controller.Edit(nullValue); //assert mockBillService.Verify(m => m.GetBill(It.IsAny <int>()), Times.Never); }
public void EditPostActionWithValidModelUpdatesBillAndRedirectsToIndexView() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, null); //act var result = controller.Edit(new CreateBillVM()) as RedirectToRouteResult; //assert mockBillService.Verify(m => m.UpdateBill(It.IsAny <IBill>()), Times.Once); Assert.AreEqual(result.RouteValues["action"], "Index"); }
public void EditPostActionWithInvalidModelReturnsEditView() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, null); controller.ModelState.AddModelError("test", "test"); //act var result = controller.Edit(new CreateBillVM()) as ViewResult; //assert Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM)); mockBillService.Verify(m => m.UpdateBill(It.IsAny <IBill>()), Times.Never); }