Пример #1
0
        public void InvoiceId_Empty_Guid()
        {
            // Arrange
            _command.InvoiceId = Guid.Empty;

            // Act
            var result = _command.IsValid();

            // Assert
            Assert.False(result);
        }
Пример #2
0
        public async Task <bool> Handle(DeleteStatementByInvoiceIdCommand request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (!request.IsValid())
            {
                await _mediatorHandler.RaiseEvent(
                    new DomainValidationEvent(request.ValidationResult.ToString()));

                return(false);
            }

            var invoice = _invoiceRepository.GetById(request.InvoiceId);

            if (invoice == null)
            {
                await _mediatorHandler.RaiseEvent(new NotFoundEvent(request.InvoiceId, "Statement", "Invoice not found."));

                return(false);
            }

            var deletedStatements = await _statementRepository.DeleteByInvoiceIdAsync(invoice.Id);

            foreach (var statement in deletedStatements)
            {
                await _mediatorHandler.RaiseEvent(new StatementDeletedEvent()
                {
                    Old = statement
                });
            }

            return(true);
        }