コード例 #1
0
        public async void PayBill_OkResult()
        {
            // Arrange
            Bill bill = new Bill {
                Id = 3, Apartment = new Apartment()
            };

            Mock <BillRepository> mockBillRepository = new Mock <BillRepository>();

            mockBillRepository
            .Setup(br => br.GetAsync(It.IsAny <int>(), It.IsAny <string>()))
            .Returns(Task.FromResult(bill));

            Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(u => u.GetRepository <Bill, BillRepository>())
            .Returns(mockBillRepository.Object);

            BillsController controller = new BillsController(mockUnitOfWork.Object);

            // Act
            IActionResult result = await controller.PayBill(bill.Id);

            // Assert
            Assert.NotNull(result);
            Assert.IsType <OkResult>(result);
        }
コード例 #2
0
        public async void PayBillBillIsNull_BadRequest()
        {
            // Arrange
            Bill bill = new Bill {
                Id = 3
            };

            Mock <BillRepository> mockBillRepository = new Mock <BillRepository>();

            mockBillRepository
            .Setup(br => br.GetAsync(It.IsAny <int>(), It.IsAny <string>()))
            .Returns(Task.FromResult(null as Bill));

            Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(u => u.GetRepository <Bill, BillRepository>())
            .Returns(mockBillRepository.Object);

            BillsController controller = new BillsController(mockUnitOfWork.Object);

            // Act
            IActionResult result = await controller.PayBill(bill.Id);

            // Assert
            Assert.NotNull(result);
            BadRequestObjectResult badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal("There is no such bill", badRequestObjectResult.Value.ToString());
        }
コード例 #3
0
        public void PayBillActionWithIdReturnsJsonResult()
        {
            //arrange
            controller = new BillsController(mockBillService.Object, null, null);
            //act
            var result = controller.PayBill(1);

            //assert
            Assert.IsInstanceOfType(result, typeof(JsonResult));
        }