Пример #1
0
        public async Task <IActionResult> Post(AddLoanCommand command)
        {
            var result = await _mediator.Send(command);

            if (result.Errors.Any())
            {
                return(BadRequest(result));
            }
            return(Created("", null));
        }
Пример #2
0
        public async Task AddLoanShouldReturnNoError()
        {
            Response result;
            var      command = new AddLoanCommand();

            command.BorrowerId = 1;
            command.LenderId   = 2;
            command.LoanTypeId = 1;
            command.LoanValue  = 100;
            result             = await _commandHandler.Handle(command, CancellationToken.None);

            Assert.Empty(result.Errors);
        }
Пример #3
0
        public async Task AddLoanShouldReturnSingleError()
        {
            Response result;
            var      command = new AddLoanCommand();

            command.BorrowerId = 1;
            command.LenderId   = 1;
            result             = await _commandHandler.Handle(command, CancellationToken.None);

            Assert.Equal("Borrower and Lender Id must not be the same", result.Errors.FirstOrDefault());
            command.LenderId   = 2;
            command.LoanTypeId = 2;
            result             = await _commandHandler.Handle(command, CancellationToken.None);

            Assert.Equal("Loan type doesnt exists", result.Errors.FirstOrDefault());
            command.LoanTypeId = 1;
            command.LenderId   = 4;
            result             = await _commandHandler.Handle(command, CancellationToken.None);

            Assert.Equal($"User with Id {command.LenderId} doesnt exist", result.Errors.FirstOrDefault());
            command.LenderId   = 2;
            command.BorrowerId = 4;
            Assert.Equal($"User with Id {command.BorrowerId} doesnt exist", result.Errors.FirstOrDefault());
        }