Files
2026-03-11 11:18:25 -05:00

71 lines
3.5 KiB
C#

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<LoanApplication>(), It.IsAny<IDistributionChannelLookupService>()))
.ReturnsAsync(mockResult.Id);
mockVendorClient
.Setup(repo => repo.AddFile(It.IsAny<string>(), It.IsAny<LoanApplicationFile>(), It.IsAny<string>()))
.ReturnsAsync(true);
mockLoanApplicationDataAccess.Setup(repo => repo.GetContainerById(It.IsAny<string>()))
.Returns(mockFoundContainer);
mockLoanApplicationDataAccess.Setup(repo => repo.UpdateLoanId(It.IsAny<string>(), It.IsAny<string>()));
mockLoanApplicationDataAccess.Setup(repo => repo.UpdateError(It.IsAny<string>(), It.IsAny<LoanError>()));
mockLoanApplicationDataAccess.Setup(repo => repo.UpdateStatus(It.IsAny<string>(), It.IsAny<LoanStatus>()));
mockLoanApplicationDataAccess.Setup(repo => repo.UpdateContainer(It.IsAny<LoanContainer>()));
mockLoanApplicationDataAccess.Setup(repo => repo.DeleteApplication(It.IsAny<string>()));
mockBlobStorageAccess.Setup(repo => repo.GetBlobAsBase64(It.IsAny<LoanApplicationFile>()))
.Returns("dGhpcy1pcy1hLW1vY2tlZC1ibG9i");
mockBlobStorageAccess.Setup(repo => repo.DeleteBlob(It.IsAny<LoanApplicationFile>()))
.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<LoanApplication>(stringResponse);
Assert.NotNull(resultApplication);
Assert.Equal("{\"loanApplicationId\":\"123456789\"}", stringResponse);
}
}
}