public async void Can_create_loan_application()
        {
            // Arrange

            var repositoryMock = new Mock <ILoanApplicationRepository>(MockBehavior.Strict);

            repositoryMock.Setup(m => m.CreateLoanApplication(It.IsNotNull <LoanApplication>()))
            .ReturnsAsync((LoanApplication la) => la.Id);

            var handler = new CreateLoanApplicationHandler(repositoryMock.Object);

            var request = new CreateLoanApplication
            {
                LoanApplication = new LoanApplication {
                    Id = Guid.NewGuid().ToString()
                }
            };

            // Act

            var response = await handler.Handle(request, CancellationToken.None);

            // Assert

            Assert.Equal(request.LoanApplication.Id, response.LoanApplicationId);
        }
示例#2
0
        public async Task <ActionResult <object> > CreateLoanApplication([FromBody] LoanApplication loanApplication)
        {
            try
            {
                var createRequest = new CreateLoanApplication {
                    LoanApplication = loanApplication
                };
                var createResponse = await _mediator.Send(createRequest);

                return(new { Id = createResponse.LoanApplicationId });
            }
            catch (NotFoundResourceException)
            {
                return(BadRequest());
            }
            catch (UnauthorizedResourceException)
            {
                return(Unauthorized());
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e));
            }
        }