This commit is contained in:
Zeeshaun
2026-03-31 16:43:12 -05:00
parent 9be174da46
commit d639027028
198 changed files with 111474 additions and 0 deletions
@@ -0,0 +1,76 @@
using LCU.API.Internal.MemberPreferencesApi.Services;
using LCU.Library.Internal.MemberPreferencesApiModels.Entities;
using LCU.Library.Internal.MemberPreferencesApiModels.Enums;
using Infrastructure.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LCU.API.Internal.MemberPreferencesApiLib.Persistence;
using LCU.API.Internal.MemberPreferencesApiLib.Repositories;
namespace LCU.API.Internal.MemberPreferencesApi.UnitTests.Repository
{
public class DnaAuditProcessRepositoryTest
{
private ApplicationDbContext _context;
private DnaAuditProcessRepository _repository;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging()
.Options;
_context = new ApplicationDbContext(options);
_repository = new DnaAuditProcessRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var saved = await _repository.GetAllDnaAuditProcesses();
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var dnaProcess = new DnaAuditProcess()
{
ProcessId = 1,
DnaProcessType = DnaAuditProcessType.DNAAccounts,
LastUpdated = DateTime.Now,
ConsecutiveFailures = 2
};
await _context.AddAsync(dnaProcess);
await _context.SaveChangesAsync();
saved = await _repository.GetAllDnaAuditProcesses();
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
var first = saved.First();
Assert.AreEqual(first.ConsecutiveFailures, 2);
Assert.AreEqual(first.DnaProcessType, DnaAuditProcessType.DNAAccounts);
Assert.AreEqual(first.ProcessId, 1);
dnaProcess.DnaProcessType = DnaAuditProcessType.DNAOrganization;
dnaProcess.ConsecutiveFailures = 0;
await _repository.Update(dnaProcess);
saved = await _repository.GetAllDnaAuditProcesses();
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
first = saved.First();
Assert.AreEqual(first.ConsecutiveFailures, 0);
Assert.AreEqual(first.DnaProcessType, DnaAuditProcessType.DNAOrganization);
Assert.AreEqual(first.ProcessId, 1);
}
}
}
@@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.MemberPreferencesApi.Services;
using LCU.Library.Internal.MemberPreferencesApiModels.Entities;
using LCU.Library.Internal.MemberPreferencesApiModels.Enums;
using Infrastructure.Services;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.MemberPreferencesApiLib.Persistence;
using LCU.API.Internal.MemberPreferencesApiLib.Repositories;
namespace LCU.API.Internal.MemberPreferencesApi.UnitTests.Repository
{
public class MemberPreferenceRepositoryTest
{
private ApplicationDbContext _context;
private MemberPreferenceRepository _repository;
private UnifiedOptInRepository _optInRepository;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging()
.Options;
_context = new ApplicationDbContext(options);
_repository = new MemberPreferenceRepository(_context);
_optInRepository = new UnifiedOptInRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var saved = await _repository.GetMemberPreferencesAsync("99");
Assert.NotNull(saved);
Assert.IsEmpty(saved);
await _repository.SaveMemberPreferenceAsync(new MemberPreference
{
UserId = "99",
Preference = PreferenceType.ENotification,
Value = "True"
});
await _context.SaveChangesAsync();
saved = await _repository.GetMemberPreferencesAsync("99");
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
var first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
Assert.NotNull(first.LastUpdatedBy);
Assert.NotNull(first.LastUpdated);
}
[Test]
public async Task Bulk_Flow_Test()
{
var memberResult = await _optInRepository.GetMemberOptInSettings("99");
Assert.Null(memberResult);
var listOfPreferences = new List<MemberPreference>
{
new MemberPreference
{
UserId = "99",
Preference = PreferenceType.EStatements,
Value = "True"
},
new MemberPreference
{
UserId = "100",
Preference = PreferenceType.EStatements,
Value = "True"
},
new MemberPreference
{
UserId = "101",
Preference = PreferenceType.EStatements,
Value = "True"
}
};
await _repository.BulkSaveMemberPreferenceAsync(listOfPreferences);
await _context.SaveChangesAsync();
var saved = await _repository.GetMemberPreferencesAsync("99");
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
var first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
Assert.NotNull(first.LastUpdatedBy);
Assert.NotNull(first.LastUpdated);
saved = await _repository.GetMemberPreferencesAsync("100");
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
Assert.NotNull(first.LastUpdatedBy);
Assert.NotNull(first.LastUpdated);
saved = await _repository.GetMemberPreferencesAsync("101");
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
Assert.NotNull(first.LastUpdatedBy);
Assert.NotNull(first.LastUpdated);
memberResult = await _optInRepository.GetMemberOptInSettings("99");
Assert.NotNull(memberResult);
Assert.AreEqual("True", memberResult.EStatements);
memberResult = await _optInRepository.GetMemberOptInSettings("100");
Assert.NotNull(memberResult);
Assert.AreEqual("True", memberResult.EStatements);
memberResult = await _optInRepository.GetMemberOptInSettings("101");
Assert.NotNull(memberResult);
Assert.AreEqual("True", memberResult.EStatements);
listOfPreferences = new List<MemberPreference>
{
new MemberPreference
{
UserId = "99",
Preference = PreferenceType.ENotification,
Value = "Yes"
},
new MemberPreference
{
UserId = "100",
Preference = PreferenceType.ENotification,
Value = "Yes"
},
new MemberPreference
{
UserId = "101",
Preference = PreferenceType.ENotification,
Value = "Yes"
}
};
await _repository.BulkSaveMemberPreferenceAsync(listOfPreferences);
memberResult = await _optInRepository.GetMemberOptInSettings("99");
Assert.AreEqual(1, saved.Count);
Assert.NotNull(memberResult);
Assert.AreEqual("Yes", memberResult.ENotifications);
memberResult = await _optInRepository.GetMemberOptInSettings("100");
Assert.AreEqual(1, saved.Count);
Assert.NotNull(memberResult);
Assert.AreEqual("Yes", memberResult.ENotifications);
memberResult = await _optInRepository.GetMemberOptInSettings("101");
Assert.AreEqual(1, saved.Count);
Assert.NotNull(memberResult);
Assert.AreEqual("Yes", memberResult.ENotifications);
}
}
}
@@ -0,0 +1,49 @@
using System;
using System.Threading.Tasks;
using LCU.API.Internal.MemberPreferencesApi.Services;
using LCU.Library.Internal.MemberPreferencesApiModels.Entities;
using LCU.Library.Internal.MemberPreferencesApiModels.Enums;
using Infrastructure.Services;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.MemberPreferencesApiLib.Persistence;
using LCU.API.Internal.MemberPreferencesApiLib.Repositories;
namespace LCU.API.Internal.MemberPreferencesApi.UnitTests.Repository
{
public class UnifiedOptInRepositoryTest
{
private ApplicationDbContext _context;
private UnifiedOptInRepository _optInRepository;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging()
.Options;
_context = new ApplicationDbContext(options);
_optInRepository = new UnifiedOptInRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var memberResult = await _optInRepository.GetMemberOptInSettings("99");
Assert.Null(memberResult);
memberResult = await _optInRepository.GetOrCreateMemberOptinSettings("99");
await _context.SaveChangesAsync();
Assert.NotNull(memberResult);
// Make sure our Auditable is working.
Assert.NotNull(memberResult.CreatedBy);
Assert.NotNull(memberResult.Created);
Assert.NotNull(memberResult.LastUpdatedBy);
Assert.NotNull(memberResult.LastUpdated);
}
}
}