Esempio n. 1
0
        public void CreatePostActionWithValidModelCreatesBillAndRedirectToIndex()
        {
            //arrange
            controller = new BillsController(mockBillService.Object, mockBillFactory.Object, mockRecipientService.Object);
            //act
            var result = controller.Create(new CreateBillVM());

            //assert
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
        }
Esempio n. 2
0
        public void CreateGetActionReturnsViewWithBillVM()
        {
            //arrange
            controller = new BillsController(mockBillService.Object, null, mockRecipientService.Object);
            //act
            var result = controller.Create() as ViewResult;

            //assert
            Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM));
            Assert.IsNotNull(result);
        }
Esempio n. 3
0
        public void CreatePostActionWithInvalidModelReturnsCreateView()
        {
            //arrange
            controller = new BillsController(mockBillService.Object, mockBillFactory.Object, mockRecipientService.Object);
            controller.ModelState.AddModelError("test", "test");
            //act
            var result = controller.Create(new CreateBillVM()) as ViewResult;

            //assert
            mockBillService.Verify(m => m.CreateBill(It.IsAny <IBill>()), Times.Never);
            Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM)); //returns model to correct errors
        }
Esempio n. 4
0
        public async Task Post_shouldReturnBadRequestWhenPersonIdIsEmpty()
        {
            Bill bill = new Bill()
            {
                DueDate  = DateTime.Now,
                Id       = "anykey1",
                PersonId = String.Empty,
                Value    = 22
            };

            Moq.Mock <IBillService> mockBillService = new Moq.Mock <IBillService>();
            mockBillService.Setup(billService => billService.CreateAsync(It.IsAny <Bill>())).ReturnsAsync(bill);
            var billsController = new BillsController(mockBillService.Object);

            var response = await billsController.Create(bill.DueDate, bill.PersonId, bill.Value);

            Assert.IsType <BadRequestObjectResult>(response.Result);
        }
Esempio n. 5
0
        public async Task Post_shouldCreateBill()
        {
            Bill bill = new Bill()
            {
                DueDate  = DateTime.Now,
                Id       = "anykey1",
                PersonId = "81309409064",
                Value    = 22
            };

            Moq.Mock <IBillService> mockBillService = new Moq.Mock <IBillService>();
            mockBillService.Setup(billService => billService.CreateAsync(It.IsAny <Bill>())).ReturnsAsync(bill);
            var billsController = new BillsController(mockBillService.Object);

            var response = await billsController.Create(bill.DueDate, bill.PersonId, bill.Value);

            var okObjetResult = Assert.IsType <OkObjectResult>(response.Result);

            Assert.IsType <Bill>(okObjetResult.Value);
            Assert.Equal(bill, (okObjetResult.Value));
        }