public void IsValid_Amount_MinValue()
        {
            // Arrange
            _command = GetValidCommand();
            _command.Amount = -1;

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

            // Assert
            Assert.False(result);
        }
        public void IsValid_Notes_Null()
        {
            // Arrange
            _command = GetValidCommand();
            _command.Notes = null;

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

            // Assert
            Assert.True(result);
        }
        public void IsValid_Notes_MaxValue()
        {
            // Arrange
            _command = GetValidCommand();
            _command.Notes = _command.Notes.RandomString(501);

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

            // Assert
            Assert.False(result);
        }
        public void IsValid_Date_MinValue()
        {
            // Arrange
            _command = GetValidCommand();
            _command.Date = DateTime.MinValue;

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

            // Assert
            Assert.False(result);
        }
        public void IsValid_Id_Empty()
        {
            // Arrange
            _command = GetValidCommand();
            _command.Id = Guid.Empty;

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

            // Assert
            Assert.False(result);
        }
Пример #6
0
        public async Task <bool> Handle(UpdateStatementCommand 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 oldStatement = _statementRepository.GetById(request.Id);

            if (oldStatement == null)
            {
                await _mediatorHandler.RaiseEvent(
                    new NotFoundEvent(request.Id, "Statement", "Statement not found."));

                return(false);
            }

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

            if (invoice == null)
            {
                await _mediatorHandler.RaiseEvent(
                    new DomainValidationEvent(
                        "Statement Invoice ID does not exist. Please select a valid value."));

                return(false);
            }

            var getByDate = _statementRepository.GetByDate(request.InvoiceId, request.Date);

            if (getByDate != null && getByDate.Id != request.Id)
            {
                await _mediatorHandler.RaiseEvent(
                    new DuplicatedRecordEvent(
                        "Name",
                        "Statement",
                        "A Stement with {0} and {1} is already present. Please select another value."));

                return(false);
            }

            var model = _mapper.Map <Statement>(request);

            await _statementRepository.UpdateAsync(model);

            await _mediatorHandler.RaiseEvent(new StatementUpdatedEvent()
            {
                Old = oldStatement,
                New = model
            });

            return(true);
        }