コード例 #1
0
        public async Task DeleteInvoiceExceptionCatch()
        {
            // Arrange


            var invoice = new Invoice();

            mockRepo.Setup(x => x.Invoice).Returns(_invoiceRepoMock.Object);
            _invoiceRepoMock.Setup(x => x.GetInvoiceById(1)).Throws(new Exception());

            // Act
            var result = await _sut.DeleteInvoice(1);

            // Assert
            mockLogger.Verify(x => x.LogError("Something went wrong inside DeleteInvoice(id) action: Exception of type 'System.Exception' was thrown."), Times.Once);
            Assert.IsType <ObjectResult>(result);
        }
        public void DeleteInvoice_Returns404NotFound_WhenInvalidInvoiceNumber()
        {
            //arrange
            var service    = new Mock <IInvoiceService>();
            var mapper     = new Mock <IMapper>();
            var controller = new InvoiceController(service.Object, mapper.Object, logger);

            service.Setup(s => s.InvoiceExists(It.IsAny <String>())).Returns(false);

            //act
            var result = controller.DeleteInvoice("xxx");

            //assert
            Assert.IsTrue(result is NotFoundResult);
        }
        public void DeleteInvoice_Returns400BadRequest_WhenInvoiceNotDraft()
        {
            //arrange
            var service    = new Mock <IInvoiceService>();
            var mapper     = new Mock <IMapper>();
            var controller = new InvoiceController(service.Object, mapper.Object, logger);

            service.Setup(s => s.InvoiceExists(It.IsAny <String>())).Returns(true);
            service.Setup(s => s.DeleteInvoice(It.IsAny <String>())).Throws(new ArgumentException());

            //act
            var result = controller.DeleteInvoice("xxx");

            //assert
            Assert.IsTrue(result is BadRequestObjectResult);
        }