Files
T
2026-05-04 10:09:55 -05:00

160 lines
6.6 KiB
C#

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.Library.Internal.MemberPreferencesApiModels.Entities;
using LCU.Library.Internal.MemberPreferencesApiModels.Enums;
using LCU.API.Internal.MemberPreferencesApi.MicroApiServices;
namespace LCU.API.Internal.MemberPreferencesApi.IntegrationTests
{
public class XdiBatchItemTest
{
private IXdiBatchService _xdiBatchItemService;
private Mock<IXdiBatchItemsRepository> _mockBatchItemsRepository;
private Mock<IUnitOfWork> _mockUnitOfWork;
private Mock<IUnifiedOptInRepository> _mockUnifiedOptinRepository;
private Mock<IMemberPreferenceRepository> _mockMemberPreferenceRepository;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockUnifiedOptinRepository = new Mock<IUnifiedOptInRepository>();
_mockBatchItemsRepository = new Mock<IXdiBatchItemsRepository>();
_mockUnitOfWork = new Mock<IUnitOfWork>();
_mockUnifiedOptinRepository = new Mock<IUnifiedOptInRepository>();
_mockMemberPreferenceRepository = new Mock<IMemberPreferenceRepository>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_xdiBatchItemService = new XdiBatchService(_mockBatchItemsRepository.Object, _mockUnitOfWork.Object,
_mockUnifiedOptinRepository.Object, _mockMemberPreferenceRepository.Object,
_mockFileOperationsApiService.Object);
}
[Test]
public void Test_XdiBatchItem_Setup()
{
IReadOnlyCollection<XdiBatchItem> items = new List<XdiBatchItem>()
{
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<MemberOptInSettings>()
{
new MemberOptInSettings()
{
Id = 1000,
UniversalOptIn = DeliveryPreference.Paper,
ENotifications = DeliveryPreference.Electronic,
EStatements = DeliveryPreference.Electronic,
UnifiedOptInEmail = "[email protected]",
ENotificationsEmail = "[email protected]",
EStatementsEmail = "[email protected]",
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 = "[email protected]",
ENotificationsEmail = null,
EStatementsEmail = "[email protected]",
UserId = "100"
},
new MemberOptInSettings()
{
Id = 1002,
UniversalOptIn = DeliveryPreference.Electronic,
ENotifications = DeliveryPreference.Paper,
EStatements = DeliveryPreference.Paper,
UnifiedOptInEmail = "[email protected]",
ENotificationsEmail = "[email protected]",
EStatementsEmail = "[email protected]",
UserId = "101"
},
new MemberOptInSettings()
{
Id = 1003,
UniversalOptIn = DeliveryPreference.Electronic,
ENotifications = null,
EStatements = DeliveryPreference.Paper,
UnifiedOptInEmail = "[email protected]",
ENotificationsEmail = null,
EStatementsEmail = null,
UserId = "102"
},
new MemberOptInSettings()
{
Id = 1004,
UniversalOptIn = DeliveryPreference.Electronic,
ENotifications = DeliveryPreference.Electronic,
EStatements = DeliveryPreference.Electronic,
UnifiedOptInEmail = "[email protected]",
ENotificationsEmail = "[email protected]",
EStatementsEmail = "[email protected]",
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<XdiBatchItem>())).Verifiable();
_mockBatchItemsRepository.Setup(x => x.Delete(It.IsAny<XdiBatchItem>())).Verifiable();
}
}
}