Adding
This commit is contained in:
+293
@@ -0,0 +1,293 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Tax;
|
||||
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
||||
using LCU.API.Internal.DocumentIngestor.DataAccess;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Accounts;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.MemberAgreements;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Agreements;
|
||||
|
||||
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
|
||||
|
||||
public class CoreApiWrapperServiceTest
|
||||
{
|
||||
private CoreApiWrapperService _coreApiWrapperService;
|
||||
private Mock<ICoreApiWrapperDao> _mockCoreApiWrapperDao;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCoreApiWrapperDao = new Mock<ICoreApiWrapperDao>();
|
||||
_coreApiWrapperService = new CoreApiWrapperService(_mockCoreApiWrapperDao.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPersonsTaxIdData_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetPersonsTaxIdData(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetPersonsTaxIdData("12"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetPersonsTaxIdData(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetUserIdByOrganizationNumber_Return()
|
||||
{
|
||||
var personTaxIdDataResponse = new List<PersonTaxIdDataResponse>()
|
||||
{
|
||||
new PersonTaxIdDataResponse()
|
||||
{
|
||||
PersonNumber = 1
|
||||
},
|
||||
new PersonTaxIdDataResponse()
|
||||
{
|
||||
PersonNumber = 2
|
||||
}
|
||||
};
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetPersonsTaxIdData(It.IsAny<string>())).ReturnsAsync(personTaxIdDataResponse);
|
||||
|
||||
var response = await _coreApiWrapperService.GetPersonsTaxIdData("12");
|
||||
Assert.IsNotNull(response);
|
||||
Assert.AreEqual(2, response.ToList().Count);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetPersonsTaxIdData(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOrganizationsTaxIdData_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetOrganizationsTaxIdData(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetOrganizationsTaxIdData("12"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetOrganizationsTaxIdData(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetOrganizationsTaxIdData_Return()
|
||||
{
|
||||
var personTaxIdDataResponse = new List<OrganizationTaxIdDataResponse>()
|
||||
{
|
||||
new OrganizationTaxIdDataResponse()
|
||||
{
|
||||
OrganizationNumber = 1
|
||||
},
|
||||
new OrganizationTaxIdDataResponse()
|
||||
{
|
||||
OrganizationNumber = 2
|
||||
}
|
||||
};
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetOrganizationsTaxIdData(It.IsAny<string>())).ReturnsAsync(personTaxIdDataResponse);
|
||||
|
||||
var response = await _coreApiWrapperService.GetOrganizationsTaxIdData("12");
|
||||
Assert.IsNotNull(response);
|
||||
Assert.AreEqual(2, response.ToList().Count);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetOrganizationsTaxIdData(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetOwnersByAccountNumber_Return()
|
||||
{
|
||||
var accountOwnershipsResponse = new List<AccountOwnership>()
|
||||
{
|
||||
new AccountOwnership()
|
||||
{
|
||||
PersonNumber = 1
|
||||
},
|
||||
new AccountOwnership()
|
||||
{
|
||||
PersonNumber = 2
|
||||
}
|
||||
};
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(accountOwnershipsResponse);
|
||||
|
||||
var response = await _coreApiWrapperService.GetOwnersByAccountNumber("12", "01022022");
|
||||
Assert.IsNotNull(response);
|
||||
Assert.AreEqual(2, response.ToList().Count);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOwnersByAccountNumber_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetOwnersByAccountNumber("12", "01022022"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetOwnersByPersonName_Return()
|
||||
{
|
||||
var accountOwnershipsResponse = new List<AccountOwnership>()
|
||||
{
|
||||
new AccountOwnership()
|
||||
{
|
||||
PersonNumber = 1
|
||||
},
|
||||
new AccountOwnership()
|
||||
{
|
||||
PersonNumber = 2
|
||||
}
|
||||
};
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByPersonName(It.IsAny<string>())).ReturnsAsync(accountOwnershipsResponse);
|
||||
|
||||
var response = await _coreApiWrapperService.GetOwnersByPersonName("Test Tester");
|
||||
Assert.IsNotNull(response);
|
||||
Assert.AreEqual(2, response.ToList().Count);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOwnersByPersonName_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByPersonName(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetOwnersByPersonName("Test Tester"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetOwnersByOrganizationName_Return()
|
||||
{
|
||||
var accountOwnershipsResponse = new List<AccountOwnership>()
|
||||
{
|
||||
new AccountOwnership()
|
||||
{
|
||||
PersonNumber = 1
|
||||
},
|
||||
new AccountOwnership()
|
||||
{
|
||||
PersonNumber = 2
|
||||
}
|
||||
};
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByOrganizationName(It.IsAny<string>())).ReturnsAsync(accountOwnershipsResponse);
|
||||
|
||||
var response = await _coreApiWrapperService.GetOwnersByOrganizationName("Test Company");
|
||||
Assert.IsNotNull(response);
|
||||
Assert.AreEqual(2, response.ToList().Count);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOwnersByOrganization_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByOrganizationName(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetOwnersByOrganizationName("Test Company"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAgreeUsersByAccount_Return()
|
||||
{
|
||||
var returnAgreeUserAccounts = new List<AgreeUserAccount>
|
||||
{
|
||||
new AgreeUserAccount
|
||||
{
|
||||
UserId = "1"
|
||||
}
|
||||
};
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUsersByAccount(It.IsAny<string>())).ReturnsAsync(returnAgreeUserAccounts);
|
||||
|
||||
var response = await _coreApiWrapperService.GetAgreeUsersByAccount("11");
|
||||
Assert.IsNotNull(response);
|
||||
var firstAgreeUserAccount = response.FirstOrDefault();
|
||||
Assert.IsNotNull(firstAgreeUserAccount);
|
||||
Assert.AreEqual("1", firstAgreeUserAccount?.UserId);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUsersByAccount(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAgreeUsersByAccount_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUsersByAccount(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetAgreeUsersByAccount("11"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUsersByAccount(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAgreeUsersByPersonNumber_Return()
|
||||
{
|
||||
var userIds = new List<string> { "1", "2" };
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>())).ReturnsAsync(userIds);
|
||||
|
||||
var response = await _coreApiWrapperService.GetAgreeUsersByPersonNumber("11");
|
||||
Assert.IsNotNull(response);
|
||||
Assert.AreEqual(2, response.ToList().Count);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAgreeUsersByPersonNumber_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetAgreeUsersByPersonNumber("11"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAgreeUserByOrganizationNumber_Return()
|
||||
{
|
||||
var userIds = "1";
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>())).ReturnsAsync(userIds);
|
||||
|
||||
var response = await _coreApiWrapperService.GetAgreeUserByOrganizationNumber("11");
|
||||
Assert.IsNotNull(response);
|
||||
Assert.AreEqual("1", response);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAgreeUserByOrganizationNumber_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetAgreeUserByOrganizationNumber("11"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAgreementAccountsByUserId_Return()
|
||||
{
|
||||
var agreementAccounts = new List<AgreementAccount>()
|
||||
{
|
||||
new ()
|
||||
{
|
||||
AccountNumber = 1,
|
||||
AccountDescription = "test",
|
||||
TaxReportForPersonNumber = 2
|
||||
}
|
||||
};
|
||||
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetAgreementAccountsByUserId(It.IsAny<string>())).ReturnsAsync(agreementAccounts);
|
||||
|
||||
var response = await _coreApiWrapperService.GetAgreementAccountsByUserId(It.IsAny<string>());
|
||||
var result = response as List<AgreementAccount>;
|
||||
var first = result.FirstOrDefault();
|
||||
Assert.IsNotNull(response);
|
||||
Assert.AreEqual(1, first?.AccountNumber);
|
||||
Assert.AreEqual("test", first?.AccountDescription);
|
||||
Assert.AreEqual(2, first?.TaxReportForPersonNumber);
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetAgreementAccountsByUserId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAgreementAccountsByUserId_Exception()
|
||||
{
|
||||
_mockCoreApiWrapperDao.Setup(x => x.GetAgreementAccountsByUserId(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetAgreementAccountsByUserId("11"));
|
||||
_mockCoreApiWrapperDao.Verify(x => x.GetAgreementAccountsByUserId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
using LCU.API.Internal.DocumentIngestor.DataAccess;
|
||||
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
||||
using LCU.Library.DocumentType.Models.Requests;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
|
||||
|
||||
public class DocumentTypeRetrieverApiServiceTest
|
||||
{
|
||||
private DocumentTypeRetrieverService _documentTypeRetrieverApiService;
|
||||
private Mock<IDocumentTypeRetrieverDao> _mockDocumentTypeRetrieverDao;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDocumentTypeRetrieverDao = new Mock<IDocumentTypeRetrieverDao>();
|
||||
_documentTypeRetrieverApiService = new DocumentTypeRetrieverService(_mockDocumentTypeRetrieverDao.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDocumentCodeDetail_Success()
|
||||
{
|
||||
var documentCode = "LnNent";
|
||||
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetail(It.IsAny<string>()));
|
||||
|
||||
await _documentTypeRetrieverApiService.GetDocumentCodeDetail(documentCode);
|
||||
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetail(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDocumentCodeDetail_Exception()
|
||||
{
|
||||
var documentCode = "LnNent";
|
||||
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetail(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeRetrieverApiService.GetDocumentCodeDetail(documentCode));
|
||||
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetail(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDocumentCodeDetails_Success()
|
||||
{
|
||||
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetails());
|
||||
|
||||
await _documentTypeRetrieverApiService.GetDocumentCodeDetails();
|
||||
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetails(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDocumentCodeDetails_Exception()
|
||||
{
|
||||
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetails())
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeRetrieverApiService.GetDocumentCodeDetails());
|
||||
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetails(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDocumentCodeDetailsCache_Success()
|
||||
{
|
||||
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetailsCache());
|
||||
|
||||
await _documentTypeRetrieverApiService.GetDocumentCodeDetailByDisplayName(It.IsAny<string>());
|
||||
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetailsCache(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDocumentCodeDetailsCache_Exception()
|
||||
{
|
||||
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetailsCache())
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeRetrieverApiService
|
||||
.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()));
|
||||
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetailsCache(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetListOfMaliciousDocuments_Success()
|
||||
{
|
||||
var filter = new MaliciousDocumentSearchFilter();
|
||||
_mockDocumentTypeRetrieverDao.Setup(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()));
|
||||
|
||||
await _documentTypeRetrieverApiService.GetListOfMaliciousDocuments(filter);
|
||||
_mockDocumentTypeRetrieverDao.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetListOfMaliciousDocuments_Exception()
|
||||
{
|
||||
var filter = new MaliciousDocumentSearchFilter();
|
||||
_mockDocumentTypeRetrieverDao.Setup(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeRetrieverApiService.GetListOfMaliciousDocuments(filter));
|
||||
_mockDocumentTypeRetrieverDao.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Once);
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Library.DocumentType.Models.Requests.PrimaryOwner;
|
||||
using LCU.Library.DocumentType.Models.Requests.Account;
|
||||
using LCU.Library.Internal.LcuMassTransitModels;
|
||||
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
||||
using LCU.API.Internal.DocumentIngestor.DataAccess;
|
||||
using LCU.API.Internal.DocumentIngestor.Configurations;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models;
|
||||
using LCU.Library.DocumentType.Models.Requests.Attributes;
|
||||
using LCU.Library.DocumentType.Models.Requests.Generic;
|
||||
|
||||
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
|
||||
|
||||
public class DocumentTypeUploaderApiServiceTest
|
||||
{
|
||||
private DocumentTypeUploaderApiService _documentTypeUploaderApiService;
|
||||
private Mock<IDocumentTypeUploaderApiDao> _mockDocumentTypeUploaderApiDao;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var connectionConfiguration = new ConnectionConfiguration()
|
||||
{
|
||||
HostUrl = "Test",
|
||||
UserName = "Test",
|
||||
Password = "Test"
|
||||
};
|
||||
var receiveEndpointConfigurations = new ReceiveEndpointConfigurations()
|
||||
{
|
||||
UploadCompletionEndpoint = new ReceiveEndpointConfiguration()
|
||||
{
|
||||
ReceiveEndpoint = "Test",
|
||||
ReceiveEndpointType = "Exchange",
|
||||
PrefetchLimit = 1
|
||||
}
|
||||
};
|
||||
_mockDocumentTypeUploaderApiDao = new Mock<IDocumentTypeUploaderApiDao>();
|
||||
_documentTypeUploaderApiService = new DocumentTypeUploaderApiService(_mockDocumentTypeUploaderApiDao.Object,
|
||||
connectionConfiguration,
|
||||
receiveEndpointConfigurations);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UploadPrimaryOwnerDocument_Exception()
|
||||
{
|
||||
_mockDocumentTypeUploaderApiDao.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var request = new PrimaryOwnerDocumentRequest
|
||||
{
|
||||
PrimaryOwnerAttribute = new PrimaryOwnerAttribute
|
||||
{
|
||||
PersonNumber = "1"
|
||||
}
|
||||
};
|
||||
var processRequest = new ProcessingRequest();
|
||||
var processResult = new ProcessResult();
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeUploaderApiService.UploadPrimaryOwnerDocument(request, processRequest, processResult));
|
||||
_mockDocumentTypeUploaderApiDao.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UploadAccountOwnerDocument_Exception()
|
||||
{
|
||||
_mockDocumentTypeUploaderApiDao.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var request = new AccountDocumentRequest
|
||||
{
|
||||
AccountAttribute = new AccountAttribute
|
||||
{
|
||||
AccountNumber = "1"
|
||||
}
|
||||
};
|
||||
var processRequest = new ProcessingRequest();
|
||||
var processResult = new ProcessResult();
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeUploaderApiService.UploadAccountDocument(request, processRequest, processResult));
|
||||
_mockDocumentTypeUploaderApiDao.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void UploadGenericDocument_Exception()
|
||||
{
|
||||
_mockDocumentTypeUploaderApiDao.Setup(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var request = new GenericDocumentRequest();
|
||||
var processRequest = new ProcessingRequest();
|
||||
var processResult = new ProcessResult();
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeUploaderApiService.UploadGenericDocument(request, processRequest, processResult));
|
||||
_mockDocumentTypeUploaderApiDao.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetUserIdByOrganizationNumber_Return()
|
||||
{
|
||||
_mockDocumentTypeUploaderApiDao.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>()));
|
||||
|
||||
var request = new PrimaryOwnerDocumentRequest
|
||||
{
|
||||
PrimaryOwnerAttribute = new PrimaryOwnerAttribute
|
||||
{
|
||||
PersonNumber = "1"
|
||||
}
|
||||
};
|
||||
var processRequest = new ProcessingRequest();
|
||||
var processResult = new ProcessResult();
|
||||
await _documentTypeUploaderApiService.UploadPrimaryOwnerDocument(request, processRequest, processResult);
|
||||
_mockDocumentTypeUploaderApiDao.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>()), Times.Once);
|
||||
}
|
||||
}
|
||||
+358
@@ -0,0 +1,358 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Library.Internal.LcuMassTransitModels;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.API.Internal.DocumentIngestor.Configurations;
|
||||
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
||||
using LCU.API.Internal.DocumentIngestor.DataAccess;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
|
||||
|
||||
public class FileOperationsApiServiceTest
|
||||
{
|
||||
private FileOperationsApiService _fileOperationsApiService;
|
||||
private Mock<IFileOperationsApiDao> _mockFileOperationsApiDao;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockFileOperationsApiDao = new Mock<IFileOperationsApiDao>();
|
||||
_fileOperationsApiService = new FileOperationsApiService(_mockFileOperationsApiDao.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DirectMoveFile_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectMoveFile(It.IsAny<MoveFileRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var path = "\\path\\";
|
||||
var file = "file.pdf";
|
||||
var destination = "\\destination\\";
|
||||
var completionRequest = new CompletionRequest();
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectMoveFile(path, file, destination));
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectMoveFile(It.IsAny<MoveFileRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DirectMoveFile_Success()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectMoveFile(It.IsAny<MoveFileRequest>()));
|
||||
|
||||
var path = "\\path\\";
|
||||
var file = "file.pdf";
|
||||
var destination = "\\destination\\";
|
||||
var completionRequest = new CompletionRequest();
|
||||
await _fileOperationsApiService.DirectMoveFile(path, file, destination);
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectMoveFile(It.IsAny<MoveFileRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DirectWriteFile_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectWriteFile(It.IsAny<WriteFileRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var fileName = "file";
|
||||
var extension = ".csv";
|
||||
var fileData = "testFile";
|
||||
var destination = "\\destination\\";
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectWriteFile(fileName, extension, fileData, destination));
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectWriteFile(It.IsAny<WriteFileRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DirectWriteFile_Success()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectWriteFile(It.IsAny<WriteFileRequest>()));
|
||||
|
||||
var fileName = "file";
|
||||
var extension = ".csv";
|
||||
var fileData = "testFile";
|
||||
var destination = "\\destination\\";
|
||||
await _fileOperationsApiService.DirectWriteFile(fileName, extension, fileData, destination);
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectWriteFile(It.IsAny<WriteFileRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DirectCreateDirectory_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectCreateDirectory(It.IsAny<CreateDirectoryRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var directoryPath = "\\path\\";
|
||||
var directoryName = "newFolder";
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectCreateDirectory(directoryPath, directoryName));
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectCreateDirectory(It.IsAny<CreateDirectoryRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DirectCreateDirectory_Success()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectCreateDirectory(It.IsAny<CreateDirectoryRequest>()));
|
||||
|
||||
var directoryPath = "\\path\\";
|
||||
var directoryName = "newFolder";
|
||||
await _fileOperationsApiService.DirectCreateDirectory(directoryPath, directoryName);
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectCreateDirectory(It.IsAny<CreateDirectoryRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DirectUnzipFile_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectUnzipFile(It.IsAny<UnzipFileRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var sourceDirectory = "\\oldPath\\";
|
||||
var destinationPath = "\\newPath\\";
|
||||
var zipFileName = "newFolder";
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectUnzipFile(sourceDirectory, zipFileName, destinationPath, true));
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectUnzipFile(It.IsAny<UnzipFileRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DirectUnzipFile_Success()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectUnzipFile(It.IsAny<UnzipFileRequest>()));
|
||||
|
||||
var sourceDirectory = "\\oldPath\\";
|
||||
var destinationPath = "\\newPath\\";
|
||||
var zipFileName = "newFolder";
|
||||
await _fileOperationsApiService.DirectUnzipFile(sourceDirectory, zipFileName, destinationPath, true);
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectUnzipFile(It.IsAny<UnzipFileRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DirectZipDirectory_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectZipDirectory(It.IsAny<ZipDirectoryRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var sourceDirectory = "\\oldPath\\";
|
||||
var zipPath = "\\newPath\\";
|
||||
var zipFileName = "newFolder";
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectZipDirectory(sourceDirectory, zipPath, zipFileName));
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectZipDirectory(It.IsAny<ZipDirectoryRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DirectZipDirectory_Success()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectZipDirectory(It.IsAny<ZipDirectoryRequest>()));
|
||||
|
||||
var sourceDirectory = "\\oldPath\\";
|
||||
var zipPath = "\\newPath\\";
|
||||
var zipFileName = "newFolder";
|
||||
await _fileOperationsApiService.DirectZipDirectory(sourceDirectory, zipPath, zipFileName);
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectZipDirectory(It.IsAny<ZipDirectoryRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void DirectDeleteDirectory_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectDeleteDirectory(It.IsAny<DeleteDirectoryRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var directoryName = "folder";
|
||||
var directoryRootPath = "\\testPath\\";
|
||||
var maxAmountOfDirectories = 1;
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectDeleteDirectory(directoryName, directoryRootPath, maxAmountOfDirectories));
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectDeleteDirectory(It.IsAny<DeleteDirectoryRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DirectDeleteDirectory_Success()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.DirectDeleteDirectory(It.IsAny<DeleteDirectoryRequest>()));
|
||||
|
||||
var directoryName = "folder";
|
||||
var directoryRootPath = "\\testPath\\";
|
||||
var maxAmountOfDirectories = 1;
|
||||
await _fileOperationsApiService.DirectDeleteDirectory(directoryName, directoryRootPath, maxAmountOfDirectories);
|
||||
_mockFileOperationsApiDao.Verify(x => x.DirectDeleteDirectory(It.IsAny<DeleteDirectoryRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetFileContent_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var filePath = "\\path\\file.pdf";
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await _fileOperationsApiService.GetFileContent(filePath));
|
||||
_mockFileOperationsApiDao.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetFileContent_Success()
|
||||
{
|
||||
var content = "test, test, test";
|
||||
_mockFileOperationsApiDao.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(content);
|
||||
|
||||
var filePath = "\\path\\file.pdf";
|
||||
var result = await _fileOperationsApiService.GetFileContent(filePath);
|
||||
Assert.AreEqual(content, result);
|
||||
_mockFileOperationsApiDao.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetContentBytes_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.GetPdfByteContent(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var documentPath = "\\path\\";
|
||||
var documentFileName = "file.pdf";
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await _fileOperationsApiService.GetContentBytes(documentPath, documentFileName));
|
||||
_mockFileOperationsApiDao.Verify(x => x.GetPdfByteContent(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetContentBytes_Success()
|
||||
{
|
||||
var content = "test, test, test";
|
||||
var contentBytes = Encoding.ASCII.GetBytes(content);
|
||||
_mockFileOperationsApiDao.Setup(x => x.GetPdfByteContent(It.IsAny<string>())).ReturnsAsync(contentBytes);
|
||||
|
||||
var documentPath = "\\path\\";
|
||||
var documentFileName = "file.pdf";
|
||||
var result = await _fileOperationsApiService.GetContentBytes(documentPath, documentFileName);
|
||||
Assert.AreEqual(contentBytes, result);
|
||||
_mockFileOperationsApiDao.Verify(x => x.GetPdfByteContent(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidateFileExists_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var filePath = "\\path\\file.pdf";
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await _fileOperationsApiService.ValidateFileExists(filePath));
|
||||
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ValidateFileExists_Success()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(true);
|
||||
|
||||
var filePath = "\\path\\file.pdf";
|
||||
var result = await _fileOperationsApiService.ValidateFileExists(filePath);
|
||||
Assert.IsTrue(result);
|
||||
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidateFileExistsAndNotArchived_ValidateFileExists_FilePath_Exception()
|
||||
{
|
||||
var filePath = "\\path\\file.pdf";
|
||||
var archiveFilePath = "\\path\\archive\\file.pdf";
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(filePath))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await _fileOperationsApiService.ValidateFileExistsAndNotArchived(filePath, archiveFilePath));
|
||||
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidateFileExistsAndNotArchived_ValidateFileExists_ArchiveFilePath_Exception()
|
||||
{
|
||||
var filePath = "\\path\\file.pdf";
|
||||
var archiveFilePath = "\\path\\archive\\file.pdf";
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(filePath)).ReturnsAsync(false);
|
||||
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(archiveFilePath))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await _fileOperationsApiService.ValidateFileExistsAndNotArchived(filePath, archiveFilePath));
|
||||
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ValidateFileExistsAndNotArchived_True()
|
||||
{
|
||||
var filePath = "\\path\\file.pdf";
|
||||
var archiveFilePath = "\\path\\archive\\file.pdf";
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(filePath)).ReturnsAsync(true);
|
||||
|
||||
var result = await _fileOperationsApiService.ValidateFileExistsAndNotArchived(filePath, archiveFilePath);
|
||||
Assert.IsTrue(result);
|
||||
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ValidateFileExistsAndNotArchived_False()
|
||||
{
|
||||
var filePath = "\\path\\file.pdf";
|
||||
var archiveFilePath = "\\path\\archive\\file.pdf";
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(filePath)).ReturnsAsync(false);
|
||||
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(archiveFilePath)).ReturnsAsync(true);
|
||||
|
||||
|
||||
var result = await _fileOperationsApiService.ValidateFileExistsAndNotArchived(filePath, archiveFilePath);
|
||||
Assert.IsFalse(result);
|
||||
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ValidatePdfPageExists_Success()
|
||||
{
|
||||
var requestResponse = new RequestResponse()
|
||||
{
|
||||
IsSuccessful = true
|
||||
};
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
|
||||
|
||||
var filePath = "\\path\\file.pdf";
|
||||
var result = await _fileOperationsApiService.ValidatePdfPageExists(filePath, "5");
|
||||
_mockFileOperationsApiDao.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidatePdfPageExists_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var filePath = "\\path\\file.pdf";
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await _fileOperationsApiService.ValidatePdfPageExists(filePath, "5"));
|
||||
_mockFileOperationsApiDao.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueBatchPdfParser_Success()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()));
|
||||
|
||||
var batchParsePdfRequest = new BatchParsePdfRequest();
|
||||
await _fileOperationsApiService.QueueBatchPdfParser(batchParsePdfRequest);
|
||||
_mockFileOperationsApiDao.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueueBatchPdfParser_Exception()
|
||||
{
|
||||
_mockFileOperationsApiDao.Setup(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var batchParsePdfRequest = new BatchParsePdfRequest();
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.QueueBatchPdfParser(batchParsePdfRequest));
|
||||
_mockFileOperationsApiDao.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Once);
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
||||
using LCU.API.Internal.DocumentIngestor.DataAccess;
|
||||
using LCU.API.Internal.DocumentIngestor.Models.MemberPreferencesDtos;
|
||||
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
|
||||
|
||||
public class MemberPreferencesApiServiceTest
|
||||
{
|
||||
private MemberPreferencesApiService _memberPreferencesApiService;
|
||||
private Mock<IMemberPreferencesApiDao> _mockMemberPreferencesApiDao;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockMemberPreferencesApiDao = new Mock<IMemberPreferencesApiDao>();
|
||||
_memberPreferencesApiService = new MemberPreferencesApiService(_mockMemberPreferencesApiDao.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetMemberOptInAgreementInfoByUserId_Return()
|
||||
{
|
||||
var memberOptInAgreementInformation = new MemberOptInAgreementInformation();
|
||||
_mockMemberPreferencesApiDao.Setup(x => x.GetMemberOptInAgreementInfoByUserId(It.IsAny<string>())).ReturnsAsync(memberOptInAgreementInformation);
|
||||
|
||||
var response = await _memberPreferencesApiService.GetMemberOptInAgreementInfoByUserId("11");
|
||||
Assert.IsNotNull(response);
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.GetMemberOptInAgreementInfoByUserId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMemberOptInAgreementInfoByUserId_Exception()
|
||||
{
|
||||
_mockMemberPreferencesApiDao.Setup(x => x.GetMemberOptInAgreementInfoByUserId(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _memberPreferencesApiService.GetMemberOptInAgreementInfoByUserId("11"));
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.GetMemberOptInAgreementInfoByUserId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetMemberOptInSettingsByUserId_Return()
|
||||
{
|
||||
var memberOptInSettings = new MemberOptInInformation();
|
||||
_mockMemberPreferencesApiDao.Setup(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>())).ReturnsAsync(memberOptInSettings);
|
||||
|
||||
var response = await _memberPreferencesApiService.GetMemberOptInSettingsByUserId("11");
|
||||
Assert.IsNotNull(response);
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMemberOptInSettingsByUserId_Exception()
|
||||
{
|
||||
_mockMemberPreferencesApiDao.Setup(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _memberPreferencesApiService.GetMemberOptInSettingsByUserId("11"));
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EmailSuccessfulSend_Return()
|
||||
{
|
||||
var memberOptInSettings = new MemberOptInInformation();
|
||||
_mockMemberPreferencesApiDao.Setup(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()));
|
||||
|
||||
await _memberPreferencesApiService.EmailStatusSend("11", "[email protected]", true);
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailSuccessfulSend_Exception()
|
||||
{
|
||||
_mockMemberPreferencesApiDao.Setup(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _memberPreferencesApiService.EmailStatusSend("11", "[email protected]", true));
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EmailFailureSend_Return()
|
||||
{
|
||||
_mockMemberPreferencesApiDao.Setup(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()));
|
||||
|
||||
await _memberPreferencesApiService.EmailStatusSend("11", "[email protected]", false);
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailFailureSend_Exception()
|
||||
{
|
||||
_mockMemberPreferencesApiDao.Setup(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _memberPreferencesApiService.EmailStatusSend("11", "[email protected]", false));
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
_mockMemberPreferencesApiDao.Verify(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
using LCU.API.Internal.DocumentIngestor.DataAccess;
|
||||
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Library.Internal.NotificationsModels.Models;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
|
||||
|
||||
public class NotificationApiServiceTest
|
||||
{
|
||||
private NotificationApiService _notificationApiService;
|
||||
private Mock<INotificationApiDao> _mockNotificationApiDao;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockNotificationApiDao = new Mock<INotificationApiDao>();
|
||||
_notificationApiService = new NotificationApiService(_mockNotificationApiDao.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendEmailAsync_Exception()
|
||||
{
|
||||
_mockNotificationApiDao.Setup(x => x.SendEmailAsync(It.IsAny<EmailRequest>()))
|
||||
.ThrowsAsync(new Exception("Error"));
|
||||
|
||||
var request = new EmailRequest()
|
||||
{
|
||||
Subject = "",
|
||||
Body = "",
|
||||
Recipient = new List<string>(new string[] { "" })
|
||||
};
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _notificationApiService.SendEmailAsync(request));
|
||||
_mockNotificationApiDao.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendEmailAsync_Return()
|
||||
{
|
||||
_mockNotificationApiDao.Setup(x => x.SendEmailAsync(It.IsAny<EmailRequest>()));
|
||||
|
||||
var request = new EmailRequest()
|
||||
{
|
||||
Subject = "",
|
||||
Body = "",
|
||||
Recipient = new List<string>(new string[] { "" })
|
||||
};
|
||||
|
||||
await _notificationApiService.SendEmailAsync(request);
|
||||
_mockNotificationApiDao.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Once);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user