using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using Moq; using Newtonsoft.Json; using Xunit; using CRIF.ACTion.Services.Landmark.DistributionChannel; using Landmark.OLA.Models.Loan; using Landmark.OLA.Models.Loan.Enums; namespace Landmark.OLA.Integration.Tests { public class LoanApplicationControllerTest : OlaIntegrationTest { public LoanApplicationControllerTest() : base() { } [Fact] public async Task SubmitExisting() { // Arrange // mock: loanApplicationStorage.GetContainerById(cosmosId); // mock: _tokenService.GetAuthenticatedDataFromCookie(HttpContext); // mock: loanApplicationStorage.UpdateLoanEnvelop(loanContainer.Id, LoanStatus.Submitted, new LoanError(LoanErrorCode.No_Error, "No_Error"), application.Id); // mock: loanApplicationStorage.DeleteApplication(cosmosId); var mockFoundContainer = new LoanContainer { LoanApplication = new MockApplication().LoanApplication, Status = LoanStatus.In_Progress, Id = "cosmos-123" }; var mockLoanFile = new LoanApplicationFile(mockFoundContainer.Id, Guid.NewGuid(), "document.pdf", "Section", "Section-1", "Mock Document"); mockFoundContainer.LoanApplication.Files.Add(mockLoanFile); var mockResult = new MockApplication().LoanApplication; mockResult.Id = "123456789"; mockVendorClient .Setup(repo => repo.CreateApplicationAndGetId(It.IsAny(), It.IsAny())) .ReturnsAsync(mockResult.Id); mockVendorClient .Setup(repo => repo.AddFile(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(true); mockLoanApplicationDataAccess.Setup(repo => repo.GetContainerById(It.IsAny())) .Returns(mockFoundContainer); mockLoanApplicationDataAccess.Setup(repo => repo.UpdateLoanId(It.IsAny(), It.IsAny())); mockLoanApplicationDataAccess.Setup(repo => repo.UpdateError(It.IsAny(), It.IsAny())); mockLoanApplicationDataAccess.Setup(repo => repo.UpdateStatus(It.IsAny(), It.IsAny())); mockLoanApplicationDataAccess.Setup(repo => repo.UpdateContainer(It.IsAny())); mockLoanApplicationDataAccess.Setup(repo => repo.DeleteApplication(It.IsAny())); mockBlobStorageAccess.Setup(repo => repo.GetBlobAsBase64(It.IsAny())) .Returns("dGhpcy1pcy1hLW1vY2tlZC1ibG9i"); mockBlobStorageAccess.Setup(repo => repo.DeleteBlob(It.IsAny())) .Returns(true); // Act var request = new StringContent("", Encoding.UTF8, "application/json"); var httpResponse = await _client.PostAsync("/api/LoanApplication/Submit/555-444-333", request); // Must be successful. httpResponse.EnsureSuccessStatusCode(); // Deserialize and examine results. var stringResponse = await httpResponse.Content.ReadAsStringAsync(); var resultApplication = JsonConvert.DeserializeObject(stringResponse); Assert.NotNull(resultApplication); Assert.Equal("{\"loanApplicationId\":\"123456789\"}", stringResponse); } } }