This commit is contained in:
Zeeshaun
2026-03-17 09:53:09 -05:00
parent cdcba54aa4
commit 1a0702a79a
590 changed files with 62058 additions and 0 deletions
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
namespace Application.UnitTests.Repository
{
public class AccountingRepositoryTest
{
private IAccountingRepository _repository;
private ApplicationDbContext _context;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
_repository = new AccountingRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var today = DateTime.Today;
var saved = await _repository.GetAccountingSummaryAsync(today);
Assert.IsNull(saved);
var deptNames = new Dictionary<int, string>();
deptNames.Add(1, "Dept1");
var lineItem = new PayoutLineItem(Product.Mortgage, PayoutProfile.BMMortgage, new Goal(),
100m, new List<Activity>(), today);
lineItem.DepartmentId = 1;
lineItem.PayoutTotal = 1000;
List<PayoutLineItem> allNewPayouts = new List<PayoutLineItem>()
{
lineItem
};
var summary = new AccountingSummary(today);
summary.Apply(allNewPayouts, deptNames);
var newId = await _repository.SaveAccountingSummaryAsync(summary);
await _context.SaveChangesAsync();
saved = await _repository.GetAccountingSummaryAsync(today);
Assert.NotNull(saved);
}
}
}
@@ -0,0 +1,265 @@
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.API.Internal.Operations.IncentiveApiLib;
namespace Application.UnitTests.Repository
{
public class ActivityTransferActionRepositoryTest
{
private ApplicationDbContext _context;
private ActivityTransferActionRepository _repository;
private Mock<IDateTime> _mockDateTime;
[SetUp]
public void Setup()
{
_mockDateTime = new Mock<IDateTime>();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, _mockDateTime.Object);
_repository = new ActivityTransferActionRepository(_context);
}
[Test]
public async Task SaveTransferAsync_Basic()
{
_mockDateTime.SetupGet(mock => mock.Now).Returns(new DateTime(2021, 9, 10, 1, 2, 3, 456));
var activityToTransfer = new Activity()
{
Id = 2,
EmployeeId = "C0000",
DepartmentId = 5,
Product = Product.CheckCard,
SourceId = "2",
State = ActivityState.Accepted,
Detail = new ActivityDetail()
{
MemberName = "Tester 1",
AgreementNumber = "234"
}
};
_context.Add(activityToTransfer);
await _context.SaveChangesAsync();
var activtyTransferAction = new ActivityTransferAction
{
Id = 0,
ActivityStateBeforeTransfer = ActivityState.Accepted,
RequestedActivityId = 2,
State = ActivityTransferState.Requested,
NewActivityDepartmentId = 3,
NewActivityEmployeeId = "C0000"
};
var savedId = await _repository.SaveTransferAsync(activtyTransferAction);
await _context.SaveChangesAsync();
var found = await _context.ActivityTransferActions.FindAsync(savedId);
Assert.NotNull(found);
Assert.AreEqual(ActivityState.Accepted, found.ActivityStateBeforeTransfer);
Assert.AreEqual(2, found.RequestedActivityId);
Assert.AreEqual(ActivityTransferState.Requested, found.State);
Assert.AreEqual(3, found.NewActivityDepartmentId);
Assert.IsNull(found.NewActivityId);
Assert.AreEqual("C0000", found.NewActivityEmployeeId);
Assert.AreEqual(new DateTime(2021, 9, 10, 1, 2, 3, 456), found.Created);
Assert.AreEqual("[email protected]", found.CreatedBy);
Assert.AreEqual(UserType.Associate, found.CreatedByType);
Assert.AreEqual(new DateTime(2021, 9, 10, 1, 2, 3, 456), found.LastUpdated);
Assert.AreEqual("[email protected]", found.LastUpdatedBy);
Assert.AreEqual(UserType.Associate, found.LastUpdatedByType);
}
[Test]
public async Task GetTransferActionById_Basic()
{
var activityToTransfer = new Activity()
{
Id = 2,
EmployeeId = "C0000",
DepartmentId = 5,
Product = Product.CheckCard,
SourceId = "2",
State = ActivityState.Accepted,
Detail = new ActivityDetail()
{
MemberName = "Tester 1",
AgreementNumber = "234"
}
};
_context.Add(activityToTransfer);
await _context.SaveChangesAsync();
var activtyTransferAction1 = new ActivityTransferAction
{
Id = 1,
ActivityStateBeforeTransfer = ActivityState.Accepted,
RequestedActivityId = 2,
State = ActivityTransferState.Accepted,
NewActivityDepartmentId = 3,
NewActivityEmployeeId = "C0001"
};
var activtyTransferAction2 = new ActivityTransferAction
{
Id = 2,
ActivityStateBeforeTransfer = ActivityState.Rejected,
RequestedActivityId = 2,
State = ActivityTransferState.Requested,
NewActivityDepartmentId = 4,
NewActivityEmployeeId = "C0002"
};
_context.Add(activtyTransferAction1);
_context.Add(activtyTransferAction2);
await _context.SaveChangesAsync();
var found = await _repository.GetTransferActionById(2);
Assert.AreEqual(2, found.Id);
Assert.AreEqual(ActivityState.Rejected, found.ActivityStateBeforeTransfer);
Assert.AreEqual(2, found.RequestedActivityId);
Assert.AreEqual(ActivityTransferState.Requested, found.State);
Assert.AreEqual(4, found.NewActivityDepartmentId);
Assert.AreEqual("C0002", found.NewActivityEmployeeId);
}
[Test]
public async Task GetRequestedTransferActionByActivityId_Basic()
{
var activityToTransfer = new Activity()
{
Id = 2,
EmployeeId = "C0000",
DepartmentId = 5,
Product = Product.CheckCard,
SourceId = "2",
State = ActivityState.Accepted,
Detail = new ActivityDetail()
{
MemberName = "Tester 1",
AgreementNumber = "234"
}
};
_context.Add(activityToTransfer);
await _context.SaveChangesAsync();
var activtyTransferAction1 = new ActivityTransferAction
{
Id = 1,
ActivityStateBeforeTransfer = ActivityState.Accepted,
RequestedActivityId = 2,
State = ActivityTransferState.Accepted,
NewActivityDepartmentId = 3,
NewActivityEmployeeId = "C0001"
};
var activtyTransferAction2 = new ActivityTransferAction
{
Id = 2,
ActivityStateBeforeTransfer = ActivityState.Rejected,
RequestedActivityId = 2,
State = ActivityTransferState.Requested,
NewActivityDepartmentId = 4,
NewActivityEmployeeId = "C0002"
};
_context.Add(activtyTransferAction1);
_context.Add(activtyTransferAction2);
await _context.SaveChangesAsync();
var found = await _repository.GetRequestedTransferActionByActivityId(2);
Assert.AreEqual(2, found.Id);
Assert.AreEqual(ActivityState.Rejected, found.ActivityStateBeforeTransfer);
Assert.AreEqual(2, found.RequestedActivityId);
Assert.AreEqual(ActivityTransferState.Requested, found.State);
Assert.AreEqual(4, found.NewActivityDepartmentId);
Assert.AreEqual("C0002", found.NewActivityEmployeeId);
}
[Test]
public async Task GetActiveTransfersByState_Basic()
{
var activityToTransfer = new Activity()
{
Id = 2,
EmployeeId = "C0000",
DepartmentId = 5,
Product = Product.CheckCard,
SourceId = "2",
State = ActivityState.Accepted,
Detail = new ActivityDetail()
{
MemberName = "Tester 1",
AgreementNumber = "234"
}
};
_context.Add(activityToTransfer);
var activityToTransfer2 = new Activity()
{
Id = 3,
EmployeeId = "C0000",
DepartmentId = 5,
Product = Product.CheckCard,
SourceId = "3",
State = ActivityState.PendingReferral,
Detail = new ActivityDetail()
{
MemberName = "Tester 1",
AgreementNumber = "234"
}
};
_context.Add(activityToTransfer);
_context.Add(activityToTransfer2);
await _context.SaveChangesAsync();
var activityTransferAction1 = new ActivityTransferAction
{
Id = 1,
ActivityStateBeforeTransfer = ActivityState.Accepted,
RequestedActivityId = 2,
State = ActivityTransferState.Requested,
NewActivityDepartmentId = 3,
NewActivityEmployeeId = "C0001",
RequestedActivity = activityToTransfer
};
var activityTransferAction2 = new ActivityTransferAction
{
Id = 2,
ActivityStateBeforeTransfer = ActivityState.PendingReferral,
RequestedActivityId = 3,
State = ActivityTransferState.Requested,
NewActivityDepartmentId = 4,
NewActivityEmployeeId = "C0002",
RequestedActivity = activityToTransfer2
};
_context.Add(activityTransferAction1);
_context.Add(activityTransferAction2);
await _context.SaveChangesAsync();
var found = await _repository.GetActiveTransfersForStateAsync(ActivityState.Accepted);
Assert.AreEqual(1, found.Count());
Assert.AreEqual(1, found.First().Id);
Assert.AreEqual(ActivityState.Accepted, found.First().ActivityStateBeforeTransfer);
}
}
}
@@ -0,0 +1,191 @@
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
namespace Application.UnitTests.Repository
{
public class CommissionRepositoryTest
{
private ApplicationDbContext _context;
private CommissionRepository _repository;
private Mock<IDateTime> _mockDateTime;
[SetUp]
public void Setup()
{
_mockDateTime = new Mock<IDateTime>();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, _mockDateTime.Object);
_repository = new CommissionRepository(_context);
}
[Test]
public async Task FindExistingCommission_FoundById()
{
var commission = new Commission
{
Id = 1,
Product = Product.NewChecking,
RatePerProduct = 2,
Role = Role.Teller
};
await _repository.SaveCommission(commission);
await _context.SaveChangesAsync();
var found = await _repository.FindExistingCommission(1);
Assert.NotNull(found);
Assert.AreEqual(1, found.Id);
}
[Test]
public async Task FindExistingCommission_FoundByRole()
{
var commission = new Commission
{
Id = 1,
Product = Product.NewChecking,
RatePerProduct = 2,
Role = Role.Teller
};
await _repository.SaveCommission(commission);
await _context.SaveChangesAsync();
var found = await _repository.FindProductCommissions(Role.Teller);
Assert.NotNull(found);
Assert.IsNotEmpty(found);
Assert.AreEqual(1, found.First().Id);
Assert.AreEqual(Role.Teller, found.First().Role);
}
[Test]
public async Task FindExistingCommission_NotFoundById()
{
var commission = new Commission
{
Id = 1,
Product = Product.NewChecking,
RatePerProduct = 2,
Role = Role.Teller
};
await _repository.SaveCommission(commission);
await _context.SaveChangesAsync();
var found = await _repository.FindExistingCommission(2);
Assert.Null(found);
}
[Test]
public async Task FindExistingCommission_FoundByRoleAndProduct()
{
var commission = new Commission
{
Id = 1,
Product = Product.NewChecking,
RatePerProduct = 2,
Role = Role.Teller
};
await _repository.SaveCommission(commission);
await _context.SaveChangesAsync();
var found = await _repository.FindExistingCommission(Role.Teller, Product.NewChecking);
Assert.NotNull(found);
Assert.AreEqual(Role.Teller, found.Role);
Assert.AreEqual(Product.NewChecking, found.Product);
}
[Test]
public async Task FindExistingCommission_NotFoundByRoleAndProduct()
{
var commission = new Commission
{
Id = 1,
Product = Product.NewChecking,
RatePerProduct = 2,
Role = Role.Teller
};
await _repository.SaveCommission(commission);
await _context.SaveChangesAsync();
var found = await _repository.FindExistingCommission(Role.Admin, Product.NewChecking);
Assert.Null(found);
}
[Test]
public async Task SaveCommission_Basic()
{
_mockDateTime.SetupGet(mock => mock.Now).Returns(new DateTime(2021, 7, 9, 1, 2, 3, 456));
var commission = new Commission
{
Id = 1,
Product = Product.ATMCard,
RatePerProduct = 3,
Role = Role.BM
};
await _repository.SaveCommission(commission);
await _context.SaveChangesAsync();
var found = await _repository.FindExistingCommission(1);
Assert.NotNull(found);
Assert.AreEqual(1, found.Id);
Assert.AreEqual(Product.ATMCard, found.Product);
Assert.AreEqual(3, found.RatePerProduct);
Assert.AreEqual(Role.BM, found.Role);
Assert.AreEqual(new DateTime(2021, 7, 9, 1, 2, 3, 456), found.Created);
Assert.AreEqual("[email protected]", found.CreatedBy);
Assert.AreEqual(UserType.Associate, found.CreatedByType);
Assert.AreEqual(new DateTime(2021, 7, 9, 1, 2, 3, 456), found.LastUpdated);
Assert.AreEqual("[email protected]", found.LastUpdatedBy);
Assert.AreEqual(UserType.Associate, found.LastUpdatedByType);
}
[Test]
public async Task GetCommissionsAsync_Basic()
{
var commission1 = new Commission
{
Id = 1,
Product = Product.NewChecking,
RatePerProduct = 2,
Role = Role.Teller
};
var commission2 = new Commission
{
Id = 2,
Product = Product.ATMCard,
RatePerProduct = 3,
Role = Role.BM
};
await _repository.SaveCommission(commission1);
await _repository.SaveCommission(commission2);
await _context.SaveChangesAsync();
var found = await _repository.GetCommissionsAsync();
Assert.NotNull(found);
Assert.IsNotEmpty(found);
Assert.AreEqual(2, found.Count);
}
}
}
@@ -0,0 +1,714 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.IncentiveApiModels.Common;
namespace Application.UnitTests.Repository
{
public class DeadActivityRepositoryTest
{
private ApplicationDbContext _context;
private DeadActivityRepository _repository;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging()
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
_repository = new DeadActivityRepository(_context);
}
[Test]
public async Task GetActivitiesAsync_Paginated_OK()
{
var activity1 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "1",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(7))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity1);
var activity2 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 56,
EmployeeId = "2",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity2);
var activity3 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "3",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Rejected,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity3);
var activity4 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "4",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Created,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(5))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity4);
await _context.SaveChangesAsync();
var found = await _repository.GetPagedDeadActivities(1, 3);
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(3, found.Items.Count());
Assert.AreEqual(4, found.Total);
Assert.True(found.Items.Any(x => x.EmployeeId == "4"));
Assert.False(found.Items.Any(x => x.EmployeeId == "1"));
Assert.True(found.Items.Any(x => x.EmployeeId == "2"));
Assert.True(found.Items.Any(x => x.EmployeeId == "3"));
found = await _repository.GetPagedDeadActivities(2, 3);
Assert.AreEqual(1, found.Items.Count());
Assert.AreEqual(4, found.Total);
Assert.False(found.Items.Any(x => x.EmployeeId == "4"));
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
found = await _repository.GetPagedDeadActivities(100, 3);
Assert.AreEqual(4, found.Total);
Assert.IsEmpty(found.Items);
}
[Test]
public async Task GetDeadActivitiesByActivityProductAsync_OK()
{
var activity1 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "1",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-3),
State = ActivityState.Accepted,
LastUpdated = new DateTime(2021, 1, 4)
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity1);
var activity2 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 56,
EmployeeId = "2",
Type = ActivityType.Sale,
Product = Product.NewChecking,
Accepted = DateTime.Today.AddMinutes(-2),
State = ActivityState.Accepted,
LastUpdated = new DateTime(2021, 1, 3)
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity2);
var activity3 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "3",
Type = ActivityType.Sale,
Product = Product.NewChecking,
Accepted = DateTime.Today.AddMinutes(-1),
State = ActivityState.Rejected,
LastUpdated = new DateTime(2021, 1, 2)
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity3);
var activity4 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "4",
Type = ActivityType.Sale,
Product = Product.NewChecking,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
LastUpdated = new DateTime(2021, 1, 1)
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity4);
await _context.SaveChangesAsync();
var filter = new DeadActivityFilter
{
Page = 1,
Limit = 2,
Product = new List<Product> { Product.CheckCard }
};
var found = await _repository.GetFilteredDeadActivities(filter);
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(1, found.Items.Count());
Assert.AreEqual(1, found.Total);
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
}
[Test]
public async Task GetDeadActivitiesByActivityTypeAsync_OK()
{
var activity1 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "1",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-3),
State = ActivityState.Accepted,
LastUpdated = new DateTime(2021, 1, 4)
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity1);
var activity2 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 56,
EmployeeId = "2",
Type = ActivityType.Referral,
Product = Product.NewChecking,
Accepted = DateTime.Today.AddMinutes(-2),
State = ActivityState.Accepted,
LastUpdated = new DateTime(2021, 1, 3)
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity2);
var activity3 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "3",
Type = ActivityType.Referral,
Product = Product.NewChecking,
Accepted = DateTime.Today.AddMinutes(-1),
State = ActivityState.Rejected,
LastUpdated = new DateTime(2021, 1, 2)
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity3);
var activity4 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "4",
Type = ActivityType.Referral,
Product = Product.NewChecking,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
LastUpdated = new DateTime(2021, 1, 1)
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity4);
await _context.SaveChangesAsync();
var filter = new DeadActivityFilter
{
Page = 1,
Limit = 2,
Type = new List<ActivityType> { ActivityType.Sale }
};
var found = await _repository.GetFilteredDeadActivities(filter);
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(1, found.Items.Count());
Assert.AreEqual(1, found.Total);
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
}
[Test]
public async Task GetFilteredDeadActivities_OK()
{
// You can't set last updated. So you'll get these back in reverse order you saved them.
var activity1 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "1",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-5),
State = ActivityState.Accepted,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(7))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity1);
var activity2 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 56,
EmployeeId = "2",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-4),
State = ActivityState.Rejected,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity2);
var activity3 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "3",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-3),
State = ActivityState.Accepted,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity3);
var activity4 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "4",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-2),
State = ActivityState.Created,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(5))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity4);
//null state
var activity5 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 55,
EmployeeId = "5",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-1),
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity5);
var activity6 = new DeadActivity(new Activity
{
Detail = new ActivityDetail(),
DepartmentId = 56,
EmployeeId = "6",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
}, DeadActivityReason.MissingRequiredField, "Test");
await _repository.SaveDeadActivity(activity6);
await _context.SaveChangesAsync();
var filter = new DeadActivityFilter
{
Page = 1,
Limit = 2,
State = new List<ActivityState> { ActivityState.Accepted }
};
var found = await _repository.GetFilteredDeadActivities(filter);
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(2, found.Items.Count());
Assert.AreEqual(3, found.Total);
Assert.True(found.Items.Any(x => x.EmployeeId == "3"));
Assert.False(found.Items.Any(x => x.EmployeeId == "4")); // not accepted
Assert.False(found.Items.Any(x => x.EmployeeId == "1")); // not on this page
Assert.False(found.Items.Any(x => x.EmployeeId == "5")); // not accepted
Assert.True(found.Items.Any(x => x.EmployeeId == "6"));
Assert.False(found.Items.Any(x => x.EmployeeId == "2")); // not accepted
filter.Page = 2;
found = await _repository.GetFilteredDeadActivities(filter);
Assert.AreEqual(1, found.Items.Count());
Assert.AreEqual(3, found.Total);
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
Assert.False(found.Items.Any(x => x.EmployeeId == "4"));
var filter2 = new DeadActivityFilter
{
Page = 1,
Limit = 100,
State = new List<ActivityState> { ActivityState.ManualReview }
};
found = await _repository.GetFilteredDeadActivities(filter2);
Assert.AreEqual(0, found.Total);
Assert.IsEmpty(found.Items);
filter2.Page = 20;
found = await _repository.GetFilteredDeadActivities(filter2);
Assert.AreEqual(0, found.Total);
Assert.IsEmpty(found.Items);
}
[Test]
public async Task GetFilteredDeadActivities_More()
{
// You can't set last updated. So you'll get these back in reverse order you saved them.
var activity1 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "1",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-4),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
MemberName = "John Doe"
}
}, DeadActivityReason.Other, "Test1");
await _repository.SaveDeadActivity(activity1);
var activity2 = new DeadActivity(new Activity
{
DepartmentId = 56,
EmployeeId = "2",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-3),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
SubjectPersonNbr = "1Jane3Doe"
}
}, DeadActivityReason.Other, "Test2");
await _repository.SaveDeadActivity(activity2);
var activity3 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "3",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-2),
State = ActivityState.Rejected,
Detail = new ActivityDetail
{
AccountNumber = "1234"
}
}, DeadActivityReason.Other, "Test3");
await _repository.SaveDeadActivity(activity3);
var activity4 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "4",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-1),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
AccountNumber = "12DOE35"
}
}, DeadActivityReason.Other, "Test4");
await _repository.SaveDeadActivity(activity4);
//Everything in Query is null. should not match, should not error
var activity5 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "4",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
Detail = new ActivityDetail()
}, DeadActivityReason.Other, "Test4");
await _repository.SaveDeadActivity(activity5);
await _context.SaveChangesAsync();
var filter = new DeadActivityFilter
{
Page = 1,
Limit = 2,
Query = "DoE"
};
var found = await _repository.GetFilteredDeadActivities(filter);
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(2, found.Items.Count());
Assert.AreEqual(3, found.Total);
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
Assert.True(found.Items.Any(x => x.EmployeeId == "4"));
Assert.False(found.Items.Any(x => x.EmployeeId == "1")); // not on this page
Assert.True(found.Items.Any(x => x.EmployeeId == "2"));
filter.Page = 2;
found = await _repository.GetFilteredDeadActivities(filter);
Assert.AreEqual(1, found.Items.Count());
Assert.AreEqual(3, found.Total);
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
Assert.False(found.Items.Any(x => x.EmployeeId == "4"));
}
[Test]
public async Task GetActivitiesByFilter_Employee_Department()
{
var activity1 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "1",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-4),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
MemberName = "John Doe"
}
}, DeadActivityReason.Other, "Test1");
await _repository.SaveDeadActivity(activity1);
var activity2 = new DeadActivity(new Activity
{
DepartmentId = 56,
EmployeeId = "2",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-3),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
SubjectPersonNbr = "1Jane3Doe"
}
}, DeadActivityReason.Other, "Test2");
await _repository.SaveDeadActivity(activity2);
var activity3 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "3",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-2),
State = ActivityState.Rejected,
Detail = new ActivityDetail
{
AccountNumber = "1234"
}
}, DeadActivityReason.Other, "Test3");
await _repository.SaveDeadActivity(activity3);
var activity4 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "4",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-1),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
AccountNumber = "12DOE35"
}
}, DeadActivityReason.Other, "Test4");
await _repository.SaveDeadActivity(activity4);
//Everything in Query is null. should not match, should not error
var activity5 = new DeadActivity(new Activity
{
EmployeeId = "4",
DepartmentId = -1,
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
Detail = new ActivityDetail()
}, DeadActivityReason.Other, "Test5");
await _repository.SaveDeadActivity(activity5);
await _context.SaveChangesAsync();
var filter = new DeadActivityFilter
{
Page = 1,
Limit = 2,
DepartmentId = 55
};
var found = await _repository.GetFilteredDeadActivities(filter);
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(2, found.Items.Count());
Assert.AreEqual(3, found.Total);
Assert.True(found.Items.Any(x => x.EmployeeId == "3"));
Assert.True(found.Items.Any(x => x.EmployeeId == "4"));
Assert.False(found.Items.Any(x => x.EmployeeId == "1")); // not on this page
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
filter.EmployeeId = "4";
found = await _repository.GetFilteredDeadActivities(filter);
Assert.AreEqual(1, found.Items.Count());
Assert.AreEqual(1, found.Total);
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
Assert.False(found.Items.Any(x => x.EmployeeId == "1"));
Assert.True(found.Items.Any(x => x.EmployeeId == "4"));
filter.DepartmentId = 99;
found = await _repository.GetFilteredDeadActivities(filter);
Assert.AreEqual(0, found.Items.Count());
Assert.AreEqual(0, found.Total);
}
[Test]
public async Task GetActivitiesByFilter_Sort()
{
var activity1 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "1",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-4),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
MemberName = "John Doe"
}
}, DeadActivityReason.Other, "Test1");
await _repository.SaveDeadActivity(activity1);
var activity2 = new DeadActivity(new Activity
{
DepartmentId = 56,
EmployeeId = "2",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-3),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
SubjectPersonNbr = "1Jane3Doe"
}
}, DeadActivityReason.Other, "Test2");
await _repository.SaveDeadActivity(activity2);
var activity3 = new DeadActivity(new Activity
{
DepartmentId = 55,
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-2),
State = ActivityState.Rejected,
Detail = new ActivityDetail
{
AccountNumber = "1234"
}
}, DeadActivityReason.Other, "Test3");
await _repository.SaveDeadActivity(activity3);
var activity4 = new DeadActivity(new Activity
{
DepartmentId = 55,
EmployeeId = "4",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today.AddMinutes(-1),
State = ActivityState.Accepted,
Detail = new ActivityDetail
{
AccountNumber = "12DOE35"
}
}, DeadActivityReason.Other, "Test4");
await _repository.SaveDeadActivity(activity4);
//Everything in Query is null. should not match, should not error
var activity5 = new DeadActivity(new Activity
{
DepartmentId = -1,
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
Detail = new ActivityDetail()
}, DeadActivityReason.Other, "Test5");
await _repository.SaveDeadActivity(activity5);
await _context.SaveChangesAsync();
//Everything in Query is null. should not match, should not error
var activity6 = new DeadActivity(new Activity
{
DepartmentId = -1,
EmployeeId = "6",
Type = ActivityType.Sale,
Product = Product.CheckCard,
Accepted = DateTime.Today,
State = ActivityState.Accepted,
Detail = new ActivityDetail()
}, DeadActivityReason.Other, "Test6");
await _repository.SaveDeadActivity(activity6);
var filter = new DeadActivityFilter
{
Page = 1,
Limit = 99,
DepartmentId = 55,
SortBy = "EmployeeId"
};
//NOTE: Null EmployeeId first
var found = await _repository.GetFilteredDeadActivities(filter);
var expected = new[] { "Test3", "Test1", "Test4" };
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(3, found.Items.Count());
Assert.AreEqual(3, found.Total);
var ordered = found.Items.Select(x => x.ReasonNote).ToArray();
Assert.AreEqual(expected, ordered);
//NOTE: Null EmployeeId Last
filter.SortDescending = true;
found = await _repository.GetFilteredDeadActivities(filter);
expected = new[] { "Test4", "Test1", "Test3" };
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(3, found.Items.Count());
Assert.AreEqual(3, found.Total);
ordered = found.Items.Select(x => x.ReasonNote).ToArray();
Assert.AreEqual(expected, ordered);
filter.SortDescending = false;
filter.SortBy = null;
found = await _repository.GetFilteredDeadActivities(filter);
expected = new[] { "Test4", "Test3", "Test1" };
Assert.NotNull(found);
Assert.IsNotEmpty(found.Items);
Assert.AreEqual(3, found.Items.Count());
Assert.AreEqual(3, found.Total);
ordered = found.Items.Select(x => x.ReasonNote).ToArray();
Assert.AreEqual(expected, ordered);
}
}
}
@@ -0,0 +1,55 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
namespace Application.UnitTests.Repository
{
public class GoalChangeRepositoryTest
{
private ApplicationDbContext _context;
private GoalChangeRepository _repository;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
_repository = new GoalChangeRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var saved = await _repository.GetGoalChangesAsync();
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var newId = await _repository.SaveGoalChangeAsync(new GoalChange());
await _context.SaveChangesAsync();
saved = await _repository.GetGoalChangesAsync();
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
var first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
}
}
}
@@ -0,0 +1,762 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.API.Internal.Operations.IncentiveApi.Extensions;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using LCU.Library.Internal.IncentiveApiModels.Requests;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.IncentiveApiModels.Common;
namespace Application.UnitTests.Repository
{
public class GoalRepositoryTest
{
private ApplicationDbContext _context;
private GoalRepository _repository;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
_repository = new GoalRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var newId = await _repository.SaveGoalAsync(new Goal()
{
DepartmentId = 6,
StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1),
EndDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).Subtract(TimeSpan.FromDays(1)),
EmployeeId = null
});
await _context.SaveChangesAsync();
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
{
IncludePersonnel = false
}
);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
var first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
}
[Test]
public async Task Basic_Search_Test()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var startDate = new DateTime(2021, 3, 1);
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
var goalPersonnel = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate
};
var goal2 = new Goal()
{
Product = Product.NewChecking,
Value = 8,
DepartmentId = 2,
StartDate = startDate,
EndDate = endDate
};
var goal3 = new Goal()
{
Product = Product.NewChecking,
Value = 11,
DepartmentId = 1,
StartDate = new DateTime(2021, 4, 1),
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth()
};
await _repository.SaveGoalAsync(goalPersonnel);
await _repository.SaveGoalAsync(goal);
await _repository.SaveGoalAsync(goal2);
await _repository.SaveGoalAsync(goal3);
await _context.SaveChangesAsync();
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
{
IncludePersonnel = false
}
);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
Assert.AreEqual(3, saved.Count);
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
{
IncludePersonnel = true
}
);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
Assert.AreEqual(1, saved.Count);
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
{
IncludePersonnel = false,
departmentId = 1
}
);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
Assert.AreEqual(2, saved.Count);
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
{
IncludePersonnel = true,
departmentId = 1
}
);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
Assert.AreEqual(1, saved.Count);
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
{
IncludePersonnel = false,
DateRange = new MonthRange(2021,3)
}
);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
Assert.AreEqual(2, saved.Count);
}
[Test]
public async Task Multi_Year_Search_Test()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var startDate = new DateTime(2021, 6, 1);
var endDate = (new DateTime(2021, 6, 1)).EndOfMonth();
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate
};
var goal2 = new Goal()
{
Product = Product.NewChecking,
Value = 11,
DepartmentId = 1,
StartDate = new DateTime(2022, 4, 1),
EndDate = (new DateTime(2022, 4, 1)).EndOfMonth()
};
await _repository.SaveGoalAsync(goal);
await _repository.SaveGoalAsync(goal2);
await _context.SaveChangesAsync();
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
{
DateRange = new MonthRange(2021,6, 2022,6),
IncludePersonnel = false
}
);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
Assert.AreEqual(2, saved.Count);
}
[Test]
public async Task Find_Goal_Basic()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var goalChange = new GoalChange()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = new DateTime(2021, 3, 1),
EndDate = (new DateTime(2021, 3, 1)).EndOfMonth(),
PersonId = "[email protected]"
};
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = new DateTime(2021, 3, 1),
EndDate = (new DateTime(2021, 3, 1)).EndOfMonth(),
EmployeeId = "[email protected]"
};
var newId = await _repository.SaveGoalAsync(goal);
await _context.SaveChangesAsync();
var foundGoal = await _repository.FindExistingGoal(goalChange);
Assert.NotNull(foundGoal);
// Make sure our Auditable is working.
Assert.NotNull(foundGoal.CreatedBy);
Assert.NotNull(foundGoal.Created);
}
[Test]
public async Task Find_Goal_UsesDate()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var goalChange = new GoalChange()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = new DateTime(2021, 3, 1),
EndDate = (new DateTime(2021, 3, 1)).EndOfMonth(),
PersonId = "[email protected]"
};
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = new DateTime(2021, 3, 1),
EndDate = (new DateTime(2021, 3, 1)).AddMonths(1).AddMilliseconds(-1),
EmployeeId = "[email protected]"
};
var newId = await _repository.SaveGoalAsync(goal);
await _context.SaveChangesAsync();
var foundGoal = await _repository.FindExistingGoal(goalChange);
Assert.NotNull(foundGoal);
// Make sure our Auditable is working.
Assert.NotNull(foundGoal.CreatedBy);
Assert.NotNull(foundGoal.Created);
}
[Test]
public async Task Find_Goal_Department_Basic()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var startDate = new DateTime(2021, 3, 1);
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
// This personnel goal shouldn't be returned.
var goalPersonnel = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate
};
var goal2 = new Goal()
{
Product = Product.NewChecking,
Value = 8,
DepartmentId = 2,
StartDate = startDate,
EndDate = endDate
};
var goal3 = new Goal()
{
Product = Product.NewChecking,
Value = 11,
DepartmentId = 1,
StartDate = new DateTime(2021, 4, 1),
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth()
};
await _repository.SaveGoalAsync(goalPersonnel);
await _repository.SaveGoalAsync(goal);
await _repository.SaveGoalAsync(goal2);
await _repository.SaveGoalAsync(goal3);
await _context.SaveChangesAsync();
var foundGoals = await _repository.FindDepartmentGoals(1, startDate, endDate);
Assert.NotNull(foundGoals);
Assert.IsNotEmpty(foundGoals);
Assert.AreEqual(1, foundGoals.Count);
Assert.AreEqual(10, foundGoals.First().Value);
}
[Test]
public async Task Find_Goal_Department_Annual()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var startDate = new DateTime(2021, 3, 1);
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
// This personnel goal shouldn't be returned.
var goalPersonnel = new Goal()
{
Product = Product.NewChecking,
Value = 7,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate
};
var goal2 = new Goal()
{
Product = Product.NewChecking,
Value = 8,
DepartmentId = 2,
StartDate = startDate,
EndDate = endDate
};
var goal3 = new Goal()
{
Product = Product.NewChecking,
Value = 11,
DepartmentId = 1,
StartDate = new DateTime(2021, 4, 1),
EndDate = (new DateTime(2021, 3, 1)).EndOfMonth()
};
await _repository.SaveGoalAsync(goalPersonnel);
await _repository.SaveGoalAsync(goal);
await _repository.SaveGoalAsync(goal2);
await _repository.SaveGoalAsync(goal3);
await _context.SaveChangesAsync();
var foundGoals = await _repository.FindAnnualDepartmentGoals(1, startDate.Year);
Assert.NotNull(foundGoals);
Assert.IsNotEmpty(foundGoals);
Assert.AreEqual(2, foundGoals.Count);
Assert.AreEqual(10, foundGoals.First().Value);
Assert.AreEqual(11, foundGoals.ElementAt(1).Value);
}
[Test]
public async Task Find_Goal_Personnel_Basic()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var startDate = new DateTime(2021, 3, 1);
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
// This department goal shouldn't be returned
var departmentGoal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate
};
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
var goalx = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
var goal2 = new Goal()
{
Product = Product.NewChecking,
Value = 8,
DepartmentId = 2,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
var goal3 = new Goal()
{
Product = Product.NewChecking,
Value = 11,
DepartmentId = 1,
StartDate = new DateTime(2021, 4, 1),
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth(),
EmployeeId = "[email protected]"
};
await _repository.SaveGoalAsync(departmentGoal);
await _repository.SaveGoalAsync(goal);
await _repository.SaveGoalAsync(goalx);
await _repository.SaveGoalAsync(goal2);
await _repository.SaveGoalAsync(goal3);
await _context.SaveChangesAsync();
var users = new List<AppUser>()
{
new AppUser()
{
AdEmail = "[email protected]",
EmployeeId = "[email protected]",
FullName = "John McTester",
HomeDepartment = "QA",
BaseRole = "Tester",
Role = Role.Developer,
}
};
var foundGoals = await _repository.FindPersonnelGoals(1, users, startDate, endDate);
Assert.NotNull(foundGoals);
Assert.IsNotEmpty(foundGoals);
Assert.AreEqual(1, foundGoals.Count);
Assert.AreEqual(10, foundGoals.First().Value);
}
[Test]
public async Task Find_Goal_Personnel_Monthly()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var startDate = new DateTime(2021, 3, 1);
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
// This department goal shouldn't be returned
var departmentGoal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate
};
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
// Not the same person.
var goalx = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
// Not the same department
var goal2 = new Goal()
{
Product = Product.NewChecking,
Value = 8,
DepartmentId = 2,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
// not the same month
var goal3 = new Goal()
{
Product = Product.NewChecking,
Value = 11,
DepartmentId = 1,
StartDate = new DateTime(2021, 4, 1),
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth(),
EmployeeId = "[email protected]"
};
await _repository.SaveGoalAsync(departmentGoal);
await _repository.SaveGoalAsync(goal);
await _repository.SaveGoalAsync(goalx);
await _repository.SaveGoalAsync(goal2);
await _repository.SaveGoalAsync(goal3);
await _context.SaveChangesAsync();
var users = new List<AppUser>()
{
new AppUser()
{
AdEmail = "[email protected]",
EmployeeId = "[email protected]",
FullName = "John McTester",
HomeDepartment = "QA",
BaseRole = "Tester",
Role = Role.Developer,
}
};
var foundGoals = await _repository.FindMonthlyPersonnelGoals(1, users, startDate.Year, startDate.Month);
Assert.NotNull(foundGoals);
Assert.IsNotEmpty(foundGoals);
Assert.AreEqual(1, foundGoals.Count);
Assert.AreEqual(10, foundGoals.First().Value);
}
[Test]
public async Task Find_Goal_Personnel_Month_Range()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var startDate = new DateTime(2021, 3, 1);
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
// This department goal shouldn't be returned
var departmentGoal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate
};
var goal = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
// Not the same person.
var goalx = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
// Not the same department
var goal2 = new Goal()
{
Product = Product.NewChecking,
Value = 8,
DepartmentId = 2,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "[email protected]"
};
// not the same month
var goal3 = new Goal()
{
Product = Product.NewChecking,
Value = 11,
DepartmentId = 1,
StartDate = new DateTime(2021, 4, 1),
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth(),
EmployeeId = "[email protected]"
};
// not in month range
var goal4 = new Goal()
{
Product = Product.NewChecking,
Value = 12,
DepartmentId = 1,
StartDate = new DateTime(2021, 5, 1),
EndDate = (new DateTime(2021, 5, 1)).EndOfMonth(),
EmployeeId = "[email protected]"
};
await _repository.SaveGoalAsync(departmentGoal);
await _repository.SaveGoalAsync(goal);
await _repository.SaveGoalAsync(goalx);
await _repository.SaveGoalAsync(goal2);
await _repository.SaveGoalAsync(goal3);
await _repository.SaveGoalAsync(goal4);
await _context.SaveChangesAsync();
var users = new List<AppUser>()
{
new AppUser()
{
AdEmail = "[email protected]",
EmployeeId = "[email protected]",
FullName = "John McTester",
HomeDepartment = "QA",
BaseRole = "Tester",
Role = Role.Developer,
}
};
var range = new MonthRange
(
startDate.Year,
startDate.Month,
endDate.Year,
endDate.Month + 1
);
var foundGoals = await _repository.FindPersonnelGoalsByMonthRange(1, users, range);
Assert.NotNull(foundGoals);
Assert.IsNotEmpty(foundGoals);
Assert.AreEqual(2, foundGoals.Count);
Assert.AreEqual(10, foundGoals.First().Value);
Assert.AreEqual(11, foundGoals.ElementAt(1).Value);
}
[Test]
public async Task FindDepartmentGoalsByMonthRange()
{
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var startDate = new DateTime(2021, 3, 1);
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
var goalInRange = new Goal()
{
Product = Product.NewChecking,
Value = 10,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate
};
var goalNotInRange = new Goal()
{
Product = Product.ATMCard,
Value = 2,
DepartmentId = 1,
StartDate = startDate.AddMonths(-2),
EndDate = endDate.AddMonths(-2)
};
var goalWithPersonId = new Goal()
{
Product = Product.CheckCard,
Value = 2,
DepartmentId = 1,
StartDate = startDate,
EndDate = endDate,
EmployeeId = "E1"
};
var goalForOtherDepartment = new Goal()
{
Product = Product.CreditCard,
Value = 2,
DepartmentId = 2,
StartDate = startDate,
EndDate = endDate
};
var range = new MonthRange(2021, 3, 2021, 4);
await _repository.SaveGoalAsync(goalInRange);
await _repository.SaveGoalAsync(goalNotInRange);
await _repository.SaveGoalAsync(goalWithPersonId);
await _repository.SaveGoalAsync(goalForOtherDepartment);
await _context.SaveChangesAsync();
var found = await _repository.FindDepartmentGoalsByMonthRange(1, range);
Assert.NotNull(found);
Assert.IsNotEmpty(found);
Assert.AreEqual(1, found.Count);
Assert.AreEqual(10, found.First().Value);
}
}
}
@@ -0,0 +1,233 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
namespace Application.UnitTests.Repository
{
public class PayoutRepositoryTest
{
private ApplicationDbContext _context;
private PayoutRepository _repository;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
_repository = new PayoutRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var saved = await _repository.GetPayoutLineItemsForPeriodAsync(period);
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var newId = await _repository.SavePayoutLineItemAsync(new PayoutLineItem()
{
Product = Product.CheckCard,
Role = Role.Teller,
EmployeeId = "11771",
DepartmentId = 999,
ActivityTotal = 1,
PayoutTotal = 10,
CommissionId = 99,
CommissionValue = 10,
ActivityPeriod = period
});
await _context.SaveChangesAsync();
saved = await _repository.GetPayoutLineItemsForPeriodAsync(period);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
var first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
var savedPayout = await _repository.GetPayoutLineItemById(saved.First().Id);
Assert.AreSame(saved.First(), savedPayout);
}
[Test]
public async Task Basic_RangeFlow_Test()
{
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var saved = await _repository.GetPayoutLineItemsForPeriodAsync(period);
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var lineItems = new List<PayoutLineItem>()
{
new PayoutLineItem()
{
Product = Product.CheckCard,
Role = Role.Teller,
EmployeeId = "11771",
DepartmentId = 999,
ActivityTotal = 1,
PayoutTotal = 10,
CommissionId = 99,
CommissionValue = 10,
ActivityPeriod = period
},
new PayoutLineItem()
{
Product = Product.CheckCard,
Role = Role.Teller,
EmployeeId = "11772",
DepartmentId = 999,
ActivityTotal = 1,
PayoutTotal = 10,
CommissionId = 99,
CommissionValue = 10,
ActivityPeriod = period
}
};
await _repository.SavePayoutLineItemRangeAsync(lineItems);
await _context.SaveChangesAsync();
saved = await _repository.GetPayoutLineItemsForPeriodAsync(period);
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
Assert.AreEqual(2, saved.Count());
var first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
var savedPayout = await _repository.GetPayoutLineItemById(saved.First().Id);
Assert.AreSame(saved.First(), savedPayout);
}
[Test]
public async Task GetEmployeePayoutsForPeriod_None()
{
var user = new AppUser()
{
Role = Role.Admin,
AdEmail = "[email protected]",
BaseRole = "Tester",
EmployeeId = "11771",
FullName = "Test McTester",
HomeDepartment = "HOME",
PersonId = 565
};
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var found = await _repository.GetEmployeePayoutsForPeriod(user, period);
Assert.NotNull(found);
Assert.IsEmpty(found);
}
[Test]
public async Task GetEmployeePayoutsForPeriod_Basic()
{
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var period2 = new DateTime(DateTime.Today.Year + 1, DateTime.Today.Month, 1);
var payout1 = new PayoutLineItem()
{
Product = Product.CheckCard,
Role = Role.Teller,
EmployeeId = "11771",
DepartmentId = 999,
ActivityTotal = 1,
PayoutTotal = 10,
CommissionId = 99,
CommissionValue = 10,
ActivityPeriod = period
};
await _repository.SavePayoutLineItemAsync(payout1);
var payout2 = new PayoutLineItem()
{
Product = Product.CheckCard,
Role = Role.Teller,
EmployeeId = "11772",
DepartmentId = 999,
ActivityTotal = 1,
PayoutTotal = 10,
CommissionId = 99,
CommissionValue = 10,
ActivityPeriod = period
};
await _repository.SavePayoutLineItemAsync(payout2);
var payout3 = new PayoutLineItem()
{
Product = Product.CheckCard,
Role = Role.Teller,
EmployeeId = "11771",
DepartmentId = 999,
ActivityTotal = 1,
PayoutTotal = 10,
CommissionId = 99,
CommissionValue = 10,
ActivityPeriod = period
};
await _repository.SavePayoutLineItemAsync(payout3);
var payout4 = new PayoutLineItem()
{
Product = Product.CheckCard,
Role = Role.Teller,
EmployeeId = "11771",
DepartmentId = 999,
ActivityTotal = 1,
PayoutTotal = 10,
CommissionId = 99,
CommissionValue = 10,
ActivityPeriod = period2
};
await _repository.SavePayoutLineItemAsync(payout4);
await _context.SaveChangesAsync();
var user = new AppUser()
{
Role = Role.Admin,
AdEmail = "[email protected]",
BaseRole = "Tester",
EmployeeId = "11771",
FullName = "Test McTester",
HomeDepartment = "HOME",
PersonId = 11771,
Departments = new List<UserDepartment>()
{
new UserDepartment()
{
DepartmentId = 55,
Department = new Department()
{
Id = 55,
State = DepartmentState.Active,
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code
}
}
}
};
var found = await _repository.GetEmployeePayoutsForPeriod(user, period);
Assert.NotNull(found);
Assert.IsNotEmpty(found);
Assert.AreEqual(2, found.Count);
}
}
}
@@ -0,0 +1,91 @@
using System;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.IncentiveApiModels.Enums;
namespace Application.UnitTests.Repository
{
public class ProcessorHistoryRepositoryTest
{
private ApplicationDbContext _context;
private ProcessorHistoryRepository _repository;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
_repository = new ProcessorHistoryRepository(_context);
}
[Test]
public async Task Basic_Flow_test()
{
var res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
{
Process = Process.ImportCheckingAccountSalesFromDna,
LastSuccessfulRunTime = DateTime.Now,
LastProcessedRecordId = 5,
LastProcessedRecordTimestamp = DateTime.Now,
});
await _context.SaveChangesAsync();
Assert.NotNull(res);
Assert.AreEqual(res, Process.ImportCheckingAccountSalesFromDna);
res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
{
Process = Process.ImportGapMbpFromAlliedFile,
LastSuccessfulRunTime = DateTime.Parse("2021-04-05"),
LastProcessedRecordId = 3,
LastProcessedRecordTimestamp = DateTime.Parse("2021-04-05")
});
await _context.SaveChangesAsync();
Assert.NotNull(res);
Assert.AreEqual(Process.ImportGapMbpFromAlliedFile, res);
var list = await _repository.GetAllProcessorRunHistory();
Assert.NotNull(list);
Assert.AreEqual(2, list.Count);
//Saving existing Process causes update
res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
{
Process = Process.ImportGapMbpFromAlliedFile,
LastSuccessfulRunTime = DateTime.Parse("2021-05-08"),
LastProcessedRecordId = 200,
LastProcessedRecordTimestamp = DateTime.Parse("2021-05-07"),
});
await _context.SaveChangesAsync();
list = await _repository.GetAllProcessorRunHistory();
Assert.NotNull(list);
Assert.AreEqual(2, list.Count);
var updatedHistoryRecord = list.Find(x => x.Process == Process.ImportGapMbpFromAlliedFile);
Assert.AreEqual(200, updatedHistoryRecord.LastProcessedRecordId);
Assert.AreEqual(DateTime.Parse("2021-05-08"), updatedHistoryRecord.LastSuccessfulRunTime);
Assert.AreEqual(DateTime.Parse("2021-05-07"), updatedHistoryRecord.LastProcessedRecordTimestamp);
updatedHistoryRecord = await _repository.GetProcessorRunHistory(Process.ImportGapMbpFromAlliedFile);
Assert.AreEqual(200, updatedHistoryRecord.LastProcessedRecordId);
Assert.AreEqual(DateTime.Parse("2021-05-08"), updatedHistoryRecord.LastSuccessfulRunTime);
Assert.AreEqual(DateTime.Parse("2021-05-07"), updatedHistoryRecord.LastProcessedRecordTimestamp);
}
}
}
@@ -0,0 +1,115 @@
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
namespace Application.UnitTests.Repository
{
public class UserAssignmentRepositoryTest
{
private ApplicationDbContext _context;
private UserAssignmentRepository _repository;
private Mock<IDateTime> _mockDateTime;
[SetUp]
public void Setup()
{
_mockDateTime = new Mock<IDateTime>();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, _mockDateTime.Object);
_repository = new UserAssignmentRepository(_context);
}
[Test]
public async Task Basic_Flow_test()
{
var mockDate = new DateTime(2021, 8, 17, 1, 2, 3, 456);
_mockDateTime.SetupGet(mock => mock.Now).Returns(mockDate);
var saved = await _repository.GetAllUserAssignmentsAsync();
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var newAssignment = new UserAssignment
{
Id = 1,
Key = "key",
Type = AssignmentType.RegionalManager,
AppUser = new AppUser {
BaseRole = "Role",
FullName = "Test",
HomeDepartment = "Test",
Role = Role.Admin,
EmployeeId = "123",
AdEmail = "[email protected]",
PersonId = 456
}
};
var newId = await _context.AddAsync(newAssignment);
await _context.SaveChangesAsync();
saved = await _repository.GetAllUserAssignmentsAsync();
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
var first = saved.First();
}
[Test]
public async Task FindExistingAssignment_Match()
{
var mockDate = new DateTime(2021, 8, 17, 1, 2, 3, 456);
_mockDateTime.SetupGet(mock => mock.Now).Returns(mockDate);
var saved = await _repository.GetAllUserAssignmentsAsync();
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var newAssignment = new UserAssignment
{
Id = 1,
Key = "NORTH",
Type = AssignmentType.RegionalManager,
AppUser = new AppUser
{
BaseRole = "Role",
FullName = "Test",
HomeDepartment = "Test",
Role = Role.Admin,
EmployeeId = "123",
AdEmail = "[email protected]",
PersonId = 456
}
};
var newId = await _context.AddAsync(newAssignment);
await _context.SaveChangesAsync();
var notFound = await _repository.FindExistingAssignmentAsync(AssignmentType.RegionalManager, "CENTRAL");
Assert.Null(notFound);
var found = await _repository.FindExistingAssignmentAsync(AssignmentType.RegionalManager, "NORTH");
Assert.NotNull(found);
Assert.AreEqual(1, found.Id);
Assert.AreEqual("NORTH", found.Key);
Assert.AreEqual(AssignmentType.RegionalManager, found.Type);
Assert.AreEqual("123", found.AppUser.EmployeeId);
Assert.AreEqual("[email protected]", found.AppUser.AdEmail);
Assert.AreEqual(456, found.AppUser.PersonId);
}
}
}