Beispiel #1
0
        public async Task <IActionResult> InvoiceCustomer(InvoiceCustomerCommand command)
        {
            if (!await _customerDataService.CustomerExists(command.CustomerId))
            {
                return(NotFound("Customer"));
            }

            try {
                await _invoiceCustomerCommandHandler.Handle(command);

                return(NoContent());
            }
            catch (ValidationException exception) {
                return(BadRequest(exception.Errors));
            }
        }
        public async Task WHEN_POST_invoice_with_invalid_command_THEN_returns_BadRequest(InvoiceCustomerCommand command)
        {
            A.CallTo(() => _customerDataService.CustomerExists(command.CustomerId)).Returns(true);
            var validationFailures = new [] { new ValidationFailure(nameof(InvoiceCustomerCommand.Description), "required") };

            A.CallTo(() => _invoiceCustomerCommandHandler.Handle(command)).Throws(new ValidationException(validationFailures));

            var result = await _sut.InvoiceCustomer(command);

            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal(validationFailures, badRequestResult.Value);
        }
        public async Task GIVEN_customer_with_id_WHEN_invoice_customer_THEN_invoices_customer_and_returns_NoContent(InvoiceCustomerCommand command)
        {
            A.CallTo(() => _customerDataService.CustomerExists(command.CustomerId)).Returns(true);

            var result = await _sut.InvoiceCustomer(command);

            Assert.IsType <NoContentResult>(result);
        }
        public async Task GIVEN_no_customer_with_id_WHEN_invoice_customer_THEN_returns_NotFound(InvoiceCustomerCommand command)
        {
            A.CallTo(() => _customerDataService.CustomerExists(command.CustomerId)).Returns(false);

            var result = await _sut.InvoiceCustomer(command);

            Assert.IsType <NotFoundObjectResult>(result);
        }