using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using LCU.API.Internal.Operations.IncentiveApi.Exceptions; using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer; using LCU.API.Internal.Operations.IncentiveApi.Models.Dayforce; using LCU.API.Internal.Operations.IncentiveApiLib.Persistence; using LCU.API.Internal.Operations.IncentiveApiLib.Repositories; using LCU.API.Internal.Operations.IncentiveApiLib.Services; using LCU.Library.Internal.IncentiveApiModels.Entities; using LCU.Library.Internal.IncentiveApiModels.Enums; using LCU.Library.Internal.IncentiveApiModels.Requests; using LCU.Library.Internal.IncentiveApiModels.Results; using LCU.API.Internal.Operations.IncentiveApi.Extensions; using Moq; using NUnit.Framework; namespace Application.UnitTests.Services { public class UserServiceTest { private IApplicationDbIntegrityService _applicationDbIntegrityService; private IDepartmentRepository _departmentRepository; private IRoleMappingRepository _roleMappingRepository; private IUnitOfWork _unitOfWork; private IUserDepartmentHistoryRepository _userDepartmentHistoryRepository; private IUserPermissionHistoryRepository _userPermissionHistoryRepository; private IUserRepository _userRepository; private UserService _userService; [SetUp] public void Setup() { _applicationDbIntegrityService = Mock.Of(); _departmentRepository = Mock.Of(); _roleMappingRepository = Mock.Of(); _unitOfWork = Mock.Of(); _userDepartmentHistoryRepository = Mock.Of(); _userPermissionHistoryRepository = Mock.Of(); _userRepository = Mock.Of(); var roleMappings = new List { new() { ApplicationRole = Role.Teller, BusinessRole = "ACH REPRESENTATIVE" } }; Mock.Get(_roleMappingRepository) .Setup(s => s.FindMatchingRoleFromBusinessRole(It.IsAny())) .Returns(roleMappings.FirstOrDefault()?.ApplicationRole); _userService = new UserService( _applicationDbIntegrityService, _departmentRepository, _roleMappingRepository, _unitOfWork, _userDepartmentHistoryRepository, _userPermissionHistoryRepository, _userRepository ); } [Test] public async Task GetAllUsers_NoQuery() { Mock.Get(_userRepository) .Setup(s => s.GetAllUsersAsync()) .ReturnsAsync(new List { new AppUser { AdEmail = "test1@test.com" } }); Mock.Get(_userRepository) .Setup(s => s.SearchUsersAsync(It.IsAny())) .ReturnsAsync(new List { new AppUser { AdEmail = "test2@test.com" } }); var results = await _userService.GetAllUsersAsync(new UserSearchRequest()); Assert.NotNull(results); Assert.AreEqual(1, results.Count); Assert.AreEqual("test1@test.com", results.First().AdEmail); } [Test] public async Task FindManager_OK() { var manager = new AppUser { EmployeeId = "11771" }; var employee = new AppUser { EmployeeId = "C00002", ManagerKey = manager.EmployeeId }; Mock.Get(_userRepository) .Setup(s => s.FindUserByEmployeeIdAsync("11771")) .ReturnsAsync(manager); var results = await _userService.FindManager(employee); Assert.NotNull(results); Assert.AreEqual(manager, results); } [Test] public async Task GetAllUsers_query() { Mock.Get(_userRepository) .Setup(s => s.GetAllUsersAsync()) .ReturnsAsync(new List { new AppUser { AdEmail = "test1@test.com" } }); Mock.Get(_userRepository) .Setup(s => s.SearchUsersAsync(It.IsAny())) .ReturnsAsync(new List { new AppUser { AdEmail = "test2@test.com" } }); var searchRequest = new UserSearchRequest { Query = "test2" }; var results = await _userService.GetAllUsersAsync(searchRequest); Assert.NotNull(results); Assert.AreEqual(1, results.Count); Assert.AreEqual("test2@test.com", results.First().AdEmail); } [Test] public async Task GetUsersByEmployeeId() { Mock.Get(_userRepository) .Setup(s => s.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( new AppUser { AdEmail = "test1@test.com" } ); Mock.Get(_userRepository) .Setup(s => s.FindUserByAdEmailAsync(It.IsAny())) .ReturnsAsync( new AppUser { AdEmail = "test1@test.com" } ); var results = await _userService.GetUserByEmployeeIdAsync("11771"); Assert.NotNull(results); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync(It.IsAny()), Times.Once); Mock.Get(_userRepository).Verify(s => s.FindUserByAdEmailAsync(It.IsAny()), Times.Never); } [Test] public async Task GetUsersByAdEmail() { Mock.Get(_userRepository) .Setup(s => s.FindUserByAdEmailAsync(It.IsAny())) .ReturnsAsync( new AppUser { AdEmail = "test1@test.com" } ); var results = await _userService.GetUserByAdEmailAsync("test1@test.com"); Assert.NotNull(results); Mock.Get(_userRepository).Verify(s => s.FindUserByAdEmailAsync(It.IsAny()), Times.Once); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync(It.IsAny()), Times.Never); } [Test] public async Task FindUser() { Mock.Get(_userRepository) .Setup(s => s.FindUserAsync(It.IsAny(), It.IsAny())) .ReturnsAsync( new AppUser { AdEmail = "test1@test.com" } ); var results = await _userService.FindUserAsync("11771", "test1@test.com"); Assert.NotNull(results); Mock.Get(_userRepository).Verify(s => s.FindUserAsync(It.IsAny(), It.IsAny()), Times.Once); Mock.Get(_userRepository).Verify(s => s.FindUserByAdEmailAsync(It.IsAny()), Times.Never); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync(It.IsAny()), Times.Never); } [Test] public async Task SyncDayForce_NewUser() { var rawData = new Dictionary { ["EmploymentStatus_ShortName"] = "Active", ["Employee_DisplayName"] = "Doe, Test", ["EmployeeEmploymentStatus_EmployeeNumber"] = "11771", ["IdLibrary_LoginName"] = "testdoe@landmarkcu.com", ["OrgUnit_ShortName"] = "WAUWATOSA - BRANCH", ["Job_ShortName"] = "TELLER II", ["OrgUnit_LedgerCode"] = "101", ["Employee_HireDate"] = "2019-09-23T00:00:00.0000000" }; var toProcess = new ActiveEmployeeResult(rawData); Mock.Get(_departmentRepository) .Setup(s => s.FindOrCreateDepartment(toProcess)) .ReturnsAsync( new Department { Id = 1, State = DepartmentState.Active, DepartmentName = "WAUWATOSA", BusinessLineCode = BusinessLine.Operations.Code }); Mock.Get(_userRepository).Setup(s => s.FindUserByEmployeeIdAsync("11771")).ReturnsAsync((AppUser)null); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var newUser = await _userService.SyncDayForceEmployee(toProcess); Assert.NotNull(newUser); Assert.AreEqual(rawData["IdLibrary_LoginName"], newUser.AdEmail); Assert.NotNull(newUser.Departments); Assert.IsNotEmpty(newUser.Departments); var userDept = newUser.Departments.First(); Assert.NotNull(userDept.StartDate); Assert.AreEqual(9, userDept.StartDate.Month); Assert.AreEqual(1, userDept.StartDate.Day); Assert.NotNull(userDept.Role); Assert.AreEqual(Role.Teller, userDept.Role); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_departmentRepository).Verify(s => s.FindOrCreateDepartment(toProcess), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Once); } [Test] public async Task SyncDayForce_NewUser_BadHireDate() { var rawData = new Dictionary { ["EmploymentStatus_ShortName"] = "Active", ["Employee_DisplayName"] = "Doe, Test", ["EmployeeEmploymentStatus_EmployeeNumber"] = "11771", ["IdLibrary_LoginName"] = "testdoe@landmarkcu.com", ["OrgUnit_ShortName"] = "WAUWATOSA - BRANCH", ["Job_ShortName"] = "TELLER II", ["OrgUnit_LedgerCode"] = "101", ["Employee_HireDate"] = DateTime.MinValue.ToLongTimeString() }; var toProcess = new ActiveEmployeeResult(rawData); Mock.Get(_departmentRepository) .Setup(s => s.FindOrCreateDepartment(toProcess)) .ReturnsAsync( new Department { Id = 1, State = DepartmentState.Active, DepartmentName = "WAUWATOSA", BusinessLineCode = BusinessLine.Operations.Code }); Mock.Get(_userRepository).Setup(s => s.FindUserByEmployeeIdAsync("11771")).ReturnsAsync((AppUser)null); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var newUser = await _userService.SyncDayForceEmployee(toProcess); Assert.NotNull(newUser); Assert.AreEqual(rawData["IdLibrary_LoginName"], newUser.AdEmail); Assert.NotNull(newUser.Departments); Assert.IsNotEmpty(newUser.Departments); var userDept = newUser.Departments.First(); Assert.NotNull(userDept.StartDate); Assert.AreEqual(DateTime.Today.Year, userDept.StartDate.Year); Assert.AreEqual(DateTime.Today.Month, userDept.StartDate.Month); Assert.AreEqual(1, userDept.StartDate.Day); Assert.NotNull(userDept.Role); Assert.AreEqual(Role.Teller, userDept.Role); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_departmentRepository).Verify(s => s.FindOrCreateDepartment(toProcess), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Once); } [Test] public async Task SyncDayForce_ExistingUser_SameDept_nochanges() { var rawData = new Dictionary { ["EmploymentStatus_ShortName"] = "Active", ["Employee_DisplayName"] = "Doe, Test", ["EmployeeEmploymentStatus_EmployeeNumber"] = "11771", ["IdLibrary_LoginName"] = "testdoe@landmarkcu.com", ["OrgUnit_ShortName"] = "WAUWATOSA - BRANCH", ["Job_ShortName"] = "TELLER II", ["OrgUnit_LedgerCode"] = "101", ["Employee_HireDate"] = "2024-10-05T00:00:00.0000000" }; var toProcess = new ActiveEmployeeResult(rawData); var department = new Department { Id = 1, State = DepartmentState.Active, DepartmentName = "WAUWATOSA", BusinessLineCode = BusinessLine.Operations.Code }; var user = new AppUser { AdEmail = "test@test.com", BaseRole = "fun", EmployeeId = "11771", HomeDepartment = "home", Departments = new List(), FullName = "Doe, Test" }; var userDepartment = new UserDepartment { Id = 11, Department = department, Employee = user, StartDate = DateTime.Parse("2024-11-01T00:00:00.0000000"), IsHome = true, Note = "For Testing", Role = Role.Teller }; user.Departments.Add(userDepartment); Mock.Get(_departmentRepository).Setup(s => s.FindOrCreateDepartment(toProcess)).ReturnsAsync(department); Mock.Get(_userRepository).Setup(s => s.FindUserByEmployeeIdAsync("11771")).ReturnsAsync(user); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var existingUser = await _userService.SyncDayForceEmployee(toProcess); Assert.NotNull(existingUser); Assert.NotNull(existingUser.Departments); Assert.IsNotEmpty(existingUser.Departments); Assert.AreEqual(1, existingUser.Departments.Count); userDepartment = existingUser.Departments.FirstOrDefault(x => x.IsHome && x.EndDate == null); Assert.NotNull(userDepartment.Role); Assert.AreEqual(Role.Teller, userDepartment.Role); Assert.NotNull(userDepartment.StartDate); Assert.AreEqual(2024, userDepartment.StartDate.Year); Assert.AreEqual(11, userDepartment.StartDate.Month); Assert.Null(userDepartment.EndDate); Assert.AreEqual(userDepartment.Department.Id, department.Id); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_departmentRepository).Verify(s => s.FindOrCreateDepartment(toProcess), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Once); } [Test] public void DotNet_Quick_Date_Test() { // 1. Start in december. var date1 = DateTime.Parse("2025-12-12T00:00:00.0000000"); Assert.AreEqual(12, date1.Month); // 2. It will throw if month = 13, some frameworks figure this out... C#... no. Assert.Throws(() => { var throwAway = new DateTime(date1.Year, date1.Month + 1, 1); }); // 3. Move to using AddMonths to try and get the first of the year. var date2 = new DateTime(date1.Year, date1.Month, 1).AddMonths(1); Assert.AreEqual(1, date2.Month); Assert.AreEqual(1, date2.Day); Assert.AreEqual(date1.Year + 1, date2.Year); // 4. Subtracting a day should give 12/31 of the original year var endDate = date2.Subtract(TimeSpan.FromDays(1)); Assert.AreEqual(12, endDate.Month); Assert.AreEqual(date1.Year, endDate.Year); Assert.AreEqual(31, endDate.Day); } [Test] public async Task SyncDayForce_ExistingUser_ChangeDept() { var rawData = new Dictionary { ["EmploymentStatus_ShortName"] = "Active", ["Employee_DisplayName"] = "Doe, Test", ["EmployeeEmploymentStatus_EmployeeNumber"] = "11771", ["IdLibrary_LoginName"] = "testdoe@landmarkcu.com", ["OrgUnit_ShortName"] = "WAUWATOSA - BRANCH", ["Job_ShortName"] = "BRANCH MANAGER", ["OrgUnit_LedgerCode"] = "101", ["Employee_HireDate"] = "2025-10-05T00:00:00.0000000" }; var toProcess = new ActiveEmployeeResult(rawData); var department = new Department { Id = 1, State = DepartmentState.Active, DepartmentName = "WAUWATESTA", BusinessLineCode = BusinessLine.BranchOperations.Code }; var departmentNew = new Department { Id = 2, State = DepartmentState.Active, DepartmentName = "WAUWATOSA", BusinessLineCode = BusinessLine.BranchOperations.Code }; var user = new AppUser { AdEmail = "test@test.com", BaseRole = "fun", EmployeeId = "11771", HomeDepartment = "home", Departments = new List(), FullName = "Doe, Test" }; var userDepartment = new UserDepartment { Id = 11, Department = department, Employee = user, StartDate = DateTime.Parse("2024-10-05T00:00:00.0000000"), IsHome = true, Role = Role.Teller, Note = "Auto Generated Home Assignment", }; user.Departments.Add(userDepartment); Mock.Get(_roleMappingRepository).Setup(s => s.FindMatchingRoleFromBusinessRole(It.IsAny())).Returns(Role.BM); Mock.Get(_departmentRepository).Setup(s => s.FindOrCreateDepartment(toProcess)).ReturnsAsync(departmentNew); Mock.Get(_userRepository).Setup(s => s.FindUserByEmployeeIdAsync("11771")).ReturnsAsync(user); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var existingUser = await _userService.SyncDayForceEmployee(toProcess); Assert.NotNull(existingUser); Assert.NotNull(existingUser.Departments); Assert.IsNotEmpty(existingUser.Departments); Assert.AreEqual(2, existingUser.Departments.Count); var newUserDepartment = existingUser.Departments.FirstOrDefault(x => x.IsHome && x.EndDate == null); Assert.NotNull(newUserDepartment.StartDate); Assert.AreEqual(DateTime.Today.Year, newUserDepartment.StartDate.Year); Assert.AreEqual(DateTime.Today.Month, newUserDepartment.StartDate.Month); Assert.Null(newUserDepartment.EndDate); Assert.True(newUserDepartment.IsHome); Assert.NotNull(newUserDepartment.Role); Assert.AreEqual(Role.BM, newUserDepartment.Role); var oldUserDepartment = existingUser.Departments.FirstOrDefault(x => x.Department.Id == 1); Assert.NotNull(oldUserDepartment.StartDate); Assert.NotNull(oldUserDepartment.EndDate); Assert.False(oldUserDepartment.IsHome); Assert.NotNull(oldUserDepartment.Role); Assert.IsEmpty(oldUserDepartment.Note); Assert.AreEqual(Role.Teller, oldUserDepartment.Role); Assert.AreEqual(newUserDepartment.Department.Id, departmentNew.Id); Assert.AreNotEqual(department.Id, departmentNew.Id); Mock.Get(_userRepository).Verify(s => s.SaveUserAsync(It.IsAny()), Times.Never); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_departmentRepository).Verify(s => s.FindOrCreateDepartment(toProcess), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Once); } [Test] public async Task SyncDayForce_ExistingUser_ChangeDept_Back() { var monthBegin = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); var monthEnd = monthBegin.EndOfMonth(); var rawData = new Dictionary { ["EmploymentStatus_ShortName"] = "Active", ["Employee_DisplayName"] = "Doe, Test", ["EmployeeEmploymentStatus_EmployeeNumber"] = "11771", ["IdLibrary_LoginName"] = "testdoe@landmarkcu.com", ["OrgUnit_ShortName"] = "WAUWATOSA - BRANCH", ["Job_ShortName"] = "CLIENT SRVC ASST-LIC", ["OrgUnit_LedgerCode"] = "101", ["Employee_HireDate"] = DateTime.Today.ToLongTimeString() }; var toProcess = new ActiveEmployeeResult(rawData); var user = new AppUser { AdEmail = "test@test.com", BaseRole = "fun", EmployeeId = "11771", HomeDepartment = "home", Departments = new List(), FullName = "Doe, Test" }; var departmentA = new Department { Id = 10, State = DepartmentState.Active, DepartmentName = "WAUWATESTA", BusinessLineCode = BusinessLine.BranchOperations.Code }; var departmentB = new Department { Id = 20, State = DepartmentState.Active, DepartmentName = "WAUWATOSA", BusinessLineCode = BusinessLine.BranchOperations.Code }; var currentHomeUserDept = new UserDepartment { Id = 11, Department = departmentA, Employee = user, StartDate = monthBegin, EndDate = null, IsHome = true, Note = "For Testing", Role = Role.Teller }; var userDepartmentB = new UserDepartment { Id = 21, Department = departmentB, Employee = user, StartDate = monthBegin, EndDate = monthEnd, IsHome = true, Note = "For Testing", Role = Role.BM }; user.Departments.Add(currentHomeUserDept); user.Departments.Add(userDepartmentB); Mock.Get(_departmentRepository).Setup(s => s.FindOrCreateDepartment(toProcess)).ReturnsAsync(departmentB); Mock.Get(_userRepository).Setup(s => s.FindUserByEmployeeIdAsync("11771")).ReturnsAsync(user); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); Mock.Get(_roleMappingRepository).Setup(s => s.FindMatchingRoleFromBusinessRole(It.IsAny())).Returns(Role.LIC); var existingUser = await _userService.SyncDayForceEmployee(toProcess); Assert.NotNull(existingUser); Assert.NotNull(existingUser.Departments); Assert.IsNotEmpty(existingUser.Departments); Assert.AreEqual(2, existingUser.Departments.Count); var newUserDepartment = existingUser.Departments.FirstOrDefault(x => x.IsHome && x.EndDate == null); Assert.NotNull(newUserDepartment.StartDate); Assert.Null(newUserDepartment.EndDate); Assert.NotNull(currentHomeUserDept.EndDate); Assert.True(newUserDepartment.IsHome); Assert.NotNull(newUserDepartment.Role); Assert.AreEqual(Role.LIC, newUserDepartment.Role); var oldUserDepartment = existingUser.Departments.FirstOrDefault(x => x.Department.Id == 10); Assert.NotNull(oldUserDepartment.StartDate); Assert.NotNull(oldUserDepartment.EndDate); Assert.False(oldUserDepartment.IsHome); Assert.NotNull(oldUserDepartment.Role); Assert.AreEqual(Role.Teller, oldUserDepartment.Role); Assert.AreEqual(newUserDepartment.Department.Id, departmentB.Id); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_departmentRepository).Verify(s => s.FindOrCreateDepartment(toProcess), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Once); } [Test] public async Task SyncDayForce_ExistingUser_ChangeFloat_To_Home() { var monthBegin = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); var rawData = new Dictionary { ["EmploymentStatus_ShortName"] = "Active", ["Employee_DisplayName"] = "Doe, Test", ["EmployeeEmploymentStatus_EmployeeNumber"] = "11771", ["IdLibrary_LoginName"] = "testdoe@landmarkcu.com", ["OrgUnit_ShortName"] = "WAUWATOSA - BRANCH", ["Job_ShortName"] = "TELLER II", ["OrgUnit_LedgerCode"] = "101", ["Employee_HireDate"] = DateTime.Today.ToLongTimeString() }; var toProcess = new ActiveEmployeeResult(rawData); var user = new AppUser { Role = Role.Teller, AdEmail = "test@test.com", BaseRole = "fun", EmployeeId = "11771", HomeDepartment = "home", Departments = new List(), FullName = "Doe, Test" }; var departmentA = new Department { Id = 10, State = DepartmentState.Active, DepartmentName = "WAUWATESTA", BusinessLineCode = BusinessLine.BranchOperations.Code }; var departmentB = new Department { Id = 20, State = DepartmentState.Active, DepartmentName = "WAUWATOSA", BusinessLineCode = BusinessLine.BranchOperations.Code }; var userDepartmentA = new UserDepartment { Id = 11, Department = departmentA, Employee = user, StartDate = monthBegin, EndDate = null, IsHome = true, Note = "For Testing" }; var userDepartmentB = new UserDepartment { Id = 21, Department = departmentB, Employee = user, StartDate = monthBegin, EndDate = null, IsHome = false, Note = "For Testing" }; user.Departments.Add(userDepartmentA); user.Departments.Add(userDepartmentB); Mock.Get(_departmentRepository).Setup(s => s.FindOrCreateDepartment(toProcess)).ReturnsAsync(departmentB); Mock.Get(_userRepository).Setup(s => s.FindUserByEmployeeIdAsync("11771")).ReturnsAsync(user); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var existingUser = await _userService.SyncDayForceEmployee(toProcess); Assert.NotNull(existingUser); Assert.AreEqual(Role.Teller, existingUser.Role); Assert.NotNull(existingUser.Departments); Assert.IsNotEmpty(existingUser.Departments); Assert.AreEqual(2, existingUser.Departments.Count); var newUserDepartment = existingUser.Departments.FirstOrDefault(x => x.IsHome && x.EndDate == null); Assert.NotNull(newUserDepartment.StartDate); Assert.Null(newUserDepartment.EndDate); Assert.IsTrue(newUserDepartment.IsHome); Assert.NotNull(userDepartmentA.EndDate); Assert.AreEqual(newUserDepartment.Department.Id, departmentB.Id); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_departmentRepository).Verify(s => s.FindOrCreateDepartment(toProcess), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Once); } [Test] public async Task AssignDepartment_OK() { var department = new Department { Id = 1, State = DepartmentState.Active, DepartmentName = "Test Dept", BusinessLineCode = BusinessLine.BranchOperations.Code }; var assignment = new DepartmentAssignmentRequest { Note = "Test Assignment", DepartmentId = new int[1], StartDate = DateTime.Today, SlidingPayout = 100, Role = Role.Teller.Name }; var employee = new AppUser { Role = Role.Teller, AdEmail = "test@test.com", BaseRole = "fun", EmployeeId = "11771", HomeDepartment = "home" }; Mock.Get(_departmentRepository) .Setup(s => s.FindDepartmentByIdAsync(It.IsAny())) .ReturnsAsync(department); Mock.Get(_userRepository) .Setup(s => s.FindUserByEmployeeIdAsync(employee.EmployeeId)) .ReturnsAsync( employee); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var newUserDepartment = await _userService.AssignDepartments(employee.EmployeeId, assignment); Assert.NotNull(newUserDepartment); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Once); } [Test] public void AssignDepartment_Bad() { var department = new Department { Id = 555, State = DepartmentState.Active, DepartmentName = "Test Dept", BusinessLineCode = BusinessLine.Operations.Code }; var assignment = new DepartmentAssignmentRequest { Note = "Test Assignment", DepartmentId = new int[555], StartDate = DateTime.Today }; var employee = new AppUser { Role = Role.Teller, AdEmail = "test@test.com", BaseRole = "fun", EmployeeId = "11771", HomeDepartment = "home" }; Mock.Get(_departmentRepository) .Setup(s => s.FindDepartmentByIdAsync(department.Id.Value)) .ThrowsAsync(new NotFoundException("Oops")); Mock.Get(_userRepository) .Setup(s => s.FindUserByEmployeeIdAsync(employee.EmployeeId)) .ReturnsAsync( employee); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); Assert.ThrowsAsync(async () => { await _userService.AssignDepartments(employee.EmployeeId, assignment); }); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never); } [Test] public void AssignDepartment_Bad_Role() { var department = new Department { Id = 555, State = DepartmentState.Active, DepartmentName = "Test Dept", BusinessLineCode = BusinessLine.Operations.Code }; var assignment = new DepartmentAssignmentRequest { Note = "Test Assignment", DepartmentId = new int[555], StartDate = DateTime.Today, SlidingPayout = 200 // oh yeah, double payout! }; var employee = new AppUser { Role = Role.Teller, AdEmail = "test@test.com", BaseRole = "fun", EmployeeId = "11771", HomeDepartment = "home" }; Mock.Get(_departmentRepository) .Setup(s => s.FindDepartmentByIdAsync(department.Id.Value)) .ReturnsAsync(department); Mock.Get(_userRepository) .Setup(s => s.FindUserByEmployeeIdAsync(employee.EmployeeId)) .ReturnsAsync( employee); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); Assert.ThrowsAsync(async () => { await _userService.AssignDepartments(employee.EmployeeId, assignment); }); assignment.Role = Role.Teller.Name; // Should still throw... no payout window Assert.ThrowsAsync(async () => { await _userService.AssignDepartments(employee.EmployeeId, assignment); }); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Exactly(2)); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never); } [Test] public async Task UpdatePermissions_OK() { Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( new AppUser { //Perms: ElligableForReferrals, ViewDashboard Departments = new List { new UserDepartment { Role = Role.Teller, StartDate = DateTime.Today.Subtract(TimeSpan.FromDays(30)) } }, AdditionalPermissions = new List { new UserPermission { Permission = Permission.HaveSalesGoals } } }); var res = await _userService.UpdatePermissions("123", new AdditionalPermissionRequest { //Already has Eligible for referrals based on role, should not add AddPermCodes = new List { "ELIGIBLE_FOR_REFERRALS", "MANAGE_DEPARTMENT_GOALS" }, RemovePermCodes = new List { "HAVE_SALES_GOALS", "UNKOWN" } }); Assert.AreEqual(1, res.Count); Assert.True(res.Contains(Permission.ManageDepartmentGoals)); } [Test] public async Task UpdatePermissions_BadCodes_OK() { Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( new AppUser { //Perms: ElligableForReferrals, ViewDashboard Departments = new List { new UserDepartment { Role = Role.Teller, StartDate = DateTime.Today.Subtract(TimeSpan.FromDays(30)) } }, AdditionalPermissions = new List { new UserPermission { Permission = Permission.HaveSalesGoals } } }); var res = await _userService.UpdatePermissions("123", new AdditionalPermissionRequest { //Already has Eligible for referrals based on role, should not add AddPermCodes = new List { "ELIGIBLE_FOR_REFERRALS", "MANAGE_DEPARTMENT_GOALS", "NOTREAL", "FAKE", "DISREGARD" }, RemovePermCodes = new List { "HAVE_SALES_GOALS", "UNKOWN", "HELLO", "FUTURE", "TESTER" } }); Assert.AreEqual(1, res.Count); Assert.True(res.Contains(Permission.ManageDepartmentGoals)); } [Test] public async Task UpdatePermissions_Add_OK() { Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( new AppUser { //Perms: EligibleForReferrals, ViewDashboard Departments = new List { new UserDepartment { Role = Role.Teller } }, AdditionalPermissions = new List { new UserPermission { Permission = Permission.HaveSalesGoals } } }); var res = await _userService.UpdatePermissions("123", new AdditionalPermissionRequest { //Already has Eligible for referrals based on role, should not add AddPermCodes = new List { "ELIGIBLE_FOR_REFERRALS", "MANAGE_DEPARTMENT_GOALS" }, RemovePermCodes = new List() }); Assert.AreEqual(2, res.Count); Assert.True(res.Contains(Permission.ManageDepartmentGoals)); Assert.True(res.Contains(Permission.HaveSalesGoals)); } [Test] public async Task UpdatePermissions_Remove_OK() { Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( new AppUser { //Perms: ElligibleForReferrals, ViewDashboard Departments = new List { new UserDepartment { Role = Role.Teller } }, AdditionalPermissions = new List { new UserPermission { Permission = Permission.HaveSalesGoals, }, new UserPermission { Permission = Permission.Unknown } } }); var res = await _userService.UpdatePermissions("123", new AdditionalPermissionRequest { //Has Eligible for referrals based on role, should not remove RemovePermCodes = new List { "ELIGIBLE_FOR_REFERRALS", "UNKNOWN" }, AddPermCodes = new List() }); Assert.AreEqual(1, res.Count); Assert.AreEqual(Permission.HaveSalesGoals, res.Single()); } [Test] public async Task UpdatePermissions_Add_AlreadyExisting_OK() { Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( new AppUser { //Perms: ElligibleForReferrals, ViewDashboard Departments = new List { new UserDepartment { Role = Role.Teller } }, AdditionalPermissions = new List { new UserPermission { Permission = Permission.HaveSalesGoals } } }); var res = await _userService.UpdatePermissions("123", new AdditionalPermissionRequest { //Already has Eligible for referrals based on role, should not add AddPermCodes = new List { "HAVE_SALES_GOALS" }, RemovePermCodes = new List() }); Assert.AreEqual(1, res.Count); Assert.True(res.Contains(Permission.HaveSalesGoals)); } [Test] public async Task UpdatePermissions_Remove_NonExistant_OK() { Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( new AppUser { //Perms: EligibleForReferrals, ViewDashboard Departments = new List { new UserDepartment { Role = Role.Teller } }, AdditionalPermissions = new List { new UserPermission { Permission = Permission.HaveSalesGoals, } } }); var res = await _userService.UpdatePermissions("123", new AdditionalPermissionRequest { //Has Eligible for referrals based on role, should not remove RemovePermCodes = new List { "UNKNOWN" }, AddPermCodes = new List() }); Assert.AreEqual(1, res.Count); Assert.True(res.Contains(Permission.HaveSalesGoals)); } [Test] public async Task TerminateDayforce_Skip_AlreadyTermed() { var rawData = new Dictionary { ["Employee_DisplayName"] = "Doe, Test", ["EmployeeEmploymentStatus_EmployeeNumber"] = "11771", ["EmployeeManager_ManagerEmployeeNumber"] = "C00002", ["IdLibrary_LoginName"] = "testdoe@landmarkcu.com", ["OrgUnit_ShortName"] = "WAUWATOSA - BRANCH", ["Job_ShortName"] = "TELLER II", ["Employee_TerminationDate"] = "2019-09-23T00:00:00.0000000" }; var terminated = new TerminatedEmployeeResult(rawData); Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( new AppUser { Role = Role.Teller, AdditionalPermissions = new List(), Terminated = DateTime.Today }); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var result = await _userService.TerminateDayForceEmployee(terminated); Assert.Null(result); Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); Mock.Get(_userRepository).Verify(s => s.SaveUserAsync(It.IsAny()), Times.Never); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never); } [Test] public async Task TerminateDayforce_Basic() { var rawData = new Dictionary { ["Employee_DisplayName"] = "Doe, Test", ["EmployeeEmploymentStatus_EmployeeNumber"] = "11771", ["EmployeeManager_ManagerEmployeeNumber"] = "C00002", ["IdLibrary_LoginName"] = "testdoe@landmarkcu.com", ["OrgUnit_ShortName"] = "WAUWATOSA - BRANCH", ["Job_ShortName"] = "TELLER II", ["Employee_TerminationDate"] = "2019-09-23T00:00:00.0000000" }; var terminated = new TerminatedEmployeeResult(rawData); var termUser = new AppUser { AdditionalPermissions = new List { new UserPermission { Permission = Permission.HaveSalesGoals, } }, Departments = new List { new UserDepartment { StartDate = DateTime.Today, EndDate = null, Role = Role.Teller, } } }; Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync( termUser); Mock.Get(_userRepository).Setup(s => s.SaveUserAsync(It.IsAny())).ReturnsAsync((AppUser x) => x); Mock.Get(_applicationDbIntegrityService).Setup(s => s.SyncIdsWithDb(It.IsAny(), false)).ReturnsAsync(true); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); Assert.Null(termUser.Terminated); Assert.NotNull(termUser.AdditionalPermissions); Assert.IsNotEmpty(termUser.AdditionalPermissions); foreach (var department in termUser.Departments) { Assert.Null(department.EndDate); } var result = await _userService.TerminateDayForceEmployee(terminated); Assert.NotNull(result); Assert.NotNull(result.Terminated); Assert.NotNull(result.AdditionalPermissions); Assert.IsEmpty(result.AdditionalPermissions); foreach (var department in result.Departments) { Assert.NotNull(department.EndDate); } Mock.Get(_userRepository).Verify(s => s.FindUserByEmployeeIdAsync("11771"), Times.Once); // SaveUserAsync is for new users. Mock.Get(_userRepository).Verify(s => s.SaveUserAsync(It.IsAny()), Times.Never); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Once); } [Test] public void UpdatePermissions_NoUser_OK() { Mock.Get(_userRepository) .Setup(x => x.FindUserByEmployeeIdAsync(It.IsAny())) .ReturnsAsync((AppUser)null); Assert.ThrowsAsync(async () => await _userService.UpdatePermissions("123", new AdditionalPermissionRequest { //Already has Eligible for referrals based on role, should not add AddPermCodes = new List { "ELIGIBLE_FOR_REFERRALS", "APPROVE_REFERRALS" }, RemovePermCodes = new List { "HAVE_SALES_GOALS", "UNKOWN" } })); } [Test] public async Task TryFindSingleUserByName_OK() { Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.IsAny())) .ReturnsAsync( new List { new AppUser { EmployeeId = "1" } }); var res = await _userService.TryFindSingleUserByName(new UserNameSearchRequest()); Mock.Get(_userRepository).Verify(x => x.SearchUsersAsync(It.IsAny()), Times.Once); Assert.NotNull(res); Assert.AreEqual("1", res.EmployeeId); } [Test] public void TryFindSingleUserByName_ExceptsWhenMultiple() { Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.IsAny())) .ReturnsAsync( new List { new AppUser { EmployeeId = "1" }, new AppUser { EmployeeId = "2" } }); Assert.ThrowsAsync(async () => await _userService.TryFindSingleUserByName(new UserNameSearchRequest())); } [Test] public async Task TryFindSingleUserByName_TriesTwice() { Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.MiddleInit) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) ))) .ReturnsAsync(new List()); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List { new AppUser { EmployeeId = "1" } }); var res = await _userService.TryFindSingleUserByName(new UserNameSearchRequest { FirstName = "John", LastName = "Smith", DnaOrgNbr = "5", MiddleInit = "D" }); Mock.Get(_userRepository).Verify(x => x.SearchUsersAsync(It.IsAny()), Times.Exactly(2)); Assert.NotNull(res); Assert.AreEqual("1", res.EmployeeId); } [Test] public async Task TryFindSingleUserByName_TriesThrice() { Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.MiddleInit) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) ))) .ReturnsAsync(new List()); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(user => !string.IsNullOrWhiteSpace(user.FirstName) && !string.IsNullOrWhiteSpace(user.LastName) && !string.IsNullOrWhiteSpace(user.DnaOrgNbr) && string.IsNullOrWhiteSpace(user.MiddleInit) ))) .ReturnsAsync(new List()); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List { new AppUser { EmployeeId = "1" }, }); var res = await _userService.TryFindSingleUserByName(new UserNameSearchRequest { FirstName = "John", LastName = "Smith", DnaOrgNbr = "5", MiddleInit = "D" }); Mock.Get(_userRepository).Verify(x => x.SearchUsersAsync(It.IsAny()), Times.Exactly(3)); Assert.NotNull(res); Assert.AreEqual("1", res.EmployeeId); } [Test] public Task TryFindSingleUserByName_SkipsTry2IfNoMiddle_ThrowIfNotFound() { Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.MiddleInit) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) ))) .ReturnsAsync(new List()); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List()); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List()); Assert.ThrowsAsync(async () => await _userService.TryFindSingleUserByName(new UserNameSearchRequest { FirstName = "John", LastName = "Smith", DnaOrgNbr = "5", })); Mock.Get(_userRepository).Verify(x => x.SearchUsersAsync(It.IsAny()), Times.Exactly(2)); return Task.CompletedTask; } [Test] public async Task TryFindSingleUserByName_SkipsTry3IfFound() { Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.MiddleInit) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) ))) .ReturnsAsync(new List()); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List { new AppUser { EmployeeId = "1" } }); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List()); var res = await _userService.TryFindSingleUserByName(new UserNameSearchRequest { FirstName = "John", LastName = "Smith", DnaOrgNbr = "5", MiddleInit = "D" }); Mock.Get(_userRepository).Verify(x => x.SearchUsersAsync(It.IsAny()), Times.Exactly(2)); Assert.NotNull(res); Assert.AreEqual("1", res.EmployeeId); } [Test] public Task TryFindSingleUserByName_SkipsTry3AndThrowsIfMultipleFound() { Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.MiddleInit) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) ))) .ReturnsAsync(new List()); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List { new AppUser { EmployeeId = "1" }, new AppUser { EmployeeId = "3" } }); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List()); Assert.ThrowsAsync(async () => await _userService.TryFindSingleUserByName(new UserNameSearchRequest { FirstName = "John", LastName = "Smith", DnaOrgNbr = "5", MiddleInit = "D" })); return Task.CompletedTask; } [Test] public Task TryFindSingleUserByName_Exception() { Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.MiddleInit) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) ))) .ReturnsAsync(new List()); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && !string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ThrowsAsync(new Exception("OOf")); Mock.Get(_userRepository) .Setup(x => x.SearchUsersAsync(It.Is(x => !string.IsNullOrWhiteSpace(x.FirstName) && !string.IsNullOrWhiteSpace(x.LastName) && string.IsNullOrWhiteSpace(x.DnaOrgNbr) && string.IsNullOrWhiteSpace(x.MiddleInit) ))) .ReturnsAsync(new List()); Assert.ThrowsAsync(async () => await _userService.TryFindSingleUserByName(new UserNameSearchRequest { FirstName = "John", LastName = "Smith", DnaOrgNbr = "5", MiddleInit = "D" })); return Task.CompletedTask; } [Test] public async Task FindDepartmentManagers_Ok() { var bm = new AppUser { AdEmail = "bm@landmarkcu.com", Departments = new List { new UserDepartment { Role = Role.BM, DepartmentId = 1 } } }; var teller = new AppUser { AdEmail = "teller@landmarkcu.com", Departments = new List { new UserDepartment { Role = Role.Teller, DepartmentId = 1 } } }; var bom = new AppUser { AdEmail = "bom@landmarkcu.com", Departments = new List { new UserDepartment { Role = Role.BOM, DepartmentId = 1 } } }; var abm = new AppUser { AdEmail = "abm@landmarkcu.com", Departments = new List { new UserDepartment { Role = Role.ABM, DepartmentId = 1 } } }; var manager = new AppUser { AdEmail = "manager@landmarkcu.com", Departments = new List { new UserDepartment { Role = Role.Manager, DepartmentId = 1 } } }; var managerOtherDepartment = new AppUser { AdEmail = "manager@landmarkcu.com", Departments = new List { new UserDepartment { Role = Role.Manager, DepartmentId = 2 } } }; var usersFromRepo = new List { bm, teller, bom, abm, manager, managerOtherDepartment }; Mock.Get(_departmentRepository) .Setup(x => x.FindDepartmentAssignments(It.IsAny())) .ReturnsAsync(usersFromRepo); var result = await _userService.FindDepartmentManagers(1); Assert.AreEqual(4, result.Count); Assert.True(result.Any(x => x.AdEmail.Equals("bm@landmarkcu.com"))); Assert.True(result.Any(x => x.AdEmail.Equals("manager@landmarkcu.com"))); Assert.True(result.Any(x => x.AdEmail.Equals("bom@landmarkcu.com"))); Assert.True(result.Any(x => x.AdEmail.Equals("abm@landmarkcu.com"))); Assert.False(result.Any(x => x.AdEmail.Equals("teller@landmarkcu.com"))); } } }