示例#1
0
        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));
        }
示例#2
0
        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);
        }
示例#3
0
        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");
        }
示例#4
0
        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);
        }