896 lines
36 KiB
C#
896 lines
36 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Internal.MemberPreferencesApi.DataAccess;
|
|
using LCU.API.Internal.MemberPreferencesApi.Services;
|
|
using LCU.Library.Internal.MemberPreferencesApiModels.Entities;
|
|
using LCU.Library.Internal.MemberPreferencesApiModels.Enums;
|
|
using Infrastructure.Services;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Agreements;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using LCU.Library.Internal.MemberPreferencesApiModels.Requests;
|
|
using LCU.API.Internal.MemberPreferencesApiLib.Repositories;
|
|
using LCU.API.Internal.MemberPreferencesApiLib.Persistence;
|
|
using LCU.API.Internal.MemberPreferencesApi.Services.XdiServices;
|
|
using LCU.API.Internal.MemberPreferencesApi.MicroApiServices;
|
|
|
|
namespace LCU.API.Internal.MemberPreferencesApi.UnitTests.Services
|
|
{
|
|
public class MemberPreferenceServiceTest
|
|
{
|
|
private MemberPreferenceService _memberPreferenceService;
|
|
private IMemberPreferenceRepository _memberPreferenceRepository;
|
|
private IUnifiedOptInRepository _unifiedOptInRepository;
|
|
private Mock<INotificationService> _mockNotificationService;
|
|
private Mock<IIntegrationService> _mockIntegrationService;
|
|
private Mock<IXdiBatchService> _xdiBatchItemServiceMock;
|
|
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
var mockDateTime = new DateTimeService();
|
|
_mockNotificationService = new Mock<INotificationService>();
|
|
_mockIntegrationService = new Mock<IIntegrationService>();
|
|
_xdiBatchItemServiceMock = new Mock<IXdiBatchService>();
|
|
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
|
|
|
|
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.EnableSensitiveDataLogging()
|
|
.Options;
|
|
var context = new ApplicationDbContext(options);
|
|
_memberPreferenceRepository = new MemberPreferenceRepository(context);
|
|
_unifiedOptInRepository = new UnifiedOptInRepository(context);
|
|
_memberPreferenceService = new MemberPreferenceService(_memberPreferenceRepository, new UnitOfWork(context),
|
|
_unifiedOptInRepository, _mockNotificationService.Object, _mockIntegrationService.Object,
|
|
_xdiBatchItemServiceMock.Object, _mockCoreApiWrapperService.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Basic_Flow()
|
|
{
|
|
var saved = await _memberPreferenceService.GetMemberPreferencesAsync("99");
|
|
Assert.NotNull(saved);
|
|
Assert.IsEmpty(saved);
|
|
|
|
var preference = new MemberPreferenceRequest
|
|
{
|
|
UserId = "99",
|
|
Preference = PreferenceType.ENotification,
|
|
Value = "True"
|
|
};
|
|
var result = await _memberPreferenceService.SaveMemberPreferenceAsync(preference);
|
|
Assert.NotNull(result);
|
|
|
|
saved = await _memberPreferenceService.GetMemberPreferencesAsync("99");
|
|
Assert.NotNull(saved);
|
|
Assert.IsNotEmpty(saved);
|
|
}
|
|
|
|
[Test]
|
|
public async Task UnifiedOptIn_Flow()
|
|
{
|
|
var saved = await _memberPreferenceService.GetMemberPreferencesAsync("99");
|
|
Assert.NotNull(saved);
|
|
Assert.IsEmpty(saved);
|
|
|
|
_mockNotificationService
|
|
.Setup(x => x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>()));
|
|
|
|
_mockIntegrationService.Setup(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()))
|
|
.Verifiable();
|
|
|
|
var preference = new MemberOptinRequest
|
|
{
|
|
UserId = "99",
|
|
Email = "[email protected]",
|
|
Value = DeliveryPreference.Electronic,
|
|
LegalReference = "1.0.0"
|
|
};
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(preference);
|
|
|
|
saved = await _memberPreferenceService.GetMemberPreferencesAsync("99");
|
|
Assert.NotNull(saved);
|
|
Assert.IsNotEmpty(saved);
|
|
_mockIntegrationService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateMemberOptInAsync_Email_Ok()
|
|
{
|
|
_mockIntegrationService.Setup(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>())).Verifiable();
|
|
|
|
var request = new MemberOptinRequest
|
|
{
|
|
Email = "[email protected]",
|
|
Value = DeliveryPreference.Electronic,
|
|
UserId = "12",
|
|
LegalReference = ""
|
|
};
|
|
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request);
|
|
_mockIntegrationService.Verify(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateMemberOptInAsync_Paper_Ok()
|
|
{
|
|
_mockIntegrationService.Setup(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()))
|
|
.Verifiable();
|
|
|
|
var agreement = new Agreement
|
|
{
|
|
UserId = "12",
|
|
ByOrgNbr = 0,
|
|
PersonNumber = 111,
|
|
AgreementNumber = 54321
|
|
};
|
|
|
|
var accounts = new List<AgreementAccount>
|
|
{
|
|
new AgreementAccount
|
|
{
|
|
AccountNumber = 123,
|
|
TaxReportForPersonNumber = 111,
|
|
OvrDeliveryMethCD = "WWW",
|
|
AccountOwner = new AgreementAccountOwner
|
|
{
|
|
AccountNumber = 123,
|
|
PersonNumber = 111,
|
|
AgreementNumber = 54321
|
|
}
|
|
}
|
|
};
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreementByUserId("12")).ReturnsAsync(agreement).Verifiable();
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreementAccountsByUserId("12")).ReturnsAsync(accounts)
|
|
.Verifiable();
|
|
|
|
var request = new MemberOptinRequest
|
|
{
|
|
Value = DeliveryPreference.Paper,
|
|
UserId = "12",
|
|
LegalReference = ""
|
|
};
|
|
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request);
|
|
_mockIntegrationService.Verify(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()), Times.Once);
|
|
_mockCoreApiWrapperService.Verify();
|
|
_mockCoreApiWrapperService.Verify(x => x.UpdateAgreementAccountsDeliveryMethod(It.Is<List<long>>(l => l.Contains(123)), It.Is<string>(d => d.Equals("PRNT")), It.Is<string>(u => u.Equals("12"))), Times.Once());
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateMemberOptInAsync_Electronic_Ok()
|
|
{
|
|
_mockIntegrationService.Setup(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()))
|
|
.Verifiable();
|
|
|
|
var agreement = new Agreement
|
|
{
|
|
UserId = "12",
|
|
ByOrgNbr = 0,
|
|
PersonNumber = 111,
|
|
AgreementNumber = 54321
|
|
};
|
|
|
|
var accounts = new List<AgreementAccount>
|
|
{
|
|
new AgreementAccount
|
|
{
|
|
AccountNumber = 123,
|
|
TaxReportForPersonNumber = 111,
|
|
OvrDeliveryMethCD = "PRNT",
|
|
AccountOwner = new AgreementAccountOwner
|
|
{
|
|
AccountNumber = 123,
|
|
PersonNumber = 111,
|
|
AgreementNumber = 54321
|
|
}
|
|
}
|
|
};
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreementByUserId("12")).ReturnsAsync(agreement).Verifiable();
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreementAccountsByUserId("12")).ReturnsAsync(accounts).Verifiable();
|
|
|
|
var request = new MemberOptinRequest
|
|
{
|
|
Email = "[email protected]",
|
|
Value = DeliveryPreference.Electronic,
|
|
UserId = "12",
|
|
LegalReference = ""
|
|
};
|
|
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request);
|
|
_mockIntegrationService.Verify(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()), Times.Once);
|
|
_mockCoreApiWrapperService.Verify();
|
|
_mockCoreApiWrapperService.Verify(x => x.UpdateAgreementAccountsDeliveryMethod(It.Is<List<long>>(l => l.Contains(123)), It.Is<string>(d => d.Equals("WWW")), It.Is<string>(u => u.Equals("12"))), Times.Once());
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateMemberOptInAsync_Organization_Electronic_Ok()
|
|
{
|
|
_mockIntegrationService.Setup(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>())).Verifiable();
|
|
|
|
var agreement = new Agreement
|
|
{
|
|
UserId = "12",
|
|
PersonNumber = 111,
|
|
ByOrgNbr = 112,
|
|
AgreementNumber = 54321
|
|
};
|
|
|
|
var organizationAccounts = new List<AgreementAccount>
|
|
{
|
|
new AgreementAccount
|
|
{
|
|
AccountNumber = 123,
|
|
TaxReportForOrgNumber = 112,
|
|
AccountOwner = new AgreementAccountOwner
|
|
{
|
|
AccountNumber = 123,
|
|
PersonNumber = 111,
|
|
AgreementNumber = 54321
|
|
}
|
|
},
|
|
new AgreementAccount
|
|
{
|
|
AccountNumber = 124,
|
|
TaxReportForOrgNumber = 112,
|
|
AccountOwner = new AgreementAccountOwner
|
|
{
|
|
AccountNumber = 124,
|
|
PersonNumber = 115,
|
|
AgreementNumber = 5432
|
|
}
|
|
},
|
|
new AgreementAccount
|
|
{
|
|
AccountNumber = 125,
|
|
TaxReportForOrgNumber = 112,
|
|
AccountOwner = new AgreementAccountOwner
|
|
{
|
|
AccountNumber = 125,
|
|
PersonNumber = 111,
|
|
AgreementNumber = 54321
|
|
}
|
|
}
|
|
};
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreementByUserId("12")).ReturnsAsync(agreement).Verifiable();
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreementAccountsByOrganizationId(112)).ReturnsAsync(organizationAccounts).Verifiable();
|
|
|
|
var request = new MemberOptinRequest
|
|
{
|
|
Email = "[email protected]",
|
|
Value = DeliveryPreference.Electronic,
|
|
UserId = "12",
|
|
LegalReference = ""
|
|
};
|
|
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request);
|
|
_mockIntegrationService.Verify(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()), Times.Once);
|
|
_mockCoreApiWrapperService.Verify();
|
|
_mockCoreApiWrapperService.Verify(x => x.UpdateAgreementAccountsDeliveryMethod(It.Is<List<long>>(l => l.Contains(123) && l.Contains(125)), It.Is<string>(d => d.Equals("WWW")), It.Is<string>(u => u.Equals("12"))), Times.Once());
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateMemberOptInAsync_Email_RequiresValidEmail()
|
|
{
|
|
_mockIntegrationService.Setup(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()))
|
|
.Verifiable();
|
|
|
|
var request = new MemberOptinRequest
|
|
{
|
|
Email = "gmail",
|
|
Value = DeliveryPreference.Electronic,
|
|
UserId = "12",
|
|
LegalReference = ""
|
|
};
|
|
|
|
Assert.ThrowsAsync<FormatException>(async () =>
|
|
{
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request);
|
|
});
|
|
|
|
_mockIntegrationService.Verify(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateMemberOptInAsync_Email_RequiresEmail()
|
|
{
|
|
_mockIntegrationService.Setup(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()))
|
|
.Verifiable();
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
Value = DeliveryPreference.Electronic,
|
|
UserId = "12",
|
|
LegalReference = ""
|
|
};
|
|
|
|
Assert.ThrowsAsync<ArgumentNullException>(async () =>
|
|
{
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request);
|
|
});
|
|
|
|
_mockIntegrationService.Verify(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateMemberOptInAsync_DoesNothing_If_Invalid_Value_Ok()
|
|
{
|
|
_mockIntegrationService.Setup(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()))
|
|
.Verifiable();
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
Email = "[email protected]",
|
|
Value = DeliveryPreference.Electronic,
|
|
UserId = "12",
|
|
LegalReference = ""
|
|
};
|
|
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request);
|
|
_mockIntegrationService.Verify(x => x.NotifyListeners(It.IsAny<MemberOptInSettings>()), Times.Once);
|
|
}
|
|
|
|
[TestCase(PreferenceType.EStatements, "Paper", false)]
|
|
[TestCase(PreferenceType.EStatements, "Email", true)]
|
|
[TestCase(PreferenceType.EStatementsEmail, "[email protected]", false)]
|
|
[TestCase(PreferenceType.EStatements, "[email protected]", true)]
|
|
[TestCase(PreferenceType.ENotificationsEmail, "[email protected]", false)]
|
|
[TestCase(PreferenceType.ENotification, "[email protected]", true)]
|
|
[TestCase(PreferenceType.UnifiedOptInEmail, "[email protected]", false)]
|
|
[TestCase(PreferenceType.UnifiedOptIn, "Electronic", false)]
|
|
public void IsExternalUpdateNecessary_NoUnified_OK(PreferenceType pref, string requestValue, bool assertion)
|
|
{
|
|
var settings = new MemberOptInSettings()
|
|
{
|
|
ENotifications = "Paper",
|
|
EStatements = "Paper",
|
|
EStatementsEmail = "[email protected]",
|
|
ENotificationsEmail = "[email protected]",
|
|
};
|
|
|
|
var request = new MemberPreferenceRequest()
|
|
{
|
|
Preference = pref,
|
|
Value = requestValue
|
|
};
|
|
|
|
Assert.AreEqual(assertion, _memberPreferenceService.IsExternalUpdateNecessary(settings, request));
|
|
}
|
|
|
|
[TestCase(PreferenceType.EStatements, "Paper", false)]
|
|
[TestCase(PreferenceType.EStatements, "Email", true)]
|
|
[TestCase(PreferenceType.EStatementsEmail, "[email protected]", false)]
|
|
[TestCase(PreferenceType.EStatements, "[email protected]", true)]
|
|
[TestCase(PreferenceType.ENotificationsEmail, "[email protected]", false)]
|
|
[TestCase(PreferenceType.ENotification, "[email protected]", true)]
|
|
[TestCase(PreferenceType.UnifiedOptInEmail, "[email protected]", false)]
|
|
[TestCase(PreferenceType.UnifiedOptInEmail, "[email protected]", true)]
|
|
[TestCase(PreferenceType.UnifiedOptIn, "Electronic", true)]
|
|
[TestCase(PreferenceType.UnifiedOptIn, "Paper", false)]
|
|
public void IsExternalUpdateNecessary_HasUnified_OK(PreferenceType pref, string requestValue, bool assertion)
|
|
{
|
|
var settings = new MemberOptInSettings()
|
|
{
|
|
ENotifications = "Paper",
|
|
EStatements = "Paper",
|
|
EStatementsEmail = "[email protected]",
|
|
ENotificationsEmail = "[email protected]",
|
|
UnifiedOptInEmail = "[email protected]",
|
|
UniversalOptIn = "Paper"
|
|
};
|
|
|
|
var request = new MemberPreferenceRequest()
|
|
{
|
|
Preference = pref,
|
|
Value = requestValue
|
|
};
|
|
|
|
Assert.AreEqual(assertion, _memberPreferenceService.IsExternalUpdateNecessary(settings, request));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SaveMemberPreferencesDefault_OK()
|
|
{
|
|
var paperDefault =
|
|
new MemberPreferenceRequest()
|
|
{
|
|
UserId = "100",
|
|
Preference = PreferenceType.UnifiedOptIn,
|
|
Value = "Paper",
|
|
LegalReference = "test",
|
|
};
|
|
|
|
var result =
|
|
await _memberPreferenceService.SaveMemberPreferenceDefaultAsync(paperDefault, "1337",
|
|
UserType.Associate,
|
|
DateTime.Parse("2021-02-12"));
|
|
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual("1337", result.LastUpdatedBy);
|
|
Assert.AreEqual(DateTime.Parse("2021-02-12"), result.LastUpdated);
|
|
Assert.AreEqual(UserType.Associate, result.LastUpdatedByType);
|
|
}
|
|
|
|
[Test]
|
|
public void SaveMemberPreferences_Null_ThrowsArgumentException()
|
|
{
|
|
Assert.ThrowsAsync<ArgumentException>(async () =>
|
|
await _memberPreferenceService.SaveMemberPreferencesAsync(null));
|
|
}
|
|
|
|
[Test]
|
|
public void SaveMemberPreferences_Empty_ThrowsArgumentException()
|
|
{
|
|
Assert.ThrowsAsync<ArgumentException>(async () =>
|
|
await _memberPreferenceService.SaveMemberPreferencesAsync(new List<MemberPreferenceRequest>()));
|
|
}
|
|
|
|
[Test]
|
|
public void SaveMemberPreferences_HasPendingXdiUpdate_PendingUpdatesException()
|
|
{
|
|
var preference = new List<MemberPreferenceRequest>
|
|
{
|
|
new MemberPreferenceRequest
|
|
{
|
|
Preference = PreferenceType.UnifiedOptIn,
|
|
Value = "Paper",
|
|
UserId = "222"
|
|
}
|
|
};
|
|
|
|
_xdiBatchItemServiceMock.Setup(x => x.DoesMemberHavePendingXdiChange("222")).ReturnsAsync(true).Verifiable();
|
|
|
|
Assert.ThrowsAsync<Exception>(async () => await _memberPreferenceService.SaveMemberPreferencesAsync(preference));
|
|
_xdiBatchItemServiceMock.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task SaveMemberPreferencesDefault_NoChange_OK()
|
|
{
|
|
await _memberPreferenceService.SaveMemberPreferencesAsync(new List<MemberPreferenceRequest>()
|
|
{
|
|
new MemberPreferenceRequest()
|
|
{
|
|
UserId = "100",
|
|
Preference = PreferenceType.UnifiedOptIn,
|
|
Value = "Electronic",
|
|
LegalReference = "test",
|
|
},
|
|
new MemberPreferenceRequest()
|
|
{
|
|
UserId = "100",
|
|
Preference = PreferenceType.EStatements,
|
|
Value = "Electronic",
|
|
LegalReference = "test",
|
|
},
|
|
}
|
|
);
|
|
|
|
var emailRequests =
|
|
new MemberPreferenceRequest()
|
|
{
|
|
UserId = "100",
|
|
Preference = PreferenceType.UnifiedOptIn,
|
|
Value = "Electronic",
|
|
LegalReference = "test",
|
|
};
|
|
|
|
var result =
|
|
await _memberPreferenceService.SaveMemberPreferenceDefaultAsync(emailRequests, "1337", UserType.System,
|
|
DateTime.Parse("2021-02-12"));
|
|
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual("Electronic", result.UniversalOptIn);
|
|
Assert.AreEqual("Electronic", result.EStatements);
|
|
Assert.AreNotEqual(DateTime.Parse("2021-02-12"), result.LastUpdatedBy);
|
|
Assert.AreNotEqual("1337", result.LastUpdated);
|
|
Assert.AreEqual(UserType.System, result.LastUpdatedByType);
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateMemberOptInAsync_BadEmail()
|
|
{
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Electronic,
|
|
Email = "234@",
|
|
LegalReference = "none"
|
|
};
|
|
|
|
Assert.ThrowsAsync<FormatException>(async () =>
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request));
|
|
|
|
request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Electronic,
|
|
LegalReference = "none"
|
|
};
|
|
|
|
Assert.ThrowsAsync<ArgumentNullException>(async () =>
|
|
await _memberPreferenceService.UpdateMemberOptinAsync(request));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendOptInChangeNotification_Unknown_To_Paper()
|
|
{
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Paper,
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, null);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>()), Times.Never);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendOptInChangeNotification_Unknown_To_Paper_IgnoresRequestEmail()
|
|
{
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Paper,
|
|
Email = "[email protected]",
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, null);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>()), Times.Never);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendOptInChangeNotification_Email_To_Paper()
|
|
{
|
|
var existing = new MemberOptInSettings()
|
|
{
|
|
EStatements = DeliveryPreference.Electronic,
|
|
EStatementsEmail = "[email protected]",
|
|
ENotifications = DeliveryPreference.Electronic,
|
|
ENotificationsEmail = "[email protected]",
|
|
|
|
UnifiedOptInEmail = "[email protected]",
|
|
UniversalOptIn = DeliveryPreference.Electronic
|
|
};
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Paper,
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, existing);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>()), Times.Never);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.Is<List<string>>(emails => emails.Count == 1)));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendOptInChangeNotification_Email_To_Paper_IgnoreRequestEmail()
|
|
{
|
|
var existing = new MemberOptInSettings()
|
|
{
|
|
EStatements = DeliveryPreference.Electronic,
|
|
EStatementsEmail = "[email protected]",
|
|
ENotifications = DeliveryPreference.Electronic,
|
|
ENotificationsEmail = "[email protected]",
|
|
|
|
UnifiedOptInEmail = "[email protected]",
|
|
UniversalOptIn = DeliveryPreference.Electronic
|
|
};
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Paper,
|
|
Email = "[email protected]",
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, existing);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>()), Times.Never);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.Is<List<string>>(emails => emails.Count == 1)));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendOptInChangeNotification_Paper_To_Email()
|
|
{
|
|
var existing = new MemberOptInSettings()
|
|
{
|
|
EStatements = DeliveryPreference.Electronic,
|
|
EStatementsEmail = "[email protected]",
|
|
ENotifications = DeliveryPreference.Electronic,
|
|
ENotificationsEmail = "[email protected]",
|
|
|
|
UnifiedOptInEmail = "[email protected]",
|
|
UniversalOptIn = DeliveryPreference.Paper
|
|
};
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Electronic,
|
|
Email = "[email protected]",
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, existing);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.Is<List<string>>(emails => emails.Count == 1),
|
|
It.IsAny<MemberOptinRequest>()));
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendOptInChangeNotification_Unknown_To_Email()
|
|
{
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Electronic,
|
|
Email = "[email protected]",
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, null);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.Is<List<string>>(emails => emails.Count == 1),
|
|
It.IsAny<MemberOptinRequest>()));
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendOptInChangeNotification_Email_To_Email_NoChange()
|
|
{
|
|
var existing = new MemberOptInSettings()
|
|
{
|
|
EStatements = DeliveryPreference.Electronic,
|
|
EStatementsEmail = "[email protected]",
|
|
ENotifications = DeliveryPreference.Electronic,
|
|
ENotificationsEmail = "[email protected]",
|
|
|
|
UnifiedOptInEmail = "[email protected]",
|
|
UniversalOptIn = DeliveryPreference.Electronic
|
|
};
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Electronic,
|
|
Email = "[email protected]",
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, existing);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>()), Times.Never);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SendOptInChangeNotification_Email_To_Email_IsChange()
|
|
{
|
|
var existing = new MemberOptInSettings()
|
|
{
|
|
EStatements = DeliveryPreference.Electronic,
|
|
EStatementsEmail = "[email protected]",
|
|
ENotifications = DeliveryPreference.Electronic,
|
|
ENotificationsEmail = "[email protected]",
|
|
|
|
UnifiedOptInEmail = "[email protected]",
|
|
UniversalOptIn = DeliveryPreference.Electronic
|
|
};
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Electronic,
|
|
Email = "[email protected]",
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, existing);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendEmailChangeNotifications(It.Is<List<string>>(emails => emails.Count == 2),
|
|
It.IsAny<MemberOptinRequest>()));
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>()), Times.Never);
|
|
}
|
|
|
|
[TestCase("[email protected]", "[email protected]", 3)]
|
|
[TestCase("[email protected]", "[email protected]", 3)]
|
|
[TestCase("[email protected]", "[email protected]", 3)]
|
|
[TestCase("[email protected]", "[email protected]", 3)]
|
|
[TestCase(null, "[email protected]", 2)]
|
|
[TestCase("[email protected]", null, 2)]
|
|
public async Task SendOptInChangeNotification_Historic_To_Email(string eStatementsEmail,
|
|
string eNotificationsEmail, int optInEmailCount)
|
|
{
|
|
var existing = new MemberOptInSettings()
|
|
{
|
|
EStatements = DeliveryPreference.Electronic,
|
|
EStatementsEmail = eStatementsEmail,
|
|
ENotifications = DeliveryPreference.Electronic,
|
|
ENotificationsEmail = eNotificationsEmail
|
|
};
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Electronic,
|
|
Email = "[email protected]",
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, existing);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.Is<List<string>>(emails => emails.Count == optInEmailCount),
|
|
It.IsAny<MemberOptinRequest>()));
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>()), Times.Never);
|
|
}
|
|
|
|
[TestCase("[email protected]", "[email protected]", 2)]
|
|
[TestCase("[email protected]", "[email protected]", 2)]
|
|
[TestCase("[email protected]", "[email protected]", 2)]
|
|
[TestCase("[email protected]", "[email protected]", 2)]
|
|
[TestCase(null, "[email protected]", 1)]
|
|
[TestCase("[email protected]", null, 1)]
|
|
public async Task SendOptInChangeNotification_Historic_To_Paper(string eStatementsEmail,
|
|
string eNotificationsEmail, int optOutEmailCount)
|
|
{
|
|
var existing = new MemberOptInSettings
|
|
{
|
|
EStatements = DeliveryPreference.Electronic,
|
|
EStatementsEmail = eStatementsEmail,
|
|
ENotifications = DeliveryPreference.Electronic,
|
|
ENotificationsEmail = eNotificationsEmail
|
|
};
|
|
|
|
var request = new MemberOptinRequest()
|
|
{
|
|
UserId = "100",
|
|
Value = DeliveryPreference.Paper,
|
|
LegalReference = "none"
|
|
};
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>())).Verifiable();
|
|
|
|
_mockNotificationService.Setup(x =>
|
|
x.SendOptOutNotifications(It.IsAny<List<string>>())).Verifiable();
|
|
|
|
await _memberPreferenceService.SendOptInChangeNotifications(request, existing);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptInNotifications(It.IsAny<List<string>>(), It.IsAny<MemberOptinRequest>()), Times.Never);
|
|
|
|
_mockNotificationService.Verify(x =>
|
|
x.SendOptOutNotifications(It.Is<List<string>>(emails => emails.Count == optOutEmailCount)));
|
|
}
|
|
|
|
[TestCase(DeliveryPreference.Paper, "[email protected]", DeliveryPreference.Electronic,
|
|
"[email protected]", 1)]
|
|
[TestCase(DeliveryPreference.Electronic, "[email protected]", DeliveryPreference.Paper,
|
|
"[email protected]", 1)]
|
|
[TestCase(DeliveryPreference.Electronic, "[email protected]", DeliveryPreference.Electronic,
|
|
"[email protected]", 2)]
|
|
[TestCase(DeliveryPreference.Electronic, "", DeliveryPreference.Electronic, "[email protected]", 1)]
|
|
[TestCase(DeliveryPreference.Electronic, "[email protected]", DeliveryPreference.Electronic, null, 1)]
|
|
[TestCase(DeliveryPreference.Paper, "[email protected]", DeliveryPreference.Paper,
|
|
"[email protected]", 0)]
|
|
public void TryAddHistoricEmails_Ok(string eNotificationsValue, string eNotificationsEmail,
|
|
string eStatementsValue, string eStatementsEmail, int assertCount)
|
|
{
|
|
var ogSettings = new MemberOptInSettings()
|
|
{
|
|
ENotifications = eNotificationsValue,
|
|
ENotificationsEmail = eNotificationsEmail,
|
|
EStatements = eStatementsValue,
|
|
EStatementsEmail = eStatementsEmail
|
|
};
|
|
|
|
var affectedEmails = new List<string>();
|
|
|
|
_memberPreferenceService.TryAddHistoricEmails(ogSettings, affectedEmails);
|
|
|
|
Assert.AreEqual(assertCount, affectedEmails.Count);
|
|
}
|
|
}
|
|
}
|