using System; using System.Collections.Generic; using Moq; using NUnit.Framework; using LCU.API.Internal.MemberPreferencesApiLib.Repositories; using LCU.API.Internal.MemberPreferencesApi.Services.XdiServices; using LCU.API.Internal.MemberPreferencesApi.Configuration; using LCU.Library.Internal.MemberPreferencesApiModels.Entities; using LCU.Library.Internal.MemberPreferencesApiModels.Enums; using LCU.Library.Internal.LcuMassTransitModels; using LCU.API.Internal.MemberPreferencesApi.MicroApiServices; namespace LCU.API.Internal.MemberPreferencesApi.IntegrationTests { public class XdiTransferTest { private IXdiBatchService _xdiBatchItemService; private Mock _mockBatchItemsRepository; private Mock _mockUnitOfWork; private XdiSftpApiConfiguration _xdiSftpConfiguration; private FtpApiConfiguration _ftpConfiguration; private Mock _mockUnifiedOptinRepository; private Mock _mockMemberPreferenceRepository; private Mock _mockFtpApiService; private ConnectionConfiguration _connectionConfiguration; private ReceiveEndpointConfiguration _completionReceiveEndpoint; private ReceiveEndpointConfigurations _endpointConfiguration; [SetUp] public void Setup() { _mockFtpApiService = new Mock(); _connectionConfiguration = new ConnectionConfiguration(); _mockBatchItemsRepository = new Mock(); _mockMemberPreferenceRepository = new Mock(); _endpointConfiguration = new ReceiveEndpointConfigurations(); _completionReceiveEndpoint = _endpointConfiguration.XdiBatchConfirmEndpoint; _mockUnitOfWork = new Mock(); _ftpConfiguration = new FtpApiConfiguration() { Url = "https://qa-ftpapi.lcu-internal.com/api/" }; _xdiSftpConfiguration = new XdiSftpApiConfiguration() { HostName = "sftp.xdi.com", UserName = "LANDMARKCU", PortNumber = 22, Password = "FILLMEIN", Fingerprint = "ssh-dss 2048 12:78:33:0a:cf:71:21:e2:8b:0e:ef:6a:8a:c6:8e:4f" }; _mockUnifiedOptinRepository = new Mock(); _xdiBatchItemService = new XdiBatchService(_mockBatchItemsRepository.Object, _mockUnitOfWork.Object, _xdiSftpConfiguration, _mockUnifiedOptinRepository.Object, _mockMemberPreferenceRepository.Object, _connectionConfiguration, _endpointConfiguration, _mockFtpApiService.Object); } [Ignore("This will actually create the items and FTP them to XDI Test Folder. Be Careful. Fill in password.")] public void Test_Send_Test_Files() { IReadOnlyCollection items = new List() { new XdiBatchItem() { Created = DateTime.Now, BatchState = BatchState.New, LastUpdated = DateTime.Now, UserId = "99" }, new XdiBatchItem() { Created = DateTime.Now, BatchState = BatchState.New, LastUpdated = DateTime.Now, UserId = "100" }, new XdiBatchItem() { Created = DateTime.Now, BatchState = BatchState.New, LastUpdated = DateTime.Now, UserId = "101" }, new XdiBatchItem() { Created = DateTime.Now, BatchState = BatchState.New, LastUpdated = DateTime.Now, UserId = "102" }, new XdiBatchItem() { Created = DateTime.Now, BatchState = BatchState.New, LastUpdated = DateTime.Now, UserId = "103" } }; var settings = new List() { new MemberOptInSettings() { Id = 1000, UniversalOptIn = DeliveryPreference.Paper, ENotifications = DeliveryPreference.Electronic, EStatements = DeliveryPreference.Electronic, UnifiedOptInEmail = "test@test.com", ENotificationsEmail = "test@test.com", EStatementsEmail = "test@test.com", LastUpdated = DateTime.Now, LegalDate = DateTime.Now, LegalVersion = "1.2.3", UserId = "99", CreatedByType = UserType.Associate, LastUpdatedByType = UserType.System, CreatedBy = "test", Created = DateTime.Now, LastUpdatedBy = "test" }, new MemberOptInSettings() { Id = 1001, UniversalOptIn = DeliveryPreference.Paper, ENotifications = null, EStatements = DeliveryPreference.Electronic, UnifiedOptInEmail = "test@test.com", ENotificationsEmail = null, EStatementsEmail = "test@test.com", UserId = "100" }, new MemberOptInSettings() { Id = 1002, UniversalOptIn = DeliveryPreference.Electronic, ENotifications = DeliveryPreference.Paper, EStatements = DeliveryPreference.Paper, UnifiedOptInEmail = "test@test.com", ENotificationsEmail = "test@test.com", EStatementsEmail = "test@test.com", UserId = "101" }, new MemberOptInSettings() { Id = 1003, UniversalOptIn = DeliveryPreference.Electronic, ENotifications = null, EStatements = DeliveryPreference.Paper, UnifiedOptInEmail = "test@test.com", ENotificationsEmail = null, EStatementsEmail = null, UserId = "102" }, new MemberOptInSettings() { Id = 1004, UniversalOptIn = DeliveryPreference.Electronic, ENotifications = DeliveryPreference.Electronic, EStatements = DeliveryPreference.Electronic, UnifiedOptInEmail = "updated_email@test.com", ENotificationsEmail = "test@test.com", EStatementsEmail = "test@test.com", UserId = "103" } }; _mockBatchItemsRepository.Setup(x => x.GetXdiBatchItems()).ReturnsAsync(items); foreach (var setting in settings) { _mockUnifiedOptinRepository.Setup(x => x.GetMemberOptInSettings(setting.UserId)) .ReturnsAsync(setting); } _mockBatchItemsRepository.Setup(x => x.SaveAsync(It.IsAny())).Verifiable(); _mockBatchItemsRepository.Setup(x => x.Delete(It.IsAny())).Verifiable(); } } }