Пример #1
0
        public async Task GIVEN_draft_invoice_WHEN_changing_status_to_sent_THEN_changes_invoice_status_to_sent(InvoiceStatus oldStatus, InvoiceStatus newStatus)
        {
            var invoice = Invoice(oldStatus);

            A.CallTo(() => _invoiceRepository.Get(invoice.Id)).Returns(invoice);
            var command = new ChangeInvoiceStatusCommand {
                Id     = invoice.Id,
                Status = newStatus
            };

            await _sut.Handle(command);

            Assert.Equal(newStatus, invoice.Deflate().Status);
            A.CallTo(() => _invoiceRepository.Upsert(invoice)).MustHaveHappened();
        }
Пример #2
0
        public async Task <IActionResult> ChangeInvoiceStatus(Guid id, ChangeInvoiceStatusCommand command)
        {
            if (!await _invoiceDataService.InvoiceExists(id))
            {
                return(NotFound("Invoice"));
            }

            try {
                await _changeInvoiceStatusCommandHandler.Handle(command);

                return(NoContent());
            }
            catch (IllegalInvoiceStatusTransitionException exception) {
                return(BadRequest(exception.Message));
            }
        }
        public async Task GIVEN_invoice_with_id_WHEN_change_invoice_status_THEN_invoices_customer_and_returns_NoContent(ChangeInvoiceStatusCommand command)
        {
            A.CallTo(() => _invoiceDataService.InvoiceExists(command.Id)).Returns(true);

            var result = await _sut.ChangeInvoiceStatus(command.Id, command);

            Assert.IsType <NoContentResult>(result);
        }
        public async Task GIVEN_invoice_with_id_WHEN_trying_to_change_invoice_status_to_illegal_status_THEN_returns_BadRequest(ChangeInvoiceStatusCommand command)
        {
            A.CallTo(() => _invoiceDataService.InvoiceExists(command.Id)).Returns(true);
            A.CallTo(() => _changeInvoiceStatusCommandHandler.Handle(command)).Throws <IllegalInvoiceStatusTransitionException>();

            var result = await _sut.ChangeInvoiceStatus(command.Id, command);

            Assert.IsType <BadRequestObjectResult>(result);
        }
        public async Task GIVEN_no_invoice_with_id_WHEN_change_invoice_status_THEN_returns_NotFound(ChangeInvoiceStatusCommand command)
        {
            A.CallTo(() => _invoiceDataService.InvoiceExists(command.Id)).Returns(false);

            var result = await _sut.ChangeInvoiceStatus(command.Id, command);

            Assert.IsType <NotFoundObjectResult>(result);
        }