using System; using System.Collections.Generic; using System.Threading.Tasks; using LCU.API.Internal.Operations.IncentiveApiLib.Repositories; using LCU.API.Internal.Operations.IncentiveApi.Services; using LCU.API.Internal.Operations.IncentiveApi.Services.Payout; using LCU.Library.Internal.IncentiveApiModels.Entities; using Moq; using NUnit.Framework; using LCU.API.Internal.Operations.IncentiveApi.Services.Dayforce; using LCU.API.Internal.Operations.IncentiveApiLib.Services; using LCU.API.Internal.Operations.IncentiveApi.Models.Dayforce; using LCU.Library.Internal.IncentiveApiModels.Results; using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices; using LCU.API.Internal.Operations.IncentiveApi.Configuration; using LCU.Library.Internal.IncentiveApiModels.Requests; namespace Application.UnitTests.Services { public class DayForceSyncServiceTest { private IDayForceClientService _dayForceClientService; private IDayForceSyncService _dayForceSyncService; private INotificationApiService _notificationService; private IPayoutService _payoutService; private ISettingsService _settingsService; private IUnitOfWork _unitOfWork; private IUserService _userService; private DayForceConfiguration _dayForceConfig; [SetUp] public void Setup() { _dayForceClientService = Mock.Of(); _notificationService = Mock.Of(); _payoutService = Mock.Of(); _settingsService = Mock.Of(); _unitOfWork = Mock.Of(); _userService = Mock.Of(); _dayForceConfig = Mock.Of(); _dayForceConfig.DayForceActiveUserReport = "INCENTIVE_MANAGER_ACTIVE"; _dayForceConfig.DayForceTerminatedUserReport = "INCENTIVE_MANAGER_TERMINATED"; _dayForceConfig.DayForceManualReportRecipients = new List() { "user22@testing.com" }; _dayForceSyncService = new DayForceSyncService( _unitOfWork, _userService, _notificationService, _payoutService, _dayForceClientService, _settingsService, _dayForceConfig ); } [Test] public void Sync_Active_Throws() { Mock.Get(_dayForceClientService) .Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport)) .ReturnsAsync(new Report() { }); Assert.Throws(() => { _dayForceSyncService.SyncActiveDayForceUsers(new List()).GetAwaiter().GetResult(); }); Mock.Get(_dayForceClientService) .Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.Once); Mock.Get(_dayForceClientService) .Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Never); } [Test] public void Sync_Term_Throws() { Mock.Get(_dayForceClientService) .Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport)) .ReturnsAsync(new Report() { }); Assert.Throws(() => { _dayForceSyncService.SyncTerminatedDayForceUsers(new List()).GetAwaiter().GetResult(); }); Mock.Get(_dayForceClientService) .Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.Never); Mock.Get(_dayForceClientService) .Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once); } [Test] public async Task Sync_Active_Empty() { Mock.Get(_dayForceClientService) .Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceActiveUserReport, Rows = new List>() }); Mock.Get(_userService) .Setup(s => s.SyncDayForceEmployee(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "test2@test.com" } ); Mock.Get(_notificationService) .Setup(s => s.SendMissingRoleNotification(It.IsAny>(), It.IsAny>())).Verifiable(); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); await _dayForceSyncService.SyncActiveDayForceUsers(new List()); Mock.Get(_dayForceClientService) .Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never); Mock.Get(_userService).Verify(s => s.SyncDayForceEmployee(It.IsAny()), Times.Never); Mock.Get(_notificationService) .Verify(s => s.SendMissingRoleNotification(It.IsAny>(), It.IsAny>()), Times.Never); } [Test] public async Task Sync_Active_Basic() { var row1 = new Dictionary(); var row2 = new Dictionary(); row1["EmploymentStatus_ShortName"] = "Active"; row1["Employee_DisplayName"] = "Test One"; row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001"; row1["IdLibrary_LoginName"] = "testone@landmarkcu.com"; row1["OrgUnit_ShortName"] = "IT"; row1["Job_ShortName"] = "ELEPHANT"; row1["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row1["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row1["OrgUnit_LedgerCode"] = "101"; row2["EmploymentStatus_ShortName"] = "Active"; row2["Employee_DisplayName"] = "Test Two"; row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002"; row2["IdLibrary_LoginName"] = "testtwo@landmarkcu.com"; row2["OrgUnit_ShortName"] = "IT"; row2["Job_ShortName"] = "Developer"; row2["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row2["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row2["OrgUnit_LedgerCode"] = "103"; Mock.Get(_dayForceClientService) .Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceActiveUserReport, Rows = new List>() { row1, row2 } }); Mock.Get(_userService) .Setup(s => s.SyncDayForceEmployee(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "test2@test.com" } ); Mock.Get(_notificationService) .Setup(s => s.SendMissingRoleNotification(It.IsAny>(), It.IsAny>())) .Verifiable(); Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); await _dayForceSyncService.SyncActiveDayForceUsers(new List()); Mock.Get(_dayForceClientService) .Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.Once); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never); Mock.Get(_userService).Verify(s => s.SyncDayForceEmployee(It.IsAny()), Times.Exactly(2)); Mock.Get(_notificationService) .Verify(s => s.SendMissingRoleNotification(It.IsAny>(), It.IsAny>()), Times.Never); } [Test] public async Task Sync_Term_Empty() { Mock.Get(_dayForceClientService) .Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceTerminatedUserReport, Rows = new List>() }); Mock.Get(_userService) .Setup(s => s.TerminateDayForceEmployee(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "test2@test.com" } ); Mock.Get(_userService) .Setup(s => s.FindManager(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "manager@test.com" } ); Mock.Get(_payoutService) .Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny(), It.IsAny())) .ReturnsAsync( new TerminatedEmployeeReceipt( new AppUser() { AdEmail = "fired@test.com" }, new PayoutEntry(), new PayoutEntry(), new AppUser() { AdEmail = "bossy@test.com" }) ); Mock.Get(_notificationService) .Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny>(), It.IsAny>())) .Verifiable(); await _dayForceSyncService.SyncTerminatedDayForceUsers(new List()); Mock.Get(_dayForceClientService) .Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once); Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny()), Times.Never); Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny()), Times.Never); Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny(), It.IsAny()), Times.Never); Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny>(), It.IsAny>()), Times.Never); } [Test] public async Task Sync_Term_Basic() { var row1 = new Dictionary(); var row2 = new Dictionary(); row1["Employee_DisplayName"] = "Test One"; row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001"; row1["IdLibrary_LoginName"] = "testone@landmarkcu.com"; row1["OrgUnit_ShortName"] = "IT"; row1["Job_ShortName"] = "ELEPHANT"; row1["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row1["Employee_TerminationDate"] = "2021-07-01T00:00:00.000"; row2["Employee_DisplayName"] = "Test Two"; row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002"; row2["IdLibrary_LoginName"] = "testtwo@landmarkcu.com"; row2["OrgUnit_ShortName"] = "IT"; row2["Job_ShortName"] = "Developer"; row2["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row2["Employee_TerminationDate"] = "2021-07-01T00:00:00.000"; Mock.Get(_dayForceClientService) .Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceTerminatedUserReport, Rows = new List>() { row1, row2 } }); Mock.Get(_userService) .Setup(s => s.TerminateDayForceEmployee(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "test2@test.com" } ); Mock.Get(_userService) .Setup(s => s.FindManager(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "manager@test.com" } ); Mock.Get(_payoutService) .Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny(), It.IsAny())) .ReturnsAsync( new TerminatedEmployeeReceipt( new AppUser() { AdEmail = "fired@test.com" }, new PayoutEntry(), new PayoutEntry(), new AppUser() { AdEmail = "bossy@test.com" }) ); Mock.Get(_notificationService) .Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny>(), It.IsAny>())) .Verifiable(); await _dayForceSyncService.SyncTerminatedDayForceUsers(new List()); Mock.Get(_dayForceClientService) .Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once); Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny()), Times.Exactly(2)); Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny()), Times.Exactly(2)); Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny(), It.IsAny()), Times.Exactly(2)); Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny>(), It.IsAny>()), Times.Once); } [Test] public async Task DayForceSync_ManualReportRecipients_Ok() { //setup for Active Users Email var row3 = new Dictionary(); var row4 = new Dictionary(); row3["EmploymentStatus_ShortName"] = "Active"; row3["Employee_DisplayName"] = "Test One"; row3["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001"; row3["IdLibrary_LoginName"] = "testone@landmarkcu.com"; row3["OrgUnit_ShortName"] = "IT"; row3["Job_ShortName"] = "ELEPHANT"; row3["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row3["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row3["OrgUnit_LedgerCode"] = "101"; row4["EmploymentStatus_ShortName"] = "Active"; row4["Employee_DisplayName"] = "Test Two"; row4["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002"; row4["IdLibrary_LoginName"] = "testtwo@landmarkcu.com"; row4["OrgUnit_ShortName"] = "IT"; row4["Job_ShortName"] = "Developer"; row4["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row4["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row4["OrgUnit_LedgerCode"] = "103"; Mock.Get(_dayForceClientService).Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceActiveUserReport, Rows = new List>() { row3, row4 } }); Mock.Get(_userService).Setup(s => s.SyncDayForceEmployee(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "test2@test.com", Departments = new List() { new UserDepartment() { Role = Role.MISSING_ROLE } } } ); Mock.Get(_notificationService).Setup(s => s.SendMissingRoleNotification(It.IsAny>(), It.IsAny>())).Verifiable(); //Setup for Terminated Email Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var row1 = new Dictionary(); var row2 = new Dictionary(); row1["Employee_DisplayName"] = "Test One"; row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001"; row1["IdLibrary_LoginName"] = "testone@landmarkcu.com"; row1["OrgUnit_ShortName"] = "IT"; row1["Job_ShortName"] = "ELEPHANT"; row1["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row1["Employee_TerminationDate"] = "2021-07-01T00:00:00.000"; row2["Employee_DisplayName"] = "Test Two"; row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002"; row2["IdLibrary_LoginName"] = "testtwo@landmarkcu.com"; row2["OrgUnit_ShortName"] = "IT"; row2["Job_ShortName"] = "Developer"; row2["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row2["Employee_TerminationDate"] = "2021-07-01T00:00:00.000"; Mock.Get(_dayForceClientService).Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceTerminatedUserReport, Rows = new List>() { row1, row2 } }); Mock.Get(_userService).Setup(s => s.TerminateDayForceEmployee(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "test2@test.com" } ); Mock.Get(_userService).Setup(s => s.FindManager(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "manager@test.com" } ); Mock.Get(_payoutService).Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny(), It.IsAny())) .ReturnsAsync( new TerminatedEmployeeReceipt( new AppUser() { AdEmail = "user22@test.com" }, new PayoutEntry(), new PayoutEntry(), new AppUser() { AdEmail = "user44@test.com" }) ); Mock.Get(_notificationService).Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny>(), It.IsAny>())).Verifiable(); var request = new DayforceProcessRequest(); await _dayForceSyncService.SyncDayForceUsers(request); //Active Role Checks Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.AtLeastOnce); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never); Mock.Get(_userService).Verify(s => s.SyncDayForceEmployee(It.IsAny()), Times.Exactly(2)); Mock.Get(_notificationService).Verify(s => s.SendMissingRoleNotification(It.IsAny>(), It.IsAny>()), Times.Once); Mock.Equals(request.MissingRoleNotification, _dayForceConfig.DayForceManualReportRecipients); Assert.AreNotSame(request.MissingRoleNotification, "testing123@test.com"); //Terminated User Checks Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny()), Times.Exactly(2)); Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny()), Times.Exactly(2)); Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny(), It.IsAny()), Times.Exactly(2)); Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once); Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny>(), It.IsAny>()), Times.Once); } [Test] public async Task DayForceSync_RequestReportRecipients_Ok() { //setup for Active Users Email var row3 = new Dictionary(); var row4 = new Dictionary(); row3["EmploymentStatus_ShortName"] = "Active"; row3["Employee_DisplayName"] = "Test One"; row3["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001"; row3["IdLibrary_LoginName"] = "testone@landmarkcu.com"; row3["OrgUnit_ShortName"] = "IT"; row3["Job_ShortName"] = "ELEPHANT"; row3["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row3["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row3["OrgUnit_LedgerCode"] = "101"; row4["EmploymentStatus_ShortName"] = "Active"; row4["Employee_DisplayName"] = "Test Two"; row4["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002"; row4["IdLibrary_LoginName"] = "testtwo@landmarkcu.com"; row4["OrgUnit_ShortName"] = "IT"; row4["Job_ShortName"] = "Developer"; row4["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row4["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row4["OrgUnit_LedgerCode"] = "103"; Mock.Get(_dayForceClientService).Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceActiveUserReport, Rows = new List>() { row3, row4 } }); Mock.Get(_userService).Setup(s => s.SyncDayForceEmployee(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "test2@test.com", Departments = new List() { new UserDepartment() { Role = Role.MISSING_ROLE } } } ); Mock.Get(_notificationService).Setup(s => s.SendMissingRoleNotification(It.IsAny>(), It.IsAny>())).Verifiable(); //Setup for Terminated Email Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable(); var row1 = new Dictionary(); var row2 = new Dictionary(); row1["Employee_DisplayName"] = "Test One"; row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001"; row1["IdLibrary_LoginName"] = "testone@landmarkcu.com"; row1["OrgUnit_ShortName"] = "IT"; row1["Job_ShortName"] = "ELEPHANT"; row1["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row1["Employee_TerminationDate"] = "2021-07-01T00:00:00.000"; row2["Employee_DisplayName"] = "Test Two"; row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002"; row2["IdLibrary_LoginName"] = "testtwo@landmarkcu.com"; row2["OrgUnit_ShortName"] = "IT"; row2["Job_ShortName"] = "Developer"; row2["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row2["Employee_TerminationDate"] = "2021-07-01T00:00:00.000"; Mock.Get(_dayForceClientService).Setup(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceTerminatedUserReport, Rows = new List>() { row1, row2 } }); Mock.Get(_userService).Setup(s => s.TerminateDayForceEmployee(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "test2@test.com" } ); Mock.Get(_userService).Setup(s => s.FindManager(It.IsAny())) .ReturnsAsync( new AppUser() { AdEmail = "manager@test.com" } ); Mock.Get(_payoutService).Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny(), It.IsAny())) .ReturnsAsync( new TerminatedEmployeeReceipt( new AppUser() { AdEmail = "user22@test.com" }, new PayoutEntry(), new PayoutEntry(), new AppUser() { AdEmail = "user44@test.com" }) ); Mock.Get(_notificationService).Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny>(), It.IsAny>())).Verifiable(); var request = new DayforceProcessRequest(); request.MissingRoleNotification = new List() { "testing123@test.com" }; await _dayForceSyncService.SyncDayForceUsers(request); //Active Role Checks Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport), Times.AtLeastOnce); Mock.Get(_unitOfWork).Verify(s => s.CompleteAsync(), Times.Never); Mock.Get(_userService).Verify(s => s.SyncDayForceEmployee(It.IsAny()), Times.Exactly(2)); Mock.Get(_notificationService).Verify(s => s.SendMissingRoleNotification(It.IsAny>(), It.IsAny>()), Times.Once); Mock.Equals(request.MissingRoleNotification, "testing123@test.com"); Assert.AreNotEqual(request.MissingRoleNotification, _dayForceConfig.DayForceManualReportRecipients); //Terminated User Checks Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny()), Times.Exactly(2)); Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny()), Times.Exactly(2)); Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny(), It.IsAny()), Times.Exactly(2)); Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once); Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny>(), It.IsAny>()), Times.Once); } [Test] public async Task GetMatchingHcmUsersReturnsEmptyListOnEmptySearch() { var result = await _dayForceSyncService.GetMatchingHcmUsers(); Assert.IsEmpty(result); } [Test] public async Task EmployeeDetailsUpdateInitializesWithNullAppUserAndSuccessSetToFalse() { var result = new EmployeeDetailsUpdateResult(); Assert.IsNull(result.AppUser); Assert.IsFalse(result.UpdatedSuccessfully); } [Test] public async Task EmployeeDetailsUpdateFailsWhenNewAndOldDetailsMatch() { var updateRequest = new EmployeeDetailsUpdate { OldEmail = "TESTTESTERSON@LANDMARKCU.COM", OldEmployeeId = "12345", OldFullName = "TESTERSON, TEST", NewEmail = "TESTTESTERSON@LANDMARKCU.COM", NewEmployeeId = "12345", NewFullName = "TESTERSON, TEST" }; Mock.Get(_userService) .Setup(s => s.GetUserByAdEmailAsync("TESTTESTERSON@LANDMARKCU.COM")) .ReturnsAsync(new AppUser { AdEmail = "TESTTESTERSON@LANDMARKCU.COM", Id = Guid.NewGuid(), EmployeeId = "12345", FullName = "TESTERSON, TEST" } ); var result = await _dayForceSyncService.UpdateEmployeeDetails(updateRequest); Assert.IsNotNull(result); Assert.IsNotNull(result.AppUser); Assert.IsFalse(result.UpdatedSuccessfully); } [Test] public async Task EmployeeDetailsUpdateFailsWhenNoAppUserFound() { var updateRequest = new EmployeeDetailsUpdate { OldEmail = "TESTTESTERSON@LANDMARKCU.COM", OldEmployeeId = "12345", OldFullName = "TESTERSON, TEST", NewEmail = "TESTTESTERSON@LANDMARKCU.COM", NewEmployeeId = "12345", NewFullName = "TESTERSON, TEST" }; var result = await _dayForceSyncService.UpdateEmployeeDetails(updateRequest); Assert.IsNotNull(result); Assert.IsNull(result.AppUser); Assert.IsFalse(result.UpdatedSuccessfully); } [Test] public async Task EmployeeDetailsUpdateFailsWhenNoHcmUserFound() { var updateRequest = new EmployeeDetailsUpdate { OldEmail = "TESTTESTERSON@LANDMARKCU.COM", OldEmployeeId = "12345", OldFullName = "TESTERSON, TEST", NewEmail = "NEWTESTTESTERSON@LANDMARKCU.COM", NewEmployeeId = "12345", NewFullName = "TESTERSON, TEST" }; Mock.Get(_userService) .Setup(s => s.GetUserByAdEmailAsync("TESTTESTERSON@LANDMARKCU.COM")) .ReturnsAsync(new AppUser { AdEmail = "TESTTESTERSON@LANDMARKCU.COM", Id = Guid.NewGuid(), EmployeeId = "12345", FullName = "TESTERSON, TEST" } ); var row1 = new Dictionary(); var row2 = new Dictionary(); row1["EmploymentStatus_ShortName"] = "Active"; row1["Employee_DisplayName"] = "Test One"; row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001"; row1["IdLibrary_LoginName"] = "testone@landmarkcu.com"; row1["OrgUnit_ShortName"] = "IT"; row1["Job_ShortName"] = "ELEPHANT"; row1["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row1["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row1["OrgUnit_LedgerCode"] = "101"; row2["EmploymentStatus_ShortName"] = "Active"; row2["Employee_DisplayName"] = "Test Two"; row2["EmployeeEmploymentStatus_EmployeeNumber"] = "C0002"; row2["IdLibrary_LoginName"] = "testtwo@landmarkcu.com"; row2["OrgUnit_ShortName"] = "IT"; row2["Job_ShortName"] = "Developer"; row2["EmployeeManager_ManagerEmployeeNumber"] = "11771"; row2["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row2["OrgUnit_LedgerCode"] = "103"; Mock.Get(_dayForceClientService) .Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceActiveUserReport, Rows = new List>() { row1, row2 } }); var result = await _dayForceSyncService.UpdateEmployeeDetails(updateRequest); Assert.IsNotNull(result); Assert.IsNotNull(result.AppUser); Assert.IsFalse(result.UpdatedSuccessfully); } [Test] public async Task EmployeeDetailsUpdateSucceedsWhenOneHcmUserFound() { var updateRequest = new EmployeeDetailsUpdate { OldEmail = "TESTTESTERSON@LANDMARKCU.COM", OldEmployeeId = "12345", OldFullName = "TESTERSON, TEST", NewEmail = "NEWTESTTESTERSON@LANDMARKCU.COM", NewEmployeeId = "12345", NewFullName = "TESTERSON, TEST" }; Mock.Get(_userService) .Setup(s => s.GetUserByAdEmailAsync("TESTTESTERSON@LANDMARKCU.COM")) .ReturnsAsync(new AppUser { AdEmail = "TESTTESTERSON@LANDMARKCU.COM", Id = Guid.NewGuid(), EmployeeId = "12345", FullName = "TESTERSON, TEST" } ); var row1 = new Dictionary(); var row2 = new Dictionary(); row1["EmploymentStatus_ShortName"] = "Active"; row1["Employee_DisplayName"] = updateRequest.NewFullName; row1["EmployeeEmploymentStatus_EmployeeNumber"] = updateRequest.NewEmployeeId; row1["IdLibrary_LoginName"] = updateRequest.NewEmail; row1["OrgUnit_ShortName"] = "IT"; row1["Job_ShortName"] = "ELEPHANT"; row1["EmployeeManager_ManagerEmployeeNumber"] = "11111"; row1["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row1["OrgUnit_LedgerCode"] = "101"; row2["EmploymentStatus_ShortName"] = "Active"; row2["Employee_DisplayName"] = "Test Two"; row2["EmployeeEmploymentStatus_EmployeeNumber"] = "98765"; row2["IdLibrary_LoginName"] = "testtwo@landmarkcu.com"; row2["OrgUnit_ShortName"] = "IT"; row2["Job_ShortName"] = "Developer"; row2["EmployeeManager_ManagerEmployeeNumber"] = "11111"; row2["Employee_HireDate"] = "2021-07-01T00:00:00.000"; row2["OrgUnit_LedgerCode"] = "103"; Mock.Get(_dayForceClientService) .Setup(s => s.GetReportData(_dayForceConfig.DayForceActiveUserReport)) .ReturnsAsync(new Report() { XRefCode = _dayForceConfig.DayForceActiveUserReport, Rows = new List>() { row1, row2 } }); Mock.Get(_userService) .Setup(s => s.UpdateEmployeeDetails(updateRequest)) .ReturnsAsync(new EmployeeDetailsUpdateResult{ AppUser = new AppUser { AdEmail = updateRequest.NewEmail, Id = Guid.NewGuid(), EmployeeId = updateRequest.NewEmployeeId, FullName = updateRequest.NewFullName }, UpdateMessage = "Employee Details Update Succeeded", UpdatedSuccessfully = true } ); var result = await _dayForceSyncService.UpdateEmployeeDetails(updateRequest); Assert.IsNotNull(result); Assert.IsNotNull(result.AppUser); Assert.AreEqual(result.AppUser.AdEmail, updateRequest.NewEmail); Assert.AreEqual(result.AppUser.EmployeeId, updateRequest.NewEmployeeId); Assert.AreEqual(result.AppUser.FullName, updateRequest.NewFullName); Assert.IsTrue(result.UpdatedSuccessfully); } } }