Files
2026-03-17 09:53:09 -05:00

1034 lines
43 KiB
C#

using System;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
using System.Collections.Generic;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using LCU.API.Internal.Operations.IncentiveApiLib;
using LCU.Library.Internal.IncentiveApiModels.Requests;
using LCU.Library.Internal.IncentiveApiModels.Common;
namespace Application.UnitTests.Repository
{
public class UserRepositoryTest
{
private ApplicationDbContext _context;
private UserRepository _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 UserRepository(_context);
}
[Test]
public async Task Save_Load_Test()
{
var userA = await _repository.SaveUserAsync(new AppUser()
{
AdEmail = "[email protected]",
PersonId = 321,
EmployeeId = "ABC",
BaseRole = "Developer",
Role = Role.Admin,
HomeDepartment = "Branch-44",
FullName = "Tester, Jane",
Departments = new List<UserDepartment>()
});
userA.Departments.Add(new UserDepartment()
{
IsHome = true,
StartDate = DateTime.Today,
Note = "Auto Generated",
Employee = userA,
Role = Role.BusinessLineManager,
Department = new Department()
{
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
DnaOrgNbr = "1",
BusinessLineCode = BusinessLine.Operations.Code,
State = DepartmentState.Active
}
}
);
userA.Assignments.Add(new UserAssignment
{
Id = 0,
Key = "ABC",
Type = AssignmentType.RegionalManager
});
await _context.SaveChangesAsync();
Assert.NotNull(userA);
var allUsers = await _repository.GetAllUsersAsync();
Assert.AreEqual(1, allUsers.Count);
var user = await _repository.FindUserAsync("ABC", "[email protected]");
Assert.NotNull(user);
Assert.AreEqual(user.AdEmail, "[email protected]");
Assert.NotNull(user.Departments);
Assert.IsNotEmpty(user.Departments);
Assert.NotNull(user.Assignments);
Assert.IsNotEmpty(user.Assignments);
Assert.NotNull(user.Created);
Assert.NotNull(user.CreatedBy);
Assert.AreEqual(1, user.Assignments.Count);
}
[Test]
public async Task Basic_Flow_test()
{
var userA = await _repository.SaveUserAsync(new AppUser()
{
AdEmail = "[email protected]",
PersonId = 321,
EmployeeId = "ABC",
BaseRole = "Developer",
Role = Role.Admin,
HomeDepartment = "Branch-44",
FullName = "Tester, Jane"
});
await _context.SaveChangesAsync();
Assert.NotNull(userA);
var userList = await _repository.SaveUserRangeAsync(new List<AppUser>()
{
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]", FullName = "Test",
PersonId = 123,
EmployeeId = "CBA",
BaseRole = "Developer",
Role = Role.UNKNOWN_ROLE,
HomeDepartment = "Branch-44",
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]", FullName = "Test",
PersonId = 456,
EmployeeId = "DEF",
BaseRole = "Developer",
Role = Role.Admin,
HomeDepartment = "Branch-44"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
FullName = "Test",
PersonId = 789,
EmployeeId = "CONTRACTOR",
BaseRole = "QA",
Role = Role.Teller,
HomeDepartment = "Branch-44"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
FullName = "Test",
PersonId = 900,
EmployeeId = "CONTRACTOR",
BaseRole = "QA",
Role = Role.BM,
HomeDepartment = "Branch-0"
}
});
await _context.SaveChangesAsync();
Assert.NotNull(userList);
Assert.AreEqual(4, userList.Count);
var allUsers = await _repository.GetAllUsersAsync();
Assert.AreEqual(5, allUsers.Count);
var user = await _repository.FindUserAsync("CBA", "[email protected]");
Assert.NotNull(user);
Assert.AreEqual(user.AdEmail, "[email protected]");
user = await _repository.FindUserByAdEmailAsync("[email protected]");
Assert.NotNull(user);
Assert.IsTrue(user.Role == Role.BM);
user = await _repository.FindUserByAdEmailAsync("[email protected]");
Assert.Null(user);
user = await _repository.FindUserByEmployeeIdAsync("DEF");
Assert.NotNull(user);
Assert.IsTrue(user.Role == Role.Admin);
var users = await _repository.FindUsersByBaseRolesAsync(new List<string>() { "QA" });
Assert.NotNull(users);
Assert.AreEqual(2, users.Count);
Assert.AreEqual(2, users.Count(x => x.EmployeeId == "CONTRACTOR"));
users = await _repository.FindUsersByHomeDepartmentsAsync(new List<string>() { "Branch-44" });
Assert.NotNull(users);
Assert.AreEqual(4, users.Count);
Assert.True(users.Any(x => x.AdEmail != "[email protected]"));
}
[Test]
public async Task Find_None_Test()
{
var userList = await _repository.SaveUserRangeAsync(new List<AppUser>()
{
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]", FullName = "Test",
PersonId = 123,
EmployeeId = "ABC",
BaseRole = "Developer",
Role = Role.UNKNOWN_ROLE,
HomeDepartment = "Branch-44"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]", FullName = "Test",
PersonId = 456,
EmployeeId = "DEF",
BaseRole = "Developer",
Role = Role.Admin,
HomeDepartment = "Branch-44"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]", FullName = "Test",
PersonId = 789,
EmployeeId = "CONTRACTOR1",
BaseRole = "QA",
Role = Role.Teller,
HomeDepartment = "Branch-44"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]", FullName = "Test",
PersonId = 900,
EmployeeId = "CONTRACTOR2",
BaseRole = "QA",
Role = Role.BM,
HomeDepartment = "Branch-0"
}
});
await _context.SaveChangesAsync();
var results = await _repository.FindUserAsync("CONTRACTOR", "[email protected]");
Assert.Null(results);
}
[Test]
public async Task search_test()
{
var userList = await _repository.SaveUserRangeAsync(new List<AppUser>()
{
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 123,
EmployeeId = "99x",
BaseRole = "Developer",
FullName = "John Doe",
HomeDepartment = "Branch-44",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "51",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.UNKNOWN_ROLE
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 456,
EmployeeId = "99y",
BaseRole = "Developer",
FullName = "Jane Doe",
HomeDepartment = "Branch-44",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "52",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Admin
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 789,
EmployeeId = "99z",
BaseRole = "QA",
FullName = "John Deer",
HomeDepartment = "Branch-44",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "53",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Teller
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 900,
EmployeeId = "CONTRACTOR",
FullName = "Emily Random",
BaseRole = "QA",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "54",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.BM
}
},
HomeDepartment = "Branch-0"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 910,
EmployeeId = "314159",
FullName = "Wayne, John D",
BaseRole = "QA",
HomeDepartment = "Branch-0",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "55",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Developer
}
}
}
});
await _context.SaveChangesAsync();
Assert.NotNull(userList);
Assert.AreEqual(5, userList.Count);
var allUsers = await _repository.GetAllUsersAsync();
Assert.AreEqual(5, allUsers.Count);
var searchParameters = new UserSearchRequest { Query = "abc" };
var userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().AdEmail, "[email protected]");
searchParameters = new UserSearchRequest { Query = "CONTRACTOR" };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().AdEmail, "[email protected]");
searchParameters = new UserSearchRequest { Query = " q " };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(4, userResults.Count);
searchParameters = new UserSearchRequest { Query = " 99 " };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(3, userResults.Count);
searchParameters = new UserSearchRequest { Query = " doe " };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(2, userResults.Count);
Assert.AreEqual(userResults.First().FullName, "John Doe");
searchParameters = new UserSearchRequest { Role = "UNKNOWN" };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().FullName, "John Doe");
searchParameters = new UserSearchRequest { Role = " BM " };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().FullName, "Emily Random");
searchParameters = new UserSearchRequest { Role = "Manager" };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().FullName, "Emily Random");
searchParameters = new UserSearchRequest { Query = "Fq, De" };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().FullName, "Jane Doe");
searchParameters = new UserSearchRequest { DnaOrgNbr = "6" };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(0, userResults.Count);
searchParameters = new UserSearchRequest { DnaOrgNbr = "55" };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().FullName, "Wayne, John D");
searchParameters = new UserSearchRequest { FirstName = "John", LastName = "Wayne", DnaOrgNbr = "55" };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().FullName, "Wayne, John D");
searchParameters = new UserSearchRequest { FirstName = "John", MiddleInit = "D" };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(1, userResults.Count);
Assert.AreEqual(userResults.First().FullName, "Wayne, John D");
searchParameters = new UserSearchRequest { Query = "," };
userResults = await _repository.SearchUsersAsync(searchParameters);
Assert.NotNull(userResults);
Assert.AreEqual(5, userResults.Count);
}
[Test]
public async Task users_for_payouts()
{
var startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var range = new MonthRange(DateTime.Today.Year, DateTime.Today.Month);
var users = new List<AppUser>()
{
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 123,
EmployeeId = "99x",
BaseRole = "TERMINATED - No",
FullName = "John Terminated",
HomeDepartment = "Branch-44",
Terminated = DateTime.Today.Subtract(TimeSpan.FromDays(30)),
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "51",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.UNKNOWN_ROLE
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 456,
EmployeeId = "99y",
BaseRole = "Developer New This Month - Yes",
FullName = "Jane Active",
HomeDepartment = "Branch-44",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "52",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Admin,
StartDate = startDate,
EndDate = null
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 789,
EmployeeId = "99z",
BaseRole = "QA Active 90 days - Yes",
FullName = "John Deer",
HomeDepartment = "Branch-44",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "53",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Teller,
StartDate = startDate.Subtract(TimeSpan.FromDays(90)),
EndDate = range.EndTime
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 900,
EmployeeId = "CONTRACTOR",
FullName = "Emily Random",
BaseRole = "QA Not Active Yet? - No",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "54",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.BM,
StartDate = startDate.Add(TimeSpan.FromDays(90)),
EndDate = null
}
},
HomeDepartment = "Branch-0"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 910,
EmployeeId = "314159",
FullName = "Wayne, John D",
BaseRole = "QA Exact - Yes",
HomeDepartment = "Branch-0",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "55",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Developer,
StartDate = startDate,
EndDate = startDate.AddMonths(1).Subtract(TimeSpan.FromSeconds(1))
}
}
}
};
var userList = await _repository.SaveUserRangeAsync(users);
await _context.SaveChangesAsync();
Assert.NotNull(userList);
Assert.AreEqual(5, userList.Count);
var allUsers = await _repository.GetAllUsersToPayoutAsync(range);
Assert.AreEqual(3, allUsers.Count);
var selected = allUsers.Select(x => x.EmployeeId).ToList();
var expected = new List<string>()
{
"99y", "99z", "314159"
};
Assert.AreEqual(selected, expected);
}
[Test]
public async Task TerminatedUsers()
{
var startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var inThePast = DateTime.Today.Subtract(TimeSpan.FromDays(DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month) != 31 ? 30 : 31));
var range = new MonthRange(inThePast.Year, inThePast.Month);
var users = new List<AppUser>()
{
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 123,
EmployeeId = "99x",
BaseRole = "TERMINATED - No",
FullName = "John Terminated",
HomeDepartment = "Branch-44",
Terminated = DateTime.Today.Subtract(TimeSpan.FromDays(DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month) != 31 ? 30 : 31)),
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "51",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.UNKNOWN_ROLE
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 456,
EmployeeId = "99y",
BaseRole = "Developer New This Month - Yes",
FullName = "Jane Active",
HomeDepartment = "Branch-44",
Terminated = DateTime.Today,
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "52",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Admin,
StartDate = startDate,
EndDate = null
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 789,
EmployeeId = "99z",
BaseRole = "QA Active 90 days - Yes",
FullName = "John Deer",
HomeDepartment = "Branch-44",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "53",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Teller,
StartDate = startDate.Subtract(TimeSpan.FromDays(90)),
EndDate = range.EndTime
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 900,
EmployeeId = "CONTRACTOR",
FullName = "Emily Random",
BaseRole = "QA Not Active Yet? - No",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "54",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.BM,
StartDate = startDate.Add(TimeSpan.FromDays(90)),
EndDate = null
}
},
HomeDepartment = "Branch-0"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 910,
EmployeeId = "314159",
FullName = "Wayne, John D",
BaseRole = "QA Exact - Yes",
HomeDepartment = "Branch-0",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "55",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Developer,
StartDate = startDate,
EndDate = startDate.AddMonths(1).Subtract(TimeSpan.FromSeconds(1))
}
}
}
};
var userList = await _repository.SaveUserRangeAsync(users);
await _context.SaveChangesAsync();
Assert.NotNull(userList);
Assert.AreEqual(5, userList.Count);
var termList = _repository.GetTerminatedUsersAsync(range);
Assert.AreEqual(1, termList.Count);
var selected = termList.Select(x => x.EmployeeId).ToList();
var expected = new List<string>()
{
"99x"
};
Assert.AreEqual(selected, expected);
range = new MonthRange(DateTime.Today.Year, DateTime.Today.Month);
termList = _repository.GetTerminatedUsersAsync(range);
Assert.AreEqual(1, termList.Count);
selected = termList.Select(x => x.EmployeeId).ToList();
expected = new List<string>()
{
"99y"
};
Assert.AreEqual(selected, expected);
range = new MonthRange(inThePast.Year, inThePast.Month, DateTime.Today.Year, DateTime.Today.Month);
Assert.Throws<ArgumentException>(() => { _repository.GetTerminatedUsersAsync(range); });
}
[Test]
public async Task GetActiveEmployeeReturnsNothingWhenOnlyMatchingInfoAppUserHasNonNullTermDate()
{
var startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var inThePast = DateTime.Today.Subtract(TimeSpan.FromDays(30));
var range = new MonthRange(inThePast.Year, inThePast.Month);
const string termedEmployeeQueryEmail = "[email protected]";
const string termedEmployeeQueryEmployeeId = "99y";
var laterTermedEmployeeRecordGuid = Guid.NewGuid();
var users = new List<AppUser>()
{
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 123,
EmployeeId = "99x",
BaseRole = "TERMINATED - No",
FullName = "John Terminated",
HomeDepartment = "Branch-44",
Terminated = DateTime.Today.Subtract(TimeSpan.FromDays(30)),
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "51",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.UNKNOWN_ROLE
}
}
},
new()
{
Id = laterTermedEmployeeRecordGuid,
AdEmail = termedEmployeeQueryEmail,
PersonId = 456,
EmployeeId = termedEmployeeQueryEmployeeId,
BaseRole = "Developer New This Month - Yes",
FullName = "Jane Active",
HomeDepartment = "Branch-44",
Terminated = DateTime.Today,
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "52",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Admin,
StartDate = startDate,
EndDate = null
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = termedEmployeeQueryEmail,
PersonId = 456,
EmployeeId = termedEmployeeQueryEmployeeId,
BaseRole = "Developer New This Month - Yes",
FullName = "Jane Active",
HomeDepartment = "Branch-44",
Terminated = DateTime.Today.AddDays(-10),
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "52",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Admin,
StartDate = startDate,
EndDate = null
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 789,
EmployeeId = "99z",
BaseRole = "QA Active 90 days - Yes",
FullName = "John Deer",
HomeDepartment = "Branch-44",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "53",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Teller,
StartDate = startDate.Subtract(TimeSpan.FromDays(90)),
EndDate = range.EndTime
}
}
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 900,
EmployeeId = "CONTRACTOR",
FullName = "Emily Random",
BaseRole = "QA Not Active Yet? - No",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "54",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.BM,
StartDate = startDate.Add(TimeSpan.FromDays(90)),
EndDate = null
}
},
HomeDepartment = "Branch-0"
},
new()
{
Id = Guid.NewGuid(),
AdEmail = "[email protected]",
PersonId = 910,
EmployeeId = "314159",
FullName = "Wayne, John D",
BaseRole = "QA Exact - Yes",
HomeDepartment = "Branch-0",
Role = Role.BusinessLineManager,
Departments = new List<UserDepartment>()
{
new()
{
Department = new Department()
{
DnaOrgNbr = "55",
DayforceDepartmentName = "Test",
DayForceGlCode = "Test",
DepartmentName = "Test",
BusinessLineCode = BusinessLine.Operations.Code,
},
DepartmentId = 3,
Role = Role.Developer,
StartDate = startDate,
EndDate = startDate.AddMonths(1).Subtract(TimeSpan.FromSeconds(1))
}
}
}
};
var userList = await _repository.SaveUserRangeAsync(users);
await _context.SaveChangesAsync();
Assert.NotNull(userList);
Assert.AreEqual(6, userList.Count);
var termedShouldBeNullEmployeeEmailResult = await _repository.FindActiveUserByAdEmailAsync(termedEmployeeQueryEmail);
var termedShouldBeNullEmployeeEmployeeIdResult = await _repository.FindActiveUserByEmployeeIdAsync(termedEmployeeQueryEmployeeId);
Assert.IsNull(termedShouldBeNullEmployeeEmailResult);
Assert.IsNull(termedShouldBeNullEmployeeEmployeeIdResult);
var termedShouldNotBeNullEmployeeEmailResult = await _repository.FindUserByAdEmailAsync(termedEmployeeQueryEmail);
var termedShouldNotBeNullEmployeeEmployeeIdResult = await _repository.FindUserByEmployeeIdAsync(termedEmployeeQueryEmployeeId);
Assert.IsNotNull(termedShouldNotBeNullEmployeeEmailResult);
Assert.IsNotNull(termedShouldNotBeNullEmployeeEmployeeIdResult);
Assert.AreEqual(termedShouldNotBeNullEmployeeEmailResult.Id, laterTermedEmployeeRecordGuid);
Assert.AreEqual(termedShouldNotBeNullEmployeeEmployeeIdResult.Id, laterTermedEmployeeRecordGuid);
}
}
}