Adding
This commit is contained in:
+174
@@ -0,0 +1,174 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Authorization;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Application.UnitTests.Authorization
|
||||
{
|
||||
public class WrappedPermissionAuthorizationHandler : PermissionAuthorizationHandler
|
||||
{
|
||||
public WrappedPermissionAuthorizationHandler(ICurrentUserService currentUserService, IUserService userService)
|
||||
: base(currentUserService, userService)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task WrappedHandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement)
|
||||
{
|
||||
await HandleRequirementAsync(context, requirement);
|
||||
}
|
||||
}
|
||||
|
||||
public class PermissionAuthorizationHandlerTest
|
||||
{
|
||||
private WrappedPermissionAuthorizationHandler _handler;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_handler = new WrappedPermissionAuthorizationHandler(_mockCurrentUserService.Object,
|
||||
_mockUserService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleAsync_MatchingPermission_ContextHasSucceeded()
|
||||
{
|
||||
var appUser = new ApplicationUser { Email = "[email protected]" };
|
||||
var user = new AppUser {
|
||||
Role = Role.OpsHelpDesk,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Role = Role.OpsHelpDesk
|
||||
}
|
||||
}
|
||||
};
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(appUser);
|
||||
|
||||
_mockUserService.Setup(service => service.UserHasAnyRequiredPermission(appUser.Email, It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(true);
|
||||
|
||||
var requirement = new PermissionRequirement("VIEW_DASHBOARD");
|
||||
var requirements = new List<IAuthorizationRequirement> { requirement };
|
||||
|
||||
var _fakeContext = new AuthorizationHandlerContext(requirements, null, null);
|
||||
|
||||
await _handler.WrappedHandleRequirementAsync(_fakeContext, requirement);
|
||||
|
||||
Assert.True(_fakeContext.HasSucceeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleAsync_MatchingAdditionalPermission_ContextHasSucceeded()
|
||||
{
|
||||
var appUser = new ApplicationUser { Email = "[email protected]" };
|
||||
var user = new AppUser {
|
||||
Role = Role.OpsHelpDesk,
|
||||
AdditionalPermissions = new List<UserPermission>()
|
||||
{
|
||||
new UserPermission()
|
||||
{
|
||||
Permission = Permission.ViewDashboard
|
||||
}
|
||||
}
|
||||
};
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(appUser);
|
||||
|
||||
_mockUserService.Setup(service => service.UserHasAnyRequiredPermission(appUser.Email, It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(true);
|
||||
|
||||
var requirement = new PermissionRequirement("VIEW_DASHBOARD");
|
||||
var requirements = new List<IAuthorizationRequirement> { requirement };
|
||||
|
||||
var _fakeContext = new AuthorizationHandlerContext(requirements, null, null);
|
||||
|
||||
await _handler.WrappedHandleRequirementAsync(_fakeContext, requirement);
|
||||
|
||||
Assert.True(_fakeContext.HasSucceeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleAsync_NoMatchingPermission_ContextHasFailed()
|
||||
{
|
||||
var appUser = new ApplicationUser { Email = "[email protected]" };
|
||||
var user = new AppUser
|
||||
{
|
||||
Role = Role.OpsHelpDesk
|
||||
};
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(appUser);
|
||||
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(appUser.Email))
|
||||
.ReturnsAsync(user);
|
||||
|
||||
var requirement = new PermissionRequirement("NO_MATCH");
|
||||
var requirements = new List<IAuthorizationRequirement> { requirement };
|
||||
var _fakeContext = new AuthorizationHandlerContext(requirements, null, null);
|
||||
|
||||
await _handler.WrappedHandleRequirementAsync(_fakeContext, requirement);
|
||||
|
||||
Assert.True(_fakeContext.HasFailed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleAsync_NoApplicationUserEmail_ContextHasFailed()
|
||||
{
|
||||
var appUser = new ApplicationUser();
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(appUser);
|
||||
var requirement = new PermissionRequirement("");
|
||||
var requirements = new List<IAuthorizationRequirement> { requirement };
|
||||
var _fakeContext = new AuthorizationHandlerContext(requirements, null, null);
|
||||
|
||||
await _handler.WrappedHandleRequirementAsync(_fakeContext, requirement);
|
||||
|
||||
Assert.True(_fakeContext.HasFailed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleAsync_NoUserFound_ContextHasFailed()
|
||||
{
|
||||
var appUser = new ApplicationUser { Email = "[email protected]" };
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(appUser);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(appUser.Email))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
var requirement = new PermissionRequirement("");
|
||||
var requirements = new List<IAuthorizationRequirement> { requirement };
|
||||
var _fakeContext = new AuthorizationHandlerContext(requirements, null, null);
|
||||
|
||||
await _handler.WrappedHandleRequirementAsync(_fakeContext, requirement);
|
||||
|
||||
Assert.True(_fakeContext.HasFailed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleAsync_UserServiceException_ContextHasFailed()
|
||||
{
|
||||
var appUser = new ApplicationUser { Email = "[email protected]" };
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(appUser);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(appUser.Email))
|
||||
.ThrowsAsync(new System.Exception("err"));
|
||||
var requirement = new PermissionRequirement("");
|
||||
var requirements = new List<IAuthorizationRequirement> { requirement };
|
||||
var _fakeContext = new AuthorizationHandlerContext(requirements, null, null);
|
||||
|
||||
await _handler.WrappedHandleRequirementAsync(_fakeContext, requirement);
|
||||
|
||||
Assert.True(_fakeContext.HasFailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Authorization;
|
||||
|
||||
namespace Application.UnitTests.Authorization
|
||||
{
|
||||
public class PermissionPolicyProviderTest
|
||||
{
|
||||
private PermissionPolicyProvider _provider;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var options = Options.Create(new AuthorizationOptions());
|
||||
_provider = new PermissionPolicyProvider(options);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetPolicyAsync_GivenPolicyName_ReturnsPermissionsPolicy()
|
||||
{
|
||||
var result = await _provider.GetPolicyAsync("Permission");
|
||||
|
||||
Assert.IsInstanceOf<PermissionRequirement>(result.Requirements.First());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetPolicyAsync_GivenParameters_PolicyWithPermissions()
|
||||
{
|
||||
var result = await _provider.GetPolicyAsync("Permissionp1,p2");
|
||||
|
||||
var requirement = result.Requirements.First() as PermissionRequirement;
|
||||
Assert.AreEqual("p1,p2", requirement.Permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Configuration
|
||||
{
|
||||
public class FileOperationsApiConfigurationTest
|
||||
{
|
||||
[Test]
|
||||
public void GetFileContentEndpoint_ValidUri()
|
||||
{
|
||||
var fileOperationsApiConfiguration = new FileOperationsApiConfiguration()
|
||||
{
|
||||
Url = "https://test/",
|
||||
GetFileContentEndpoint = "test"
|
||||
};
|
||||
|
||||
var result = fileOperationsApiConfiguration.GetFileContentUri;
|
||||
|
||||
Assert.NotNull(result);
|
||||
var testUri = new Uri("https://test/test");
|
||||
Assert.AreEqual(testUri, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
+786
@@ -0,0 +1,786 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.AutoDecision;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class ActivityControllerTest
|
||||
{
|
||||
private ActivityController _controller;
|
||||
private Mock<IActivityService> _mockActivityService;
|
||||
private Mock<IActivityDetailService> _mockActivityDetailService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
private Mock<IDashboardService> _mockDashboardService;
|
||||
private Mock<IActivityDecisionService> _mockActivityDecisionService;
|
||||
private Mock<IEStatementService> _mockEStatementService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockActivityService = new Mock<IActivityService>();
|
||||
_mockActivityDetailService = new Mock<IActivityDetailService>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_mockDashboardService = new Mock<IDashboardService>();
|
||||
_mockActivityDecisionService = new Mock<IActivityDecisionService>();
|
||||
_mockEStatementService = new Mock<IEStatementService>();
|
||||
_controller = new ActivityController(_mockActivityService.Object, _mockActivityDetailService.Object, _mockUserService.Object,
|
||||
_mockCurrentUserService.Object, _mockDashboardService.Object, _mockActivityDecisionService.Object, _mockEStatementService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
var filter = new ActivityFilter()
|
||||
{
|
||||
Limit = 999,
|
||||
Page = 1
|
||||
};
|
||||
var results = new PagedResult<Activity>();
|
||||
results.Items = new List<Activity>()
|
||||
{
|
||||
new Activity()
|
||||
{
|
||||
Id = 1
|
||||
}
|
||||
};
|
||||
results.Total = 1;
|
||||
|
||||
_mockActivityService
|
||||
.Setup(service => service.ListByFilterAsync(filter)).ReturnsAsync(results);
|
||||
var result = await _controller.Get(filter);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task POST_OK()
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
State = ActivityState.Created,
|
||||
EmployeeId = "55",
|
||||
DepartmentId = 55,
|
||||
SourceId = "444",
|
||||
SourceSystem = SystemType.Dna
|
||||
};
|
||||
_mockActivityService
|
||||
.Setup(service => service.SaveActivityAsync(activity)).ReturnsAsync(1);
|
||||
|
||||
var result = await _controller.CreateActivity(activity);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_CurrentUserActivity_OK()
|
||||
{
|
||||
var user1 = new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
FirstName = "Test",
|
||||
LastName = "McTester"
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
var goals = new EmployeeProgress(user, range, new List<IPayoutRule>());
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
|
||||
_mockDashboardService
|
||||
.Setup(service => service.GetEmployeeProgressForMonthRangeAsync(goals.Employee, range))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _controller.GetCurrentUserProgress(range.FromMonth, range.FromYear, range.ToMonth, range.ToYear);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_CurrentUserDepartmentProgress_OK()
|
||||
{
|
||||
var user1 = new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
FirstName = "Test",
|
||||
LastName = "McTester"
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment> {
|
||||
new UserDepartment {
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 7, 1),
|
||||
EndDate = new DateTime(2021, 7, 31)
|
||||
}
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
var goals = new List<DepartmentProgress> { new DepartmentProgress(1, range) };
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
|
||||
_mockActivityService
|
||||
.Setup(service => service.GetDepartmentActivityForMonthRangeAsync(user.Departments, range))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _controller.GetCurrentUserProgress(range.FromMonth, range.FromYear, range.ToMonth, range.ToYear);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_CurrentUserRegionProgress_OK()
|
||||
{
|
||||
var user1 = new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
FirstName = "Test",
|
||||
LastName = "McTester"
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.RegionalManager,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment> {
|
||||
new UserDepartment {
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 7, 1),
|
||||
EndDate = new DateTime(2021, 7, 31),
|
||||
Role = Role.RegionalManager,
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Dept 1",
|
||||
RegionCode = Region.North.Code
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
var progress = new RegionProgress(Region.North, range);
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
|
||||
_mockDashboardService
|
||||
.Setup(service => service.GetRegionProgressForMonthRangeAsync(Region.North, range))
|
||||
.ReturnsAsync(progress);
|
||||
|
||||
var result = await _controller.GetRegionProgress(range.FromMonth, range.FromYear, range.ToMonth, range.ToYear, Region.East.Code);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivityStateChanges_OK()
|
||||
{
|
||||
_mockActivityService
|
||||
.Setup(service => service.GetActivityStateChanges(It.IsAny<int>())).ReturnsAsync(
|
||||
new List<ActivityStateChange>()
|
||||
{
|
||||
new ActivityStateChange()
|
||||
{
|
||||
Id = 1,
|
||||
ActivityId = 5
|
||||
},
|
||||
new ActivityStateChange()
|
||||
{
|
||||
Id = 2,
|
||||
ActivityId = 5
|
||||
},
|
||||
new ActivityStateChange()
|
||||
{
|
||||
Id = 3,
|
||||
ActivityId = 5
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.GetActivityStateChanges(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
|
||||
|
||||
var value = okResult.Value as IReadOnlyCollection<ActivityStateChange>;
|
||||
Assert.NotNull(value);
|
||||
Assert.AreEqual(3, value.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivityStateChanges_Exception()
|
||||
{
|
||||
_mockActivityService.Setup(x => x.GetActivityStateChanges(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("oops"));
|
||||
|
||||
var result = await _controller.GetActivityStateChanges(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Ok()
|
||||
{
|
||||
|
||||
_mockActivityService.Setup(x => x.GetActivity(5))
|
||||
.ReturnsAsync(new Activity()
|
||||
{
|
||||
Id = 5,
|
||||
});
|
||||
|
||||
var result = await _controller.Get(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
|
||||
|
||||
var value = okResult.Value as Activity;
|
||||
Assert.NotNull(value);
|
||||
Assert.AreEqual(5, value.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_NotFound()
|
||||
{
|
||||
_mockActivityService.Setup(x => x.GetActivity(1))
|
||||
.ThrowsAsync(new NotFoundException("Not Found"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Activity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Exception()
|
||||
{
|
||||
_mockActivityService.Setup(x => x.GetActivity(1))
|
||||
.ThrowsAsync(new Exception("Internal Server Error"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_Ok()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange));
|
||||
_mockActivityService.Setup(mock => mock.ApplyStateChange(stateChange,true))
|
||||
.ReturnsAsync(activityResult);
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_AppUserNotFound()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns((ApplicationUser)null);
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
Assert.AreEqual("No AD User Found.", unauthorizedResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_UserNotFound()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
Assert.AreEqual("No AD User Found.", unauthorizedResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_BadActivityStateChangeException()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange))
|
||||
.ThrowsAsync(new BadActivityStateChangeException("Bad activity state change."));
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Bad activity state change.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_NotAuthorizedException()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange))
|
||||
.ThrowsAsync(new NotAuthorizedException("Not Authorized."));
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var objectResult = result as ObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(403, objectResult.StatusCode);
|
||||
Assert.AreEqual("Not Authorized.", objectResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_NotFoundException()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange))
|
||||
.ThrowsAsync(new NotFoundException("Activity Not Found."));
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Activity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_Exception()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange))
|
||||
.ThrowsAsync(new Exception("Internal Server Error."));
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RequestTransfer_Ok()
|
||||
{
|
||||
var request = new ActivityTransferRequest
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewDepartmentId = 2,
|
||||
NewEmployeeId = "C0000"
|
||||
};
|
||||
|
||||
var response = new ActivityTransferAction
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewActivity = new Activity
|
||||
{
|
||||
Product = Product.CreditCard,
|
||||
Type = ActivityType.Referral,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
Activity = new Activity
|
||||
{
|
||||
Product = Product.CreditCard,
|
||||
Type = ActivityType.Referral,
|
||||
},
|
||||
AccountNumber = "1234567890"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockActivityService.Setup(mock => mock.RequestTransfer(request)).ReturnsAsync(response).Verifiable();
|
||||
|
||||
var result = await _controller.RequestTransfer(request);
|
||||
|
||||
_mockActivityService.Verify();
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
var activityTransfer = okResult.Value as ActivityTransferAction;
|
||||
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual("XXXXXX7890", activityTransfer.NewActivity.Detail.AccountNumber);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RequestTransfer_NotFoundException()
|
||||
{
|
||||
var request = new ActivityTransferRequest
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewDepartmentId = 2,
|
||||
NewEmployeeId = "C0000"
|
||||
};
|
||||
_mockActivityService.Setup(mock => mock.RequestTransfer(It.IsAny<ActivityTransferRequest>()))
|
||||
.ThrowsAsync(new NotFoundException(""));
|
||||
|
||||
var result = await _controller.RequestTransfer(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Activity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RequestTransfer_BadActivityTransferRequestException()
|
||||
{
|
||||
var request = new ActivityTransferRequest
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewDepartmentId = 2,
|
||||
NewEmployeeId = "C0000"
|
||||
};
|
||||
_mockActivityService.Setup(mock => mock.RequestTransfer(It.IsAny<ActivityTransferRequest>()))
|
||||
.ThrowsAsync(new BadActivityTransferActionException("Cannot complete request."));
|
||||
|
||||
var result = await _controller.RequestTransfer(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Cannot complete request.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RequestTransfer_Exception()
|
||||
{
|
||||
var request = new ActivityTransferRequest
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewDepartmentId = 2,
|
||||
NewEmployeeId = "C0000"
|
||||
};
|
||||
_mockActivityService.Setup(mock => mock.RequestTransfer(It.IsAny<ActivityTransferRequest>()))
|
||||
.ThrowsAsync(new Exception("Internal Server Error."));
|
||||
|
||||
var result = await _controller.RequestTransfer(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_Ok()
|
||||
{
|
||||
var approval = new ActivityTransferApprovalRequest
|
||||
{
|
||||
Id = 1,
|
||||
ApprovalState = ActivityTransferState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ApproveTransfer(It.IsAny<AppUser>(), approval))
|
||||
.ReturnsAsync(new ActivityTransferAction { Id = 1 } );
|
||||
|
||||
var result = await _controller.ApproveTransfer(approval);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_AppUserNotFound()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns((ApplicationUser)null);
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
Assert.AreEqual("No AD User Found.", unauthorizedResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_UserNotFound()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
Assert.AreEqual("No AD User Found.", unauthorizedResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_NotFoundException()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService
|
||||
.Setup(mock => mock.ApproveTransfer(It.IsAny<AppUser>(), It.IsAny<ActivityTransferApprovalRequest>()))
|
||||
.ThrowsAsync(new NotFoundException(""));
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Activity Transfer Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_BadActivityTransferActionException()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService
|
||||
.Setup(mock => mock.ApproveTransfer(It.IsAny<AppUser>(), It.IsAny<ActivityTransferApprovalRequest>()))
|
||||
.ThrowsAsync(new BadActivityTransferActionException("Cannot complete request."));
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Cannot complete request.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_Exception()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService
|
||||
.Setup(mock => mock.ApproveTransfer(It.IsAny<AppUser>(), It.IsAny<ActivityTransferApprovalRequest>()))
|
||||
.ThrowsAsync(new Exception("Internal Server Error."));
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTransferAction_Ok()
|
||||
{
|
||||
var actionFromService = new ActivityTransferAction
|
||||
{
|
||||
Id = 1,
|
||||
State = ActivityTransferState.Requested
|
||||
};
|
||||
_mockActivityService.Setup(mock => mock.GetRequestedTransfer(1))
|
||||
.ReturnsAsync(actionFromService);
|
||||
|
||||
var result = await _controller.GetTransferAction(1);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTransferAction_Exception()
|
||||
{
|
||||
_mockActivityService.Setup(mock => mock.GetRequestedTransfer(1))
|
||||
.ThrowsAsync(new Exception("Internal Server Error."));
|
||||
|
||||
var result = await _controller.GetTransferAction(1);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.QueueServices;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class ActivityImportControllerTest
|
||||
{
|
||||
private ActivityImportController _controller;
|
||||
private Mock<IQueueCreditCardImportService> _mockQueueCreditCardImportService;
|
||||
private Mock<IQueueIndirectVehicleImportService> _mockQueueVehicleImportService;
|
||||
private Mock<IQueueAlliedGapMbpService> _mockQueueAlliedGapMbpService;
|
||||
private Mock<IQueueActionCreditCardService> _mockQueueActionCreditCardService;
|
||||
private Mock<IQueueActionVehicleService> _mockQueueActionVehicleService;
|
||||
private Mock<IEStatementService> _mockEStatementService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockQueueCreditCardImportService = new Mock<IQueueCreditCardImportService>();
|
||||
_mockQueueVehicleImportService = new Mock<IQueueIndirectVehicleImportService>();
|
||||
_mockQueueActionVehicleService = new Mock<IQueueActionVehicleService>();
|
||||
_mockQueueActionCreditCardService = new Mock<IQueueActionCreditCardService>();
|
||||
_mockQueueAlliedGapMbpService = new Mock<IQueueAlliedGapMbpService>();
|
||||
_controller = new ActivityImportController(_mockQueueCreditCardImportService.Object, _mockQueueVehicleImportService.Object,
|
||||
_mockQueueActionCreditCardService.Object,
|
||||
_mockQueueActionVehicleService.Object, _mockQueueAlliedGapMbpService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueCreditCardImportRequest_Accepted()
|
||||
{
|
||||
_mockQueueCreditCardImportService.Setup(x => x.QueueCreditCardSalesImport(It.IsAny<ImportCreditCardSalesRequest>()));
|
||||
|
||||
var result = await _controller.QueueCreditCardImportRequest(It.IsAny<ImportCreditCardSalesRequest>());
|
||||
|
||||
var acceptedResult = result as AcceptedResult;
|
||||
Assert.NotNull(acceptedResult);
|
||||
Assert.AreEqual(202, acceptedResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueCreditCardImportRequest_ServiceFails_ServiceException()
|
||||
{
|
||||
_mockQueueCreditCardImportService.Setup(x => x.QueueCreditCardSalesImport(It.IsAny<ImportCreditCardSalesRequest>()))
|
||||
.ThrowsAsync(new ServiceException("Failure"));
|
||||
|
||||
var result = await _controller.QueueCreditCardImportRequest(It.IsAny<ImportCreditCardSalesRequest>());
|
||||
|
||||
var objectResult = result as ObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(500, objectResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueCreditCardImportRequest_ServiceFails_Exception()
|
||||
{
|
||||
_mockQueueCreditCardImportService.Setup(x => x.QueueCreditCardSalesImport(It.IsAny<ImportCreditCardSalesRequest>()))
|
||||
.ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var result = await _controller.QueueCreditCardImportRequest(It.IsAny<ImportCreditCardSalesRequest>());
|
||||
|
||||
var objectResult = result as StatusCodeResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(500, objectResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueIndirectVehicleImportRequest_Accepted()
|
||||
{
|
||||
_mockQueueVehicleImportService.Setup(x => x.QueueIndirectVehicleSalesImport(It.IsAny<ImportIndirectVehicleSalesRequest>()));
|
||||
|
||||
var result = await _controller.QueueIndirectVehicleImportRequest(It.IsAny<ImportIndirectVehicleSalesRequest>());
|
||||
|
||||
var acceptedResult = result as AcceptedResult;
|
||||
Assert.NotNull(acceptedResult);
|
||||
Assert.AreEqual(202, acceptedResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueIndirectVehicleImportRequest_ServiceFails_ServiceException()
|
||||
{
|
||||
_mockQueueVehicleImportService.Setup(x => x.QueueIndirectVehicleSalesImport(It.IsAny<ImportIndirectVehicleSalesRequest>()))
|
||||
.ThrowsAsync(new ServiceException("Failure"));
|
||||
|
||||
var result = await _controller.QueueIndirectVehicleImportRequest(It.IsAny<ImportIndirectVehicleSalesRequest>());
|
||||
|
||||
var objectResult = result as ObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(500, objectResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueeIndirectVehicleImportRequest_ServiceFails_Exception()
|
||||
{
|
||||
_mockQueueVehicleImportService.Setup(x => x.QueueIndirectVehicleSalesImport(It.IsAny<ImportIndirectVehicleSalesRequest>()))
|
||||
.ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var result = await _controller.QueueIndirectVehicleImportRequest(It.IsAny<ImportIndirectVehicleSalesRequest>());
|
||||
|
||||
var objectResult = result as StatusCodeResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(500, objectResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class CommissionControllerTest
|
||||
{
|
||||
private CommissionController _controller;
|
||||
private Mock<ICommissionService> _mockCommissionService;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCommissionService = new Mock<ICommissionService>();
|
||||
_controller = new CommissionController(_mockCommissionService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
_mockCommissionService.Setup(mock => mock.GetCommissionsAsync())
|
||||
.ReturnsAsync(new List<Commission>
|
||||
{
|
||||
new Commission()
|
||||
});
|
||||
|
||||
var result = await _controller.Get();
|
||||
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_ServiceException_Returns500()
|
||||
{
|
||||
_mockCommissionService.Setup(mock => mock.GetCommissionsAsync())
|
||||
.ThrowsAsync(new Exception("error thrown"));
|
||||
|
||||
var result = await _controller.Get();
|
||||
|
||||
Assert.NotNull(result);
|
||||
var errorResult = result as StatusCodeResult;
|
||||
Assert.NotNull(errorResult);
|
||||
Assert.AreEqual(500, errorResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetCommissions_Created()
|
||||
{
|
||||
var commissions = new List<Commission>();
|
||||
_mockCommissionService.Setup(mock => mock.SaveCommissionsAsync(commissions));
|
||||
|
||||
var result = await _controller.SetCommissions(commissions);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var noContentResult = result as NoContentResult;
|
||||
Assert.NotNull(noContentResult);
|
||||
Assert.AreEqual(204, noContentResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetCommissions_ServiceException_Returns500()
|
||||
{
|
||||
var commissions = new List<Commission>();
|
||||
_mockCommissionService.Setup(mock => mock.SaveCommissionsAsync(commissions))
|
||||
.ThrowsAsync(new Exception("error thrown"));
|
||||
|
||||
var result = await _controller.SetCommissions(commissions);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var errorResult = result as StatusCodeResult;
|
||||
Assert.NotNull(errorResult);
|
||||
Assert.AreEqual(500, errorResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetCommissions_CommissionExistsException_Returns409()
|
||||
{
|
||||
var commissions = new List<Commission>();
|
||||
_mockCommissionService.Setup(mock => mock.SaveCommissionsAsync(commissions))
|
||||
.ThrowsAsync(new CommissionExistsException("commission exists error thrown"));
|
||||
|
||||
var result = await _controller.SetCommissions(commissions);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var conflictResult = result as ConflictObjectResult;
|
||||
Assert.NotNull(conflictResult);
|
||||
Assert.AreEqual(409, conflictResult.StatusCode);
|
||||
Assert.AreEqual("commission exists error thrown", conflictResult.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class DeadActivityControllerTest
|
||||
{
|
||||
private DeadActivityController _controller;
|
||||
private Mock<IDeadActivityService> _mockDeadActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDeadActivityService = new Mock<IDeadActivityService>();
|
||||
_controller = new DeadActivityController(_mockDeadActivityService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
var filter = new DeadActivityFilter()
|
||||
{
|
||||
Limit = 999,
|
||||
Page = 1
|
||||
};
|
||||
var results = new PagedResult<DeadActivity>();
|
||||
results.Items = new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test")
|
||||
};
|
||||
results.Total = 1;
|
||||
|
||||
_mockDeadActivityService
|
||||
.Setup(service => service.ListByFilterAsync(filter)).ReturnsAsync(results);
|
||||
var result = await _controller.Get(filter);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Ok()
|
||||
{
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(5))
|
||||
.ReturnsAsync(new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test"));
|
||||
|
||||
var result = await _controller.Get(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
|
||||
var value = okResult.Value as DeadActivity;
|
||||
Assert.NotNull(value);
|
||||
Assert.AreEqual("1234", value.SourceId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_NotFound()
|
||||
{
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(1))
|
||||
.ThrowsAsync(new NotFoundException("Not Found"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("DeadActivity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Exception()
|
||||
{
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(1))
|
||||
.ThrowsAsync(new Exception("Internal Server Error"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessDeadActivityState_Ok()
|
||||
{
|
||||
var deadActivity = new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test");
|
||||
_mockDeadActivityService.Setup(mock => mock.ProcessDeadActivity(1,2))
|
||||
.ReturnsAsync(deadActivity);
|
||||
|
||||
var result = await _controller.Delete(1,2);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessDeadActivityState_Ok_NoLink()
|
||||
{
|
||||
var deadActivity = new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test");
|
||||
_mockDeadActivityService.Setup(mock => mock.ProcessDeadActivity(1,-1))
|
||||
.ReturnsAsync(deadActivity);
|
||||
|
||||
var result = await _controller.Delete(1);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class DeadActiviyControlerTest
|
||||
{
|
||||
private DeadActivityController _controller;
|
||||
private Mock<IDeadActivityService> _mockDeadActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockDeadActivityService = new Mock<IDeadActivityService>();
|
||||
_controller = new DeadActivityController(_mockDeadActivityService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Ok()
|
||||
{
|
||||
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(5))
|
||||
.ReturnsAsync(new DeadActivity(new Activity()
|
||||
{
|
||||
Id = 5,
|
||||
Detail = new ActivityDetail()
|
||||
}, DeadActivityReason.Other, "Test"));
|
||||
|
||||
var result = await _controller.Get(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
|
||||
|
||||
var value = okResult.Value as DeadActivity;
|
||||
Assert.NotNull(value);
|
||||
Assert.AreEqual("Test", value.ReasonNote);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_NotFound()
|
||||
{
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(It.IsAny<int>()))
|
||||
.ThrowsAsync(new NotFoundException("Not Found"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("DeadActivity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class DepartmentControllerTest
|
||||
{
|
||||
private DepartmentController _controller;
|
||||
private IDepartmentService _mockDepartmentService;
|
||||
private IUserService _userService;
|
||||
private ICurrentUserService _currentUser;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDepartmentService = Mock.Of<IDepartmentService>();
|
||||
_userService = Mock.Of<IUserService>();
|
||||
_currentUser = Mock.Of<ICurrentUserService>();
|
||||
_controller = new DepartmentController(_mockDepartmentService, _userService, _currentUser);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAll_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetAllDepartmentsAsync()).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
Id = 0
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.GetDepartments(null,null);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAll_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetAllDepartmentsAsync())
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartments(null, null);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetById_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentByIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new Department() { Id = 5 });
|
||||
|
||||
var result = await _controller.GetDepartmentById(0);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetById_NotFound()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentByIdAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new NotFoundException("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartmentById(5);
|
||||
;
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as NotFoundObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(404, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetById_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentByIdAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartmentById(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CreateDepartment_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.SaveDepartmentAsync(It.IsAny<Department>()))
|
||||
.ReturnsAsync(new Department() {Id = 5});
|
||||
|
||||
var result = await _controller.CreateDepartment(new Department() {DepartmentName = "Test"});
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CreateDepartment_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.SaveDepartmentAsync(It.IsAny<Department>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.CreateDepartment(new Department() {DepartmentName = "Test"});
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CreateDepartment_DuplicateName()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.SaveDepartmentAsync(It.IsAny<Department>()))
|
||||
.ThrowsAsync(new DuplicateDataException("Oops"));
|
||||
|
||||
var result = await _controller.CreateDepartment(new Department() {DepartmentName = "Test"});
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as BadRequestObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(400, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateDepartment_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.UpdateDepartmentAsync(It.IsAny<Department>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(new Department() {Id = 5});
|
||||
|
||||
var result = await _controller.UpdateDepartment(new Department() {DepartmentName = "Test"}, 3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateDepartment_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.UpdateDepartmentAsync(It.IsAny<Department>(), It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.UpdateDepartment(new Department() {DepartmentName = "Test"}, 3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateDepartment_NotFound()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.UpdateDepartmentAsync(It.IsAny<Department>(), It.IsAny<int>()))
|
||||
.ThrowsAsync(new NotFoundException("Oops"));
|
||||
|
||||
var result = await _controller.UpdateDepartment(new Department() {DepartmentName = "Test"}, 3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as NotFoundObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(404, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateDepartment_DuplicateName()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.UpdateDepartmentAsync(It.IsAny<Department>(), It.IsAny<int>()))
|
||||
.ThrowsAsync(new DuplicateDataException("Oops"));
|
||||
|
||||
var result = await _controller.UpdateDepartment(new Department() {DepartmentName = "Test"}, 3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as BadRequestObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(400, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDepartmentDetails_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentDetailsAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new DepartmentDetails {
|
||||
Department = new Department { Id = 3 },
|
||||
Assignments = new List<UserDepartment> { new UserDepartment(), new UserDepartment() },
|
||||
RegionalManager = new AppUser { EmployeeId = "C0000" }
|
||||
});
|
||||
|
||||
var result = await _controller.GetDepartmentDetails(3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDepartmentDetails_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentDetailsAsync( It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartmentDetails(3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDepartmentDetails_NotFound()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentDetailsAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new NotFoundException("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartmentDetails(3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as NotFoundObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(404, statusRes.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+703
@@ -0,0 +1,703 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Dayforce;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class EmployeeControllerTest
|
||||
{
|
||||
private EmployeeController _controller;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDayForceSyncService> _mockDayForceService;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_mockDayForceService = new Mock<IDayForceSyncService>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_controller = new EmployeeController(
|
||||
_mockCurrentUserService.Object,
|
||||
_mockDayForceService.Object,
|
||||
_mockUserService.Object
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
_mockUserService
|
||||
.Setup(service => service.GetAllUsersAsync(null))
|
||||
.ReturnsAsync(
|
||||
new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 456,
|
||||
EmployeeId = "DEF",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.Admin,
|
||||
HomeDepartment = "Branch-44"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 789,
|
||||
EmployeeId = "CONTRACTOR1",
|
||||
BaseRole = "QA",
|
||||
Role = Role.Teller,
|
||||
HomeDepartment = "Branch-44"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 900,
|
||||
EmployeeId = "CONTRACTOR2",
|
||||
BaseRole = "QA",
|
||||
Role = Role.BM,
|
||||
HomeDepartment = "Branch-0"
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.GetAllUsers(null, null);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Resolve_ok()
|
||||
{
|
||||
_mockUserService
|
||||
.Setup(service => service.FindUserAsync("123", null))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.ResolveUser("123");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Resolve_BadRequest()
|
||||
{
|
||||
_mockUserService
|
||||
.Setup(service => service.FindUserAsync("11771", null))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.ResolveUser("11771", "[email protected]");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as BadRequestObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(400, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Resolve_Throws()
|
||||
{
|
||||
_mockUserService
|
||||
.Setup(service => service.FindUserAsync("123", null))
|
||||
.Throws<Exception>();
|
||||
|
||||
var result = await _controller.ResolveUser("123");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Self_ok()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.GetCurrentEmployee();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Self_Unknown()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
(AppUser)null
|
||||
);
|
||||
|
||||
var result = await _controller.GetCurrentEmployee();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as NoContentResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(204, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignment_Ok()
|
||||
{
|
||||
var employee = new AppUser()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
|
||||
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 userDepartments = new List<UserDepartment>
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Employee = employee,
|
||||
Note = "Test Assignment",
|
||||
Department = department,
|
||||
StartDate = DateTime.Today,
|
||||
IsHome = false
|
||||
}
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "1",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service => service.AssignDepartments(employee.EmployeeId, It.IsAny<DepartmentAssignmentRequest>()))
|
||||
.ReturnsAsync(
|
||||
userDepartments
|
||||
);
|
||||
|
||||
var result = await _controller.AssignDepartment(employee.EmployeeId, assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignment_BadRequest()
|
||||
{
|
||||
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()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "1",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service => service.AssignDepartments(employee.EmployeeId, It.IsAny<DepartmentAssignmentRequest>()))
|
||||
.ThrowsAsync(new BadDepartmentAssignmentException("test"));
|
||||
|
||||
var result = await _controller.AssignDepartment(employee.EmployeeId, assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(400, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignment_ADUserNotFound()
|
||||
{
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
_mockCurrentUserService
|
||||
.Setup(service => service.GetCurrentUser())
|
||||
.Returns<ApplicationUser>(null);
|
||||
|
||||
var result = await _controller.AssignDepartment("C1", assignment);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignment_ForbiddenSelfAssign()
|
||||
{
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "999",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.AssignDepartment("999", assignment);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var forbiddennResult = result as ObjectResult;
|
||||
Assert.NotNull(forbiddennResult);
|
||||
Assert.AreEqual(403, forbiddennResult.StatusCode);
|
||||
Assert.AreEqual("Not allowed to assign yourself to a department.", forbiddennResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignmentUpdate_Ok()
|
||||
{
|
||||
var employee = new AppUser()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
var assignment = new UserDepartment()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = 555,
|
||||
Employee = employee,
|
||||
IsHome = false,
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
var request = new DepartmentUpdateRequest()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
AssignmentId = 5,
|
||||
SlidingPayout = 100,
|
||||
Role = "Teller"
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "1",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service =>
|
||||
service.UpdateDepartmentAssignment(request))
|
||||
.ReturnsAsync(
|
||||
assignment
|
||||
);
|
||||
|
||||
var result =
|
||||
await _controller.UpdateDepartmentAssignment(assignment.Employee.EmployeeId, assignment.DepartmentId, request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignmentTerm_BadRequest()
|
||||
{
|
||||
var employee = new AppUser()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
var assignment = new UserDepartment()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = 555,
|
||||
Employee = employee,
|
||||
IsHome = false,
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
var request = new DepartmentUpdateRequest()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
AssignmentId = 5,
|
||||
SlidingPayout = 999,
|
||||
Role = "Teller"
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "1",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service =>
|
||||
service.UpdateDepartmentAssignment(request))
|
||||
.ThrowsAsync(new BadDepartmentAssignmentException("test"));
|
||||
|
||||
var result =
|
||||
await _controller.UpdateDepartmentAssignment(assignment.Employee.EmployeeId, assignment.DepartmentId, request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(400, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignmentTerm_ADUserNotFound()
|
||||
{
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
_mockCurrentUserService
|
||||
.Setup(service => service.GetCurrentUser())
|
||||
.Returns<ApplicationUser>(null);
|
||||
|
||||
var result = await _controller.UpdateDepartmentAssignment("C1", 1, null);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignmentTerm_ForbiddenSelfTerm()
|
||||
{
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
var request = new DepartmentUpdateRequest()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
AssignmentId = 5,
|
||||
SlidingPayout = 999,
|
||||
Role = "Teller"
|
||||
};
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "999",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.UpdateDepartmentAssignment("999", 1, request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var forbiddennResult = result as ObjectResult;
|
||||
Assert.NotNull(forbiddennResult);
|
||||
Assert.AreEqual(403, forbiddennResult.StatusCode);
|
||||
Assert.AreEqual("Not allowed to terminate yourself from a department.", forbiddennResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Employee_By_Id_ok()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByEmployeeIdAsync("ABC"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.GetEmployeeById("ABC");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Employee_By_Id_Unknown()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByEmployeeIdAsync("DEF"))
|
||||
.ReturnsAsync(
|
||||
(AppUser)null
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByEmployeeIdAsync("ABC"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.GetEmployeeById("DEF");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as NoContentResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(204, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Employee_By_Id_Throw()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]"
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByEmployeeIdAsync("DEF"))
|
||||
.Throws<Exception>();
|
||||
|
||||
var result = await _controller.GetEmployeeById("DEF");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SyncDayForce_ForceRefresh()
|
||||
{
|
||||
_mockDayForceService.Setup(service => service.SyncDayForceUsers(new DayforceProcessRequest()));
|
||||
|
||||
var result = await _controller.SyncDayForce();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var successResult = result as StatusCodeResult;
|
||||
Assert.NotNull(successResult);
|
||||
Assert.AreEqual(200, successResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class GoalControllerTest
|
||||
{
|
||||
private GoalController _controller;
|
||||
private Mock<IGoalService> _mockGoalService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
private Mock<IGoalDispersalService> _goalDispersalService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockGoalService = new Mock<IGoalService>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_goalDispersalService = new Mock<IGoalDispersalService>();
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_controller = new GoalController(_mockGoalService.Object, _goalDispersalService.Object ,_mockCurrentUserService.Object,
|
||||
_mockUserService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
_mockGoalService
|
||||
.Setup(service => service.GetGoalsAsync(It.IsAny<GoalSearchRequest>())).ReturnsAsync(
|
||||
new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
Id = 1
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.GetGoals(12,2021,12,2021, 1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_DepartmentGoals_OK()
|
||||
{
|
||||
var goals = new DepartmentGoals(55, DateTime.Now.Year);
|
||||
_mockGoalService
|
||||
.Setup(service => service.GetAnnualDepartmentGoalsAsync(goals.DepartmentId, goals.Year)).ReturnsAsync(
|
||||
goals);
|
||||
|
||||
var result = await _controller.GetDepartmentGoals(55, DateTime.Now.Year);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_PersonnelGoals_OK()
|
||||
{
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565
|
||||
}
|
||||
};
|
||||
|
||||
var goals = new PersonnelGoals(55, DateTime.Now.Month, DateTime.Now.Year, users);
|
||||
var searchRequest = new DepartmentPersonnelSearchRequest
|
||||
{
|
||||
DepartmentId = goals.DepartmentId,
|
||||
Year = goals.Month,
|
||||
Month = goals.Year
|
||||
};
|
||||
_mockGoalService
|
||||
.Setup(service => service.GetMonthlyPersonnelGoalsAsync(searchRequest))
|
||||
.ReturnsAsync(
|
||||
goals);
|
||||
|
||||
var result = await _controller.GetPersonnelGoals(55, DateTime.Now.Month, DateTime.Now.Year);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_CurrentUserGoals_OK()
|
||||
{
|
||||
var user1 = new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
FirstName = "Test",
|
||||
LastName = "McTester"
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
var goals = new EmployeeGoals(user, range);
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
|
||||
_mockGoalService
|
||||
.Setup(service => service.GetEmployeeGoalsForMonthRangeAsync(goals.Employee, range))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _controller.GetCurrentUserGoals(range.FromMonth, range.FromYear, range.ToMonth, range.ToYear);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_CurrentUserDepartmentsGoals_OK()
|
||||
{
|
||||
var user1 = new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
FirstName = "Test",
|
||||
LastName = "McTester"
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
var goals = new List<DepartmentGoalsForRange> { new DepartmentGoalsForRange(1, range) };
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
|
||||
_mockGoalService
|
||||
.Setup(service => service.GetEmployeeDepartmentsGoalsForMonthRangeAsync(user, range))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _controller.GetCurrentUserDepartmentsGoals(range.FromMonth, range.FromYear, range.ToMonth, range.ToYear);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Payout;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Payout;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class PayoutControllerTest
|
||||
{
|
||||
private PayoutController _controller;
|
||||
private Mock<IPayoutService> _mockPayoutService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IActivityService> _mockActivityService;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockPayoutService = new Mock<IPayoutService>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_mockActivityService = new Mock<IActivityService>();
|
||||
_controller = new PayoutController(_mockPayoutService.Object, _mockUserService.Object,
|
||||
_mockCurrentUserService.Object, _mockActivityService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Employee_OK()
|
||||
{
|
||||
var user1 = new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
FirstName = "Test",
|
||||
LastName = "McTester"
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "5",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(user.EmployeeId)).ReturnsAsync(user);
|
||||
_mockPayoutService
|
||||
.Setup(service => service.BuildUserDepartmentsPayoutView(It.IsAny<AppUser>(), It.IsAny<MonthRange>()))
|
||||
.ReturnsAsync(
|
||||
new List<DepartmentPayout>());
|
||||
|
||||
var result = await _controller.GetEmployeePayout("5", 2021, 12);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Me_OK()
|
||||
{
|
||||
var user1 = new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
FirstName = "Test",
|
||||
LastName = "McTester"
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "5",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(user.EmployeeId)).ReturnsAsync(user);
|
||||
_mockPayoutService
|
||||
.Setup(service => service.BuildUserDepartmentsPayoutView(It.IsAny<AppUser>(), It.IsAny<MonthRange>()))
|
||||
.ReturnsAsync(
|
||||
new List<DepartmentPayout>());
|
||||
|
||||
var result = await _controller.GetEmployeePayout(user.EmployeeId, 2021, 12);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class SettingsControllerTest
|
||||
{
|
||||
private SettingsController _controller;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
private Mock<IDepartmentService> _mockDepartmentService;
|
||||
private Mock<ISettingsService> _mockSettingsService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_mockDepartmentService = new Mock<IDepartmentService>();
|
||||
_mockSettingsService = new Mock<ISettingsService>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_controller = new SettingsController(
|
||||
_mockCurrentUserService.Object,
|
||||
new DateTimeService(),
|
||||
_mockDepartmentService.Object,
|
||||
_mockSettingsService.Object,
|
||||
_mockUserService.Object
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
_mockDepartmentService.Setup(service => service.GetAllDepartmentsAsync()).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
Id = 0
|
||||
}
|
||||
});
|
||||
|
||||
_mockUserService.Setup(service => service.GetAllUserSummariesAsync()).ReturnsAsync(
|
||||
new List<UserSummary>()
|
||||
{
|
||||
new UserSummary()
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.Get();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class UserAssignmentControllerTest
|
||||
{
|
||||
private UserAssignmentController _controller;
|
||||
private Mock<IUserAssignmentService> _mockUserAssignmentService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserAssignmentService = new Mock<IUserAssignmentService>();
|
||||
_controller = new UserAssignmentController(_mockUserAssignmentService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAllUserAssignments_OK()
|
||||
{
|
||||
_mockUserAssignmentService.Setup(service => service.GetAllUserAssignmentsAsync())
|
||||
.ReturnsAsync(new List<UserAssignment>());
|
||||
|
||||
var result = await _controller.GetAllUserAssignments();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAllUserAssignments_Exception()
|
||||
{
|
||||
{
|
||||
_mockUserAssignmentService.Setup(service => service.GetAllUserAssignmentsAsync())
|
||||
.ThrowsAsync(new Exception("Exception Message"));
|
||||
|
||||
var result = await _controller.GetAllUserAssignments();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetRegionalManager_OK()
|
||||
{
|
||||
|
||||
var assignment = new UserAssignmentRequest
|
||||
{
|
||||
EmployeeId = "123",
|
||||
Key = "NORTH",
|
||||
Type = AssignmentType.RegionalManager
|
||||
};
|
||||
|
||||
_mockUserAssignmentService.Setup(service => service.SetRegionalManager(It.IsAny<UserAssignmentRequest>()))
|
||||
.ReturnsAsync(new UserAssignment());
|
||||
|
||||
var result = await _controller.SetRegionalManager(assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetRegionalManager_BadUserAssignmentException()
|
||||
{
|
||||
var assignment = new UserAssignmentRequest();
|
||||
_mockUserAssignmentService.Setup(service => service.SetRegionalManager(assignment))
|
||||
.ThrowsAsync(new BadUserAssignmentException("Exception Message"));
|
||||
|
||||
var result = await _controller.SetRegionalManager(assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestRes = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestRes);
|
||||
Assert.AreEqual(400, badRequestRes.StatusCode);
|
||||
Assert.AreEqual("Exception Message", badRequestRes.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetRegionalManager_Exception()
|
||||
{
|
||||
var assignment = new UserAssignmentRequest();
|
||||
_mockUserAssignmentService.Setup(service => service.SetRegionalManager(assignment))
|
||||
.ThrowsAsync(new Exception("Exception Message"));
|
||||
|
||||
var result = await _controller.SetRegionalManager(assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class ActivityTest
|
||||
{
|
||||
[Test]
|
||||
public void CopyActivityForTransfer_Basic()
|
||||
{
|
||||
var activityToCopy = new Activity
|
||||
{
|
||||
Accepted = new DateTime(2021, 9, 22),
|
||||
DepartmentId = 2,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountBalance = 100.00,
|
||||
AccountNewBalance = 99.00,
|
||||
AccountNumber = "888888",
|
||||
AccountStatus = "Open",
|
||||
AgreementNumber = "999",
|
||||
BranchOrgName = "Org Name",
|
||||
BranchOrgNbr = "Org Number",
|
||||
DnaPersonNbr = "DNA number",
|
||||
IsDebtProtectionEligible = true,
|
||||
MemberName = "Member Name",
|
||||
StationName = "Station Name",
|
||||
SubjectOrgNbr = "Subject Org Number",
|
||||
SubjectPersonNbr = "Subject Person Number",
|
||||
IsGapInsuranceEligible = true,
|
||||
},
|
||||
EmployeeEmail = "[email protected]",
|
||||
EmployeeId = "E0000",
|
||||
MatchingActivityId = 0,
|
||||
Product = Product.CheckCard,
|
||||
SourceCreated = new DateTime(2021, 9, 22),
|
||||
SourceId = "Source ID",
|
||||
SourceSystem = SystemType.Dna,
|
||||
State = ActivityState.PendingTransfer,
|
||||
Type = ActivityType.Sale
|
||||
};
|
||||
var activityTransferAction = new ActivityTransferAction
|
||||
{
|
||||
NewActivityDepartmentId = 88,
|
||||
NewActivityEmployeeId = "C0001",
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted
|
||||
};
|
||||
var employeeEmailAddress = "[email protected]";
|
||||
|
||||
var result = Activity.CopyActivityForTransfer(activityToCopy, activityTransferAction, employeeEmailAddress);
|
||||
|
||||
Assert.AreEqual(true, result.Detail.IsDebtProtectionEligible);
|
||||
Assert.AreEqual(0, result.Id);
|
||||
Assert.AreEqual("888888", result.Detail.AccountNumber);
|
||||
Assert.AreEqual(new DateTime(2021, 9, 22), result.Accepted);
|
||||
Assert.AreEqual(new DateTime(2021, 9, 22), result.SourceCreated);
|
||||
Assert.AreEqual(ActivityType.Sale, result.Type);
|
||||
Assert.AreEqual(activityTransferAction.NewActivityDepartmentId, result.DepartmentId);
|
||||
Assert.AreEqual(activityTransferAction.NewActivityEmployeeId, result.EmployeeId);
|
||||
Assert.AreEqual(activityTransferAction.ActivityStateBeforeTransfer, result.State);
|
||||
Assert.AreEqual(employeeEmailAddress, result.EmployeeEmail);
|
||||
Assert.AreEqual(new DateTime(), result.LastUpdated);
|
||||
Assert.AreEqual(null, result.LastUpdatedBy);
|
||||
Assert.AreEqual(UserType.Associate, result.LastUpdatedByType);
|
||||
Assert.AreEqual(new DateTime(), result.Created);
|
||||
Assert.AreEqual(null, result.CreatedBy);
|
||||
Assert.AreEqual(UserType.Associate, result.CreatedByType);
|
||||
Assert.AreEqual(true, result.Detail.IsGapInsuranceEligible);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ActivityTransformForView()
|
||||
{
|
||||
var activity = new Activity
|
||||
{
|
||||
Product = Product.CreditCard,
|
||||
Type = ActivityType.Referral,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
Activity = new Activity
|
||||
{
|
||||
Product = Product.CreditCard,
|
||||
Type = ActivityType.Referral,
|
||||
},
|
||||
AccountNumber = "1234567890"
|
||||
}
|
||||
};
|
||||
|
||||
var result = activity.TransformForView();
|
||||
|
||||
Assert.AreEqual("XXXXXX7890", result.Detail.AccountNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class ActivityTransferActionTest
|
||||
{
|
||||
[Test]
|
||||
public void IsEligibleForTransfer()
|
||||
{
|
||||
Assert.True(ActivityTransferAction.IsEligibleForTransfer(ActivityState.Accepted));
|
||||
Assert.True(ActivityTransferAction.IsEligibleForTransfer(ActivityState.PendingReferral));
|
||||
Assert.True(ActivityTransferAction.IsEligibleForTransfer(ActivityState.ManualReview));
|
||||
Assert.False(ActivityTransferAction.IsEligibleForTransfer(ActivityState.Created));
|
||||
Assert.False(ActivityTransferAction.IsEligibleForTransfer(ActivityState.PendingTransfer));
|
||||
Assert.False(ActivityTransferAction.IsEligibleForTransfer(ActivityState.Rejected));
|
||||
Assert.False(ActivityTransferAction.IsEligibleForTransfer(ActivityState.Transferred));
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class BusinessLineTest
|
||||
{
|
||||
[Test]
|
||||
public void DetermineBusinessLine()
|
||||
{
|
||||
Assert.AreEqual(BusinessLine.TryLookup("HEADQUARTERS - SECURITY & FRAUD"),BusinessLine.MemberServices);
|
||||
Assert.AreEqual(BusinessLine.TryLookup("GERMANTOWN - BRANCH"),BusinessLine.BranchOperations);
|
||||
Assert.AreEqual(BusinessLine.TryLookup("HEADQUARTERS - OPERATIONS"),BusinessLine.Operations);
|
||||
Assert.AreEqual(BusinessLine.TryLookup(null),BusinessLine.MemberServices);
|
||||
Assert.AreEqual(BusinessLine.TryLookup(""),BusinessLine.MemberServices);
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class CommissionTest
|
||||
{
|
||||
[Test]
|
||||
public void HasSameRoleAndProduct_FullMatch_True()
|
||||
{
|
||||
var commission = new Commission { Role = Role.ABM, Product = Product.ATMCard };
|
||||
var fullMatch = new Commission { Role = Role.ABM, Product = Product.ATMCard };
|
||||
Assert.True(commission.HasSameRoleAndProduct(fullMatch));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasSameRoleAndProduct_NoMatch_False()
|
||||
{
|
||||
var commission = new Commission { Role = Role.ABM, Product = Product.ATMCard };
|
||||
var noMatch = new Commission { Role = Role.Admin, Product = Product.NewChecking };
|
||||
Assert.False(commission.HasSameRoleAndProduct(noMatch));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasSameRoleAndProduct_OnlyRoleMatch_False()
|
||||
{
|
||||
var commission = new Commission { Role = Role.ABM, Product = Product.ATMCard };
|
||||
var roleMatch = new Commission { Role = Role.ABM, Product = Product.NewChecking };
|
||||
Assert.False(commission.HasSameRoleAndProduct(roleMatch));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasSameRoleAndProduct_OnlyProductMatch_False()
|
||||
{
|
||||
var commission = new Commission { Role = Role.ABM, Product = Product.ATMCard };
|
||||
var productMatch = new Commission { Role = Role.Admin, Product = Product.ATMCard };
|
||||
Assert.False(commission.HasSameRoleAndProduct(productMatch));
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class DepartmentLineItemTest
|
||||
{
|
||||
[Test]
|
||||
public void Validate_CalculatePercentage_TotalNonZero()
|
||||
{
|
||||
var departmentLineItem = new DepartmentLineItem
|
||||
{
|
||||
DepartmentName = "Test1",
|
||||
PayoutTotal = 12
|
||||
};
|
||||
|
||||
departmentLineItem.CalculatePercentage(12);
|
||||
|
||||
Assert.NotNull(departmentLineItem.PayoutPercentage);
|
||||
Assert.AreEqual((decimal) 100, departmentLineItem.PayoutPercentage);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_CalculatePercentage_TotalZero()
|
||||
{
|
||||
var departmentLineItem = new DepartmentLineItem
|
||||
{
|
||||
DepartmentName = "Test1",
|
||||
PayoutTotal = 12
|
||||
};
|
||||
|
||||
departmentLineItem.CalculatePercentage(0);
|
||||
|
||||
Assert.NotNull(departmentLineItem.PayoutPercentage);
|
||||
Assert.AreEqual((decimal) 0, departmentLineItem.PayoutPercentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class DepartmentTest
|
||||
{
|
||||
[Test]
|
||||
public void Validate_OK()
|
||||
{
|
||||
var dept = new Department()
|
||||
{
|
||||
DepartmentName = "Test1",
|
||||
BusinessLineCode = "MEMSRV",
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
|
||||
var results = dept.Validate(new ValidationContext(dept));
|
||||
Assert.IsEmpty(results);
|
||||
}
|
||||
|
||||
[TestCase("BCHOPS", false)]
|
||||
[TestCase("MEMSRV", false)]
|
||||
[TestCase("OPS", false)]
|
||||
[TestCase("TOAST", true)]
|
||||
public void Validate_BusinessLineCode_OK(string businessLine, bool hasError)
|
||||
{
|
||||
var dept = new Department()
|
||||
{
|
||||
DepartmentName = "Test1",
|
||||
BusinessLineCode = businessLine,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
|
||||
var results = dept.Validate(new ValidationContext(dept));
|
||||
Assert.AreEqual(hasError,results.Any());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_Bad_BusinessLine()
|
||||
{
|
||||
var dept = new Department()
|
||||
{
|
||||
DepartmentName = "Test1",
|
||||
BusinessLineCode = "THISISNOTAREALBUSINESSLINECODE",
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
|
||||
var results = dept.Validate(new ValidationContext(dept));
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(1, results.Count());
|
||||
Assert.AreEqual(results.First().ErrorMessage, "The supplied BusinessLineCode is not associated with any known BusinessLine");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NullRegionCode_OK()
|
||||
{
|
||||
var department = new Department()
|
||||
{
|
||||
DepartmentName = "Test1",
|
||||
BusinessLineCode = "MEMSRV",
|
||||
RegionCode = null,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
|
||||
var results = department.Validate(new ValidationContext(department));
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
}
|
||||
|
||||
[TestCase("INVALID_REGION")]
|
||||
[TestCase("")]
|
||||
[TestCase(" ")]
|
||||
public void Validate_BadRegionCode_IncludesValidationResult(string regionCode)
|
||||
{
|
||||
var department = new Department()
|
||||
{
|
||||
DepartmentName = "Test1",
|
||||
BusinessLineCode = "MEMSRV",
|
||||
RegionCode = regionCode,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
|
||||
var results = department.Validate(new ValidationContext(department));
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(1, results.Count());
|
||||
Assert.AreEqual(results.First().ErrorMessage, "The supplied RegionCode is not associated with any known Region");
|
||||
}
|
||||
|
||||
[TestCase("EAST")]
|
||||
[TestCase("NORTH")]
|
||||
[TestCase("SOUTH")]
|
||||
[TestCase("WEST")]
|
||||
public void Validate_RegionCode_OK(string regionCode)
|
||||
{
|
||||
var dept = new Department()
|
||||
{
|
||||
DepartmentName = "Test1",
|
||||
BusinessLineCode = "MEMSRV",
|
||||
RegionCode = regionCode,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
|
||||
var results = dept.Validate(new ValidationContext(dept));
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class RegionTest
|
||||
{
|
||||
[Test]
|
||||
public void Regions_ContainsRegions()
|
||||
{
|
||||
var regions = Region.Regions;
|
||||
|
||||
Assert.AreEqual(4, regions.Count);
|
||||
Assert.Contains(Region.North, regions);
|
||||
Assert.Contains(Region.South, regions);
|
||||
Assert.Contains(Region.East, regions);
|
||||
Assert.Contains(Region.West, regions);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindByCode_ValidCodes_ReturnsRegion()
|
||||
{
|
||||
Assert.AreSame(Region.North, Region.FindByCode("NORTH"));
|
||||
Assert.AreSame(Region.South, Region.FindByCode("SOUTH"));
|
||||
Assert.AreSame(Region.East, Region.FindByCode("EAST"));
|
||||
Assert.AreSame(Region.West, Region.FindByCode("WEST"));
|
||||
}
|
||||
|
||||
[TestCase(null)]
|
||||
[TestCase("")]
|
||||
[TestCase(" ")]
|
||||
[TestCase("INVALID")]
|
||||
public void FindByCode_InvalidCodes_ReturnsNull(string regionCode)
|
||||
{
|
||||
Assert.Null(Region.FindByCode(regionCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
using System.Linq;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class RoleTest
|
||||
{
|
||||
[Test]
|
||||
public void GetRolesList_OK()
|
||||
{
|
||||
var roles = Role.GetRolesList();
|
||||
Assert.Contains(Role.Admin, roles);
|
||||
Assert.Contains(Role.RegionalManager, roles);
|
||||
Assert.Contains(Role.BM, roles);
|
||||
Assert.Contains(Role.ABM, roles);
|
||||
Assert.Contains(Role.BOM, roles);
|
||||
Assert.Contains(Role.PFO, roles);
|
||||
Assert.Contains(Role.Teller, roles);
|
||||
Assert.Contains(Role.MSCTeamLead, roles);
|
||||
Assert.Contains(Role.MSLO, roles);
|
||||
Assert.Contains(Role.MSR, roles);
|
||||
Assert.Contains(Role.OpsHelpDesk, roles);
|
||||
Assert.Contains(Role.UniversalSpecialistPFO, roles);
|
||||
Assert.Contains(Role.UniversalSpecialistTeller, roles);
|
||||
Assert.Contains(Role.InStoreBranchManager, roles);
|
||||
Assert.Contains(Role.InStoreAssistantBranchManager, roles);
|
||||
Assert.Contains(Role.ManagementTrainee, roles);
|
||||
Assert.Contains(Role.BusinessLineManager, roles);
|
||||
Assert.Contains(Role.MISSING_ROLE, roles);
|
||||
Assert.Contains(Role.UNKNOWN_ROLE, roles);
|
||||
Assert.Contains(Role.Developer, roles);
|
||||
Assert.Contains(Role.Mortgage, roles);
|
||||
Assert.Contains(Role.LIC, roles);
|
||||
Assert.Contains(Role.Manager, roles);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DetermineRoleOrDefault_Ok()
|
||||
{
|
||||
var role = Role.DetermineRoleOrDefault("Admin");
|
||||
Assert.AreEqual(Role.Admin, role);
|
||||
|
||||
var roleUnknownEmpty = Role.DetermineRoleOrDefault("");
|
||||
Assert.AreEqual(Role.UNKNOWN_ROLE, roleUnknownEmpty);
|
||||
|
||||
var roleUnknown = Role.DetermineRoleOrDefault("NOT_REAL_HOPEFULLY");
|
||||
Assert.AreEqual(Role.UNKNOWN_ROLE, roleUnknown);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SearchRoles_OK()
|
||||
{
|
||||
var foundRoles = Role.SearchRoles("Admin");
|
||||
Assert.Contains(Role.Admin, foundRoles);
|
||||
Assert.AreEqual(2, foundRoles.Count());
|
||||
|
||||
foundRoles = Role.SearchRoles("Branch Manager");
|
||||
Assert.Contains(Role.BM, foundRoles);
|
||||
Assert.Contains(Role.ABM, foundRoles);
|
||||
Assert.Contains(Role.InStoreBranchManager, foundRoles);
|
||||
Assert.Contains(Role.InStoreAssistantBranchManager, foundRoles);
|
||||
Assert.AreEqual(4, foundRoles.Count());
|
||||
|
||||
foundRoles = Role.SearchRoles("Developer");
|
||||
Assert.Contains(Role.Developer, foundRoles);
|
||||
Assert.AreEqual(1, foundRoles.Count());
|
||||
|
||||
foundRoles = Role.SearchRoles("Develop");
|
||||
Assert.Contains(Role.Developer, foundRoles);
|
||||
Assert.AreEqual(1, foundRoles.Count());
|
||||
|
||||
foundRoles = Role.SearchRoles("LIC");
|
||||
Assert.Contains(Role.LIC, foundRoles);
|
||||
Assert.AreEqual(2, foundRoles.Count());
|
||||
|
||||
foundRoles = Role.SearchRoles("LIC ");
|
||||
Assert.Contains(Role.LIC, foundRoles);
|
||||
Assert.AreEqual(2, foundRoles.Count());
|
||||
|
||||
foundRoles = Role.SearchRoles(" LIC");
|
||||
Assert.Contains(Role.LIC, foundRoles);
|
||||
Assert.AreEqual(2, foundRoles.Count());
|
||||
|
||||
foundRoles = Role.SearchRoles(" LIC ");
|
||||
Assert.Contains(Role.LIC, foundRoles);
|
||||
Assert.AreEqual(2, foundRoles.Count());
|
||||
|
||||
foundRoles = Role.SearchRoles(" lic ");
|
||||
Assert.Contains(Role.LIC, foundRoles);
|
||||
Assert.AreEqual(2, foundRoles.Count());
|
||||
}
|
||||
}
|
||||
}
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
using System;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Entities
|
||||
{
|
||||
public class UserDepartmentTest
|
||||
{
|
||||
private readonly AppUser _employee = new AppUser()
|
||||
{
|
||||
EmployeeId = "5",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void NonConflictingAssignment_Diff_Dept()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 6,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
Assert.AreEqual(string.Empty, message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NonConflictingAssignment_Diff_User()
|
||||
{
|
||||
var employee2 = new AppUser()
|
||||
{
|
||||
EmployeeId = "6",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = employee2,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
Assert.AreEqual(string.Empty, message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConflictingAssignment_Case_Null_Null()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConflictingAssignment_Case_Null_Valid()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Parse("2021-01-01T00:00:00.000Z").ToUniversalTime(),
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000Z").ToUniversalTime(),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000Z").ToUniversalTime()
|
||||
};
|
||||
|
||||
Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConflictingAssignment_Case_Valid_Null_Before()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = DateTime.Today.AddDays(1)
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today.AddDays(1),
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NonConflictingAssignment_Case_Valid_Null_After()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = DateTime.Today.AddDays(1)
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today.AddDays(2),
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NonConflictingAssignment_Case_Valid_Valid_After()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000Z").ToUniversalTime(),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000Z").ToUniversalTime()
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Parse("2021-08-01T00:00:00.000Z").ToUniversalTime(),
|
||||
EndDate = DateTime.Parse("2021-08-31T23:59:00.000Z").ToUniversalTime()
|
||||
};
|
||||
|
||||
Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NonConflictingAssignment_Case_Valid_Valid_Before()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000Z").ToUniversalTime(),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000Z").ToUniversalTime()
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Parse("2021-06-01T00:00:00.000Z").ToUniversalTime(),
|
||||
EndDate = DateTime.Parse("2021-06-30T23:59:00.000Z").ToUniversalTime()
|
||||
};
|
||||
|
||||
Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConflictingAssignment_Case_Valid_Valid_Overlap()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = DateTime.Today.AddDays(5)
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Today.AddDays(2),
|
||||
EndDate = DateTime.Today.AddDays(10)
|
||||
};
|
||||
|
||||
Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConflictingAssignment_Case_Overlap_IgnoreTimestamp()
|
||||
{
|
||||
var existingAssignment = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000Z").ToUniversalTime(),
|
||||
EndDate = DateTime.Parse("2021-07-05T12:00:00.000Z").ToUniversalTime()
|
||||
};
|
||||
|
||||
var newAssignment = new UserDepartment()
|
||||
{
|
||||
// DepartmentID will be NULL.
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
Employee = _employee,
|
||||
StartDate = DateTime.Parse("2021-07-05T15:00:00.000Z").ToUniversalTime(),
|
||||
EndDate = DateTime.Parse("2021-07-08T00:00:00.000Z").ToUniversalTime()
|
||||
};
|
||||
|
||||
Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message));
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
namespace Application.UnitTests.Extensions
|
||||
{
|
||||
public class PayoutProfileCalculateTestInput
|
||||
{
|
||||
public PayoutProfileCalculateTestInput(Product product, Role role, PayoutType type, PayoutProfile expectedProfile, int goal,
|
||||
int actual, int expectedPay, double expectedPercentage)
|
||||
{
|
||||
Product = product;
|
||||
Role = role;
|
||||
Type = type;
|
||||
ExpectedProfile = expectedProfile;
|
||||
Goal = goal;
|
||||
Actual = actual;
|
||||
ExpectedPay = expectedPay;
|
||||
ExpectedPercentage = expectedPercentage;
|
||||
}
|
||||
|
||||
public Product Product { get; set; }
|
||||
public Role Role { get; set; }
|
||||
public PayoutType Type { get; set; }
|
||||
public PayoutProfile ExpectedProfile { get; set; }
|
||||
public int Goal { get; set; }
|
||||
public int Actual { get; set; }
|
||||
public int ExpectedPay { get; set; }
|
||||
public double ExpectedPercentage { get; set; }
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Extensions
|
||||
{
|
||||
public class PayoutProfileExtensionsTest
|
||||
{
|
||||
private readonly DateTime _nonOverriddenDateTime = DateTime.ParseExact("2021-12-01", "yyyy-MM-dd", CultureInfo.InvariantCulture);
|
||||
|
||||
[Test]
|
||||
public void Payout_Basic()
|
||||
{
|
||||
var product = Product.Vehicle;
|
||||
var role = Role.BM;
|
||||
var expectedProfile = PayoutProfile.BMVehicle;
|
||||
var goal = 10;
|
||||
var actual = 10;
|
||||
var expectedPay = 125;
|
||||
var expectedPercentage = 1.0;
|
||||
|
||||
var profile = PayoutProfile.LookupProfile(product, role, PayoutType.Department);
|
||||
Assert.NotNull(profile);
|
||||
Assert.AreEqual(profile, expectedProfile);
|
||||
|
||||
double percentage = actual / (double)goal;
|
||||
Assert.AreEqual(expectedPercentage, percentage);
|
||||
|
||||
var range = profile.FindPayoutRange(percentage, _nonOverriddenDateTime);
|
||||
Assert.IsTrue(range.IsInRange(percentage));
|
||||
|
||||
var result = profile.CalculateLineItemPayout(goal, actual, _nonOverriddenDateTime);
|
||||
Assert.AreEqual(expectedPay, result);
|
||||
}
|
||||
|
||||
[TestCase(0, 0)]
|
||||
[TestCase(0.12, 0.1)]
|
||||
[TestCase(41.62, 33.3)]
|
||||
[TestCase(83.38, 66.7)]
|
||||
[TestCase(41.25, 33)]
|
||||
[TestCase(31.25, 25)]
|
||||
[TestCase(123.75, 99)]
|
||||
[TestCase(125.00, 100)]
|
||||
public void Payout_Basic_Percentage(decimal expectedPayout, decimal fromPercentage)
|
||||
{
|
||||
var product = Product.Vehicle;
|
||||
var role = Role.BM;
|
||||
var expectedProfile = PayoutProfile.BMVehicle;
|
||||
var goal = 10;
|
||||
var actual = 10;
|
||||
var expectedPay = expectedPayout;
|
||||
var expectedPercentage = 1.0;
|
||||
|
||||
var profile = PayoutProfile.LookupProfile(product, role, PayoutType.Department);
|
||||
Assert.NotNull(profile);
|
||||
Assert.AreEqual(profile, expectedProfile);
|
||||
|
||||
double percentage = actual / (double)goal;
|
||||
Assert.AreEqual(expectedPercentage, percentage);
|
||||
|
||||
var range = profile.FindPayoutRange(percentage, _nonOverriddenDateTime);
|
||||
Assert.IsTrue(range.IsInRange(percentage));
|
||||
|
||||
var result = profile.CalculateLineItemPayout(goal, actual, _nonOverriddenDateTime, fromPercentage);
|
||||
Assert.AreEqual(expectedPay, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Payout_All_Test()
|
||||
{
|
||||
var payoutProfiles = PayoutProfile.PayoutProfiles;
|
||||
var testInputs = new[]
|
||||
{
|
||||
new PayoutProfileCalculateTestInput(Product.Mortgage, Role.BM, PayoutType.Department,
|
||||
payoutProfiles.Find(payout => payout.Id == 1), 10, 15, 325, 1.5),
|
||||
new PayoutProfileCalculateTestInput(Product.Mortgage, Role.ABM, PayoutType.Department,
|
||||
payoutProfiles.Find(payout => payout.Id == 2), 8, 10, 175, 1.25),
|
||||
new PayoutProfileCalculateTestInput(Product.Mortgage, Role.MSCTeamLead, PayoutType.Department,
|
||||
payoutProfiles.Find(payout => payout.Id == 5), 8, 10, 75, 1.25),
|
||||
new PayoutProfileCalculateTestInput(Product.Mortgage, Role.MSCTeamLead, PayoutType.Personal,
|
||||
payoutProfiles.Find(payout => payout.Id == 4), 8, 10, 150, 1.25),
|
||||
new PayoutProfileCalculateTestInput(Product.Vehicle, Role.BM, PayoutType.Department,
|
||||
payoutProfiles.Find(payout => payout.Id == 6), 10, 10, 125, 1.0),
|
||||
new PayoutProfileCalculateTestInput(Product.Vehicle, Role.PFO, PayoutType.Personal,
|
||||
payoutProfiles.Find(payout => payout.Id == 8), 4, 3, 25, 0.75),
|
||||
// You can't test GAP here, it doesn't pay out like that. @see GapPayoutStrategy
|
||||
};
|
||||
|
||||
foreach (var testInput in testInputs)
|
||||
{
|
||||
var profile = PayoutProfile.LookupProfile(testInput.Product, testInput.Role, testInput.Type);
|
||||
Assert.NotNull(profile);
|
||||
Assert.AreEqual(profile, testInput.ExpectedProfile);
|
||||
Assert.AreEqual(profile.Product, testInput.Product);
|
||||
Assert.IsTrue(profile.Roles.Contains(testInput.Role));
|
||||
|
||||
double percentage = testInput.Actual / (double)testInput.Goal;
|
||||
Assert.AreEqual(testInput.ExpectedPercentage, percentage);
|
||||
|
||||
var range = profile.FindPayoutRange(percentage, _nonOverriddenDateTime);
|
||||
Assert.IsTrue(range.IsInRange(percentage));
|
||||
var result = profile.CalculateLineItemPayout(testInput.Goal, testInput.Actual, _nonOverriddenDateTime);
|
||||
Assert.AreEqual(testInput.ExpectedPay, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LCU.Api.Internal.FTPLib" Version="2.1.0" />
|
||||
<PackageReference Include="LCU.Library.Internal.ApiResponse" Version="3.4.1" />
|
||||
<PackageReference Include="LCU.Library.Internal.CoreApiWrapperModel" Version="2.20.0" />
|
||||
<PackageReference Include="LCU.Library.Internal.Logging" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.2" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
|
||||
<PackageReference Include="TimeZoneConverter" Version="6.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Services\TestData\GoalDispersalServiceTestData.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Remove="Services\DispersalStrategy\DispersalStrategyServiceTestData.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Services\DispersalStrategy\DispersalStrategyServiceTestData.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Remove="Services\Allied\SalesByEmployee.csv" />
|
||||
<None Remove="Services\Action\Action_IndirectVehicleLoanSales.csv" />
|
||||
<Content Include="Services\Action\Action_IndirectVehicleLoanSales.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Remove="Services\Action\Action_CreditCardPersonal.csv" />
|
||||
<Content Include="Services\Action\Action_CreditCardPersonal.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Remove="Services\Allied\SalesWithCancellationsByEmployee.csv" />
|
||||
<Content Include="Services\Allied\SalesWithCancellationsByEmployee.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LCU.API.Internal.Operations.IncentiveApi\LCU.API.Internal.Operations.IncentiveApi.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models
|
||||
{
|
||||
public class DepartmentGoalsTest
|
||||
{
|
||||
[Test]
|
||||
public void ApplyGoals_Basic()
|
||||
{
|
||||
var goals = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Vehicle,
|
||||
DepartmentId = 55,
|
||||
Value = 1,
|
||||
StartDate = DateTime.Today
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 55,
|
||||
Value = 34,
|
||||
StartDate = DateTime.Today
|
||||
}
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Role = Role.Admin
|
||||
}
|
||||
}
|
||||
};
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
var departmentGoals = new DepartmentGoals(55, DateTime.Now.Year);
|
||||
Assert.NotNull(departmentGoals.MonthlyGoals);
|
||||
Assert.AreEqual(12, departmentGoals.MonthlyGoals.Length);
|
||||
|
||||
Assert.AreEqual(0,departmentGoals.MonthlyGoals[DateTime.Today.Month-1].ProductGoals[Product.Vehicle] );
|
||||
Assert.AreEqual(0,departmentGoals.MonthlyGoals[DateTime.Today.Month-1].ProductGoals[Product.CheckCard] );
|
||||
departmentGoals.ApplyAll(goals);
|
||||
Assert.AreEqual(1,departmentGoals.MonthlyGoals[DateTime.Today.Month-1].ProductGoals[Product.Vehicle] );
|
||||
Assert.AreEqual(34,departmentGoals.MonthlyGoals[DateTime.Today.Month-1].ProductGoals[Product.CheckCard] );
|
||||
}
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models
|
||||
{
|
||||
public class EmployeeGoalTest
|
||||
{
|
||||
[Test]
|
||||
public void ApplyGoals_Basic()
|
||||
{
|
||||
var goals = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Vehicle,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11771",
|
||||
Value = 1
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11771",
|
||||
Value = 34
|
||||
},
|
||||
// This user shouldn't have this goal, but they do...
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Value = 44
|
||||
},
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55
|
||||
}
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
var employeeGoals = new EmployeeGoals(user, range);
|
||||
Assert.NotNull(employeeGoals.Departments);
|
||||
Assert.AreEqual(1, employeeGoals.Departments.Count);
|
||||
|
||||
Assert.AreEqual(0,employeeGoals.Goals[55].ProductGoals[Product.Vehicle]);
|
||||
Assert.AreEqual(0,employeeGoals.Goals[55].ProductGoals[Product.CheckCard]);
|
||||
employeeGoals.ApplyAll(goals);
|
||||
Assert.AreEqual(1,employeeGoals.Goals[55].ProductGoals[Product.Vehicle]);
|
||||
Assert.AreEqual(34,employeeGoals.Goals[55].ProductGoals[Product.CheckCard]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmployeeGoals_CreatesGoalsForDepartmentsAssignedInRange()
|
||||
{
|
||||
var deparmentBeforeRange = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2020, 12, 1),
|
||||
EndDate = new DateTime(2020, 12, 31)
|
||||
};
|
||||
|
||||
var departmentAfterRange = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 2,
|
||||
StartDate = new DateTime(2021, 3, 1),
|
||||
EndDate = new DateTime(2021, 3, 31)
|
||||
};
|
||||
|
||||
var departmentInRange = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 3,
|
||||
StartDate = new DateTime(2021, 2, 1),
|
||||
EndDate = new DateTime(2021, 2, 28)
|
||||
};
|
||||
|
||||
var departmentCurrentlyAssigned = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 4,
|
||||
StartDate = new DateTime(2020, 1, 1),
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
deparmentBeforeRange,
|
||||
departmentAfterRange,
|
||||
departmentCurrentlyAssigned,
|
||||
departmentInRange
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
|
||||
var employeeGoals = new EmployeeGoals(user, range);
|
||||
|
||||
Assert.AreEqual(2, employeeGoals.Departments.Count);
|
||||
Assert.IsFalse(employeeGoals.Departments.Contains(deparmentBeforeRange));
|
||||
Assert.IsFalse(employeeGoals.Departments.Contains(departmentAfterRange));
|
||||
Assert.IsTrue(employeeGoals.Departments.Contains(departmentInRange));
|
||||
Assert.IsTrue(employeeGoals.Departments.Contains(departmentCurrentlyAssigned));
|
||||
}
|
||||
}
|
||||
}
|
||||
+313
@@ -0,0 +1,313 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models
|
||||
{
|
||||
public class EmployeeProgressTest
|
||||
{
|
||||
[Test]
|
||||
public void ApplyProgress_Basic()
|
||||
{
|
||||
var activity = new List<Activity>()
|
||||
{
|
||||
new Activity()
|
||||
{
|
||||
Id = 5,
|
||||
Product = Product.Mortgage,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountBalance = 5100.25
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 5,
|
||||
Product = Product.Vehicle,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
IsDebtProtectionEligible = true,
|
||||
DebtProtectionAddDate = DateTime.Today,
|
||||
AccountBalance = 5100.25
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 6,
|
||||
Product = Product.Mortgage,
|
||||
State = ActivityState.Rejected,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountBalance = 7100.75
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 55,
|
||||
Product = Product.CheckCard,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 56,
|
||||
Product = Product.CheckCard,
|
||||
State = ActivityState.Transferred,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 57,
|
||||
Product = Product.ATMCard,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale
|
||||
}
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Role = Role.Admin
|
||||
}
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021, 1, 2021, 2);
|
||||
|
||||
var employeeProgress = new EmployeeProgress(user, range, new List<IPayoutRule>());
|
||||
Assert.NotNull(employeeProgress.Departments);
|
||||
Assert.AreEqual(1, employeeProgress.Departments.Count);
|
||||
|
||||
Assert.AreEqual(0, employeeProgress.Progress[55].ProductActivity[Product.Mortgage]);
|
||||
Assert.AreEqual(0, employeeProgress.Progress[55].ProductActivity[Product.CheckCard]);
|
||||
employeeProgress.ApplyAll(activity);
|
||||
Assert.AreEqual(5100.25, employeeProgress.Progress[55].ProductActivity[Product.Mortgage]);
|
||||
Assert.AreEqual(1, employeeProgress.Progress[55].ProductActivity[Product.CheckCard]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ApplyProgress_GAP_DP()
|
||||
{
|
||||
var activity = new List<Activity>()
|
||||
{
|
||||
new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
Product = Product.Mortgage,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountBalance = 5100.25
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
Product = Product.Vehicle,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
IsDebtProtectionEligible = true,
|
||||
DebtProtectionAddDate = null,
|
||||
AccountBalance = 5100.25
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 3,
|
||||
Product = Product.DebtProtectionEligibleLoan,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
IsDebtProtectionEligible = true,
|
||||
DebtProtectionAddDate = null,
|
||||
AccountBalance = 5100.25
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 5,
|
||||
Product = Product.Vehicle,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
IsDebtProtectionEligible = true,
|
||||
DebtProtectionAddDate = DateTime.Today,
|
||||
AccountBalance = 5100.25
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 6,
|
||||
Product = Product.Mortgage,
|
||||
State = ActivityState.Rejected,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountBalance = 7100.75
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 55,
|
||||
Product = Product.CheckCard,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 56,
|
||||
Product = Product.CheckCard,
|
||||
State = ActivityState.Transferred,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 57,
|
||||
Product = Product.ATMCard,
|
||||
State = ActivityState.Accepted,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale
|
||||
}
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Role = Role.Admin
|
||||
}
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021, 1, 2021, 2);
|
||||
|
||||
var employeeProgress = new EmployeeProgress(user, range, new List<IPayoutRule>());
|
||||
Assert.NotNull(employeeProgress.Departments);
|
||||
Assert.AreEqual(1, employeeProgress.Departments.Count);
|
||||
|
||||
Assert.AreEqual(0, employeeProgress.Progress[55].ProductActivity[Product.DebtProtectionEligibleLoan]);
|
||||
employeeProgress.ApplyAll(activity);
|
||||
Assert.AreEqual(1, employeeProgress.Progress[55].ProductActivity[Product.DebtProtectionEligibleLoan]);
|
||||
Assert.AreEqual(3, employeeProgress.Progress[55].ProductOther[Product.DebtProtectionEligibleLoan]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmployeeProgress_CreatesProgressForDepartmentsAssignedInRange()
|
||||
{
|
||||
var departmentBeforeRange = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2020, 12, 1),
|
||||
EndDate = new DateTime(2020, 12, 31),
|
||||
Role = Role.Admin
|
||||
};
|
||||
|
||||
var departmentAfterRange = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 2,
|
||||
StartDate = new DateTime(2021, 3, 1),
|
||||
EndDate = new DateTime(2021, 3, 31),
|
||||
Role = Role.Admin
|
||||
};
|
||||
|
||||
var departmentInRange = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 3,
|
||||
StartDate = new DateTime(2021, 2, 1),
|
||||
EndDate = new DateTime(2021, 2, 28),
|
||||
Role = Role.Admin
|
||||
};
|
||||
|
||||
var departmentCurrentlyAssigned = new UserDepartment()
|
||||
{
|
||||
DepartmentId = 4,
|
||||
StartDate = new DateTime(2020, 1, 1),
|
||||
EndDate = null,
|
||||
Role = Role.Admin
|
||||
};
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
departmentBeforeRange,
|
||||
departmentAfterRange,
|
||||
departmentCurrentlyAssigned,
|
||||
departmentInRange
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021, 1, 2021, 2);
|
||||
|
||||
var employeeProgress = new EmployeeProgress(user, range, new List<IPayoutRule>());
|
||||
|
||||
Assert.AreEqual(2, employeeProgress.Departments.Count);
|
||||
Assert.IsFalse(employeeProgress.Departments.Contains(departmentBeforeRange));
|
||||
Assert.IsFalse(employeeProgress.Departments.Contains(departmentAfterRange));
|
||||
Assert.IsTrue(employeeProgress.Departments.Contains(departmentInRange));
|
||||
Assert.IsTrue(employeeProgress.Departments.Contains(departmentCurrentlyAssigned));
|
||||
}
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models.ExternalActivity
|
||||
{
|
||||
public class ExternalActivityTests
|
||||
{
|
||||
private NewLoanSaleActivity externalActivity = new NewLoanSaleActivity();
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
externalActivity.ActivityNbr = 100;
|
||||
externalActivity.ActivityDateTime = DateTime.Parse("2021-09-28T21:32:38");
|
||||
externalActivity.SubjectAccountNbr = 555;
|
||||
externalActivity.OriginatingPersonNbr = 10;
|
||||
externalActivity.ActivityTypeCode = "ADAC";
|
||||
externalActivity.MajorAccountType = "CNS";
|
||||
externalActivity.MinorAccountType = "DV01";
|
||||
externalActivity.AssociateFirst = "Bruce";
|
||||
externalActivity.AssociateMiddleInit = null;
|
||||
externalActivity.AssociateLast = "Willis";
|
||||
externalActivity.TaxPersonNbr = "1258";
|
||||
externalActivity.TaxOrgNbr = null;
|
||||
externalActivity.AccountContractDate = DateTime.Parse("2021-09-28T00:00:00");
|
||||
externalActivity.CurrentAccountStatus = "ACT";
|
||||
externalActivity.BranchOrgNbr = 1119;
|
||||
externalActivity.BranchOrgName = "Oak Creek Branch";
|
||||
externalActivity.EmployeeEmail = "[email protected]";
|
||||
externalActivity.LoanSourceCode = "NEW";
|
||||
externalActivity.LoanAmount = 23000;
|
||||
externalActivity.DebtProtectionEffectiveDate = DateTime.Parse("2021-09-29T00:00:00");
|
||||
externalActivity.YoungestBirthdateOnLoan = DateTime.Parse("1999-04-01T00:00:00");
|
||||
externalActivity.HasOrgRoles = 0;
|
||||
}
|
||||
|
||||
[TestCase("BE21", 0, null, false, false)]
|
||||
[TestCase("DV01", 1, null, false, true)]
|
||||
[TestCase("DV01", 0, "12345", false, true)]
|
||||
[TestCase("DV02", 0, null, true, true)]
|
||||
[TestCase("DV03", 0, null, true, true)]
|
||||
[TestCase("DV04", 0, null, true, true)]
|
||||
[TestCase("DV05", 0, null, true, true)]
|
||||
[TestCase("DV06", 0, null, true, true)]
|
||||
[TestCase("DV07", 0, null, true, true)]
|
||||
[TestCase("DV08", 0, null, true, true)]
|
||||
[TestCase("SC01", 0, null, true, false)]
|
||||
[TestCase("SC02", 0, null, true, false)]
|
||||
[TestCase("SG01", 0, null, true, false)]
|
||||
[TestCase("NotReal", 0, null, false, true)]
|
||||
[TestCase("FE01", 0, null, false, false)]
|
||||
public void ExternalLoanSaleActivity_IsDebtProtectionEligible_OK(string minorAccountType, int hasOrgRoles, string taxOrgNbr,
|
||||
bool result, bool isGap)
|
||||
{
|
||||
externalActivity.MinorAccountType = minorAccountType;
|
||||
externalActivity.TaxOrgNbr = taxOrgNbr;
|
||||
externalActivity.HasOrgRoles = hasOrgRoles;
|
||||
|
||||
var mapped = externalActivity.MapToActivity();
|
||||
Assert.AreEqual(result, mapped.Detail.IsDebtProtectionEligible);
|
||||
Assert.AreEqual(isGap, mapped.Detail.IsGapInsuranceEligible);
|
||||
}
|
||||
|
||||
|
||||
[TestCase("FE01", Product.Mortgage, false)]
|
||||
[TestCase("FE02", Product.Mortgage, false)]
|
||||
[TestCase("FLML", Product.Mortgage, false)]
|
||||
[TestCase("MF01", Product.Mortgage, false)]
|
||||
[TestCase("FNMA", Product.FirstMortgageReferral, false)]
|
||||
[TestCase("fnma", Product.FirstMortgageReferral, false)]
|
||||
[TestCase("FRML", Product.FirstMortgageReferral, false)]
|
||||
[TestCase("frMl", Product.FirstMortgageReferral, false)]
|
||||
[TestCase("mJ30", Product.FirstMortgageReferral, false)]
|
||||
[TestCase("MJ30", Product.FirstMortgageReferral, false)]
|
||||
[TestCase("DL01",Product.Vehicle, true)]
|
||||
[TestCase("DV07",Product.Vehicle, true)]
|
||||
[TestCase("DV08",Product.Vehicle, true)]
|
||||
[TestCase("DL09",Product.Vehicle, true)]
|
||||
[TestCase("DV02",Product.Vehicle, true)]
|
||||
[TestCase("DV03",Product.Vehicle, true)]
|
||||
[TestCase("DV04",Product.Vehicle, true)]
|
||||
[TestCase("DV05",Product.Vehicle, true)]
|
||||
[TestCase("DV06",Product.Vehicle, true)]
|
||||
[TestCase("DL08",Product.Vehicle, true)]
|
||||
[TestCase("DV01",Product.Vehicle, true)]
|
||||
[TestCase("DL13",Product.Vehicle, true)]
|
||||
[TestCase("DL14",Product.Vehicle, true)]
|
||||
[TestCase("DL16",Product.Vehicle, true)]
|
||||
[TestCase("DL10",Product.Vehicle, true)]
|
||||
[TestCase("DL12",Product.Vehicle, true)]
|
||||
[TestCase("DL11",Product.Vehicle, true)]
|
||||
[TestCase("DL07",Product.Vehicle, true)]
|
||||
[TestCase("DL06",Product.Vehicle, true)]
|
||||
[TestCase("SC01",Product.DebtProtectionEligibleLoan, false)]
|
||||
[TestCase("SC02",Product.DebtProtectionEligibleLoan, false)]
|
||||
[TestCase("SG01",Product.DebtProtectionEligibleLoan, false)]
|
||||
|
||||
public void NewLoanActivity_MapActivity_Product(string minorAccountType, Product expectedProduct, bool isGap)
|
||||
{
|
||||
externalActivity.MinorAccountType = minorAccountType;
|
||||
var mapped = externalActivity.MapToActivity();
|
||||
Assert.AreEqual(expectedProduct, mapped.Product);
|
||||
Assert.AreEqual(isGap, externalActivity.IsGapInsuranceEligible());
|
||||
}
|
||||
|
||||
[TestCase("CC Balance Transfer", Product.CreditCardBalanceTransfer, 0)]
|
||||
[TestCase("ATM Card", Product.ATMCard, 0)]
|
||||
[TestCase("Check Card Referral", Product.CheckCard, 0)]
|
||||
[TestCase("Checking Referral", Product.NewChecking, 0)]
|
||||
[TestCase("Mortgage Referral", Product.Mortgage, 0)]
|
||||
[TestCase("Direct Deposit", Product.DirectDeposit, 0)]
|
||||
[TestCase("LIC Referral", Product.LIC, 1)]
|
||||
[TestCase("First Mortgage Referral", Product.FirstMortgageReferral, 0)]
|
||||
[TestCase("eStatement Referral", Product.eStatement, 0)]
|
||||
public void NewActivityManagerReferral_MapActivity_Product(string campaign, Product expectedProduct, int isFinalStation)
|
||||
{
|
||||
var amr = new NewActivityManagerReferral();
|
||||
amr.Campaign = campaign;
|
||||
amr.IsFinalStation = isFinalStation;
|
||||
var mapped = amr.MapToActivity();
|
||||
Assert.AreEqual(expectedProduct, mapped.Product);
|
||||
}
|
||||
|
||||
[TestCase("ATM", Product.ATMCard)]
|
||||
[TestCase("DB01", Product.CheckCard)]
|
||||
public void NewCardSaleActivity_MapActivity_Product(string cardType, Product expectedProduct)
|
||||
{
|
||||
var amr = new NewAtmCheckCardActivity();
|
||||
amr.CardType = cardType;
|
||||
var mapped = amr.MapToActivity();
|
||||
Assert.AreEqual(expectedProduct, mapped.Product);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExternalLoanSaleActivity_IsDebtProtectionEligible_AgeCalc_OK()
|
||||
{
|
||||
externalActivity.YoungestBirthdateOnLoan = DateTime.Now.AddYears(-70).AddDays(-1);
|
||||
var mapped = externalActivity.MapToActivity();
|
||||
Assert.AreEqual(false, mapped.Detail.IsDebtProtectionEligible);
|
||||
|
||||
externalActivity.YoungestBirthdateOnLoan = DateTime.Now.AddYears(-68).AddDays(-1);
|
||||
mapped = externalActivity.MapToActivity();
|
||||
Assert.AreEqual(true, mapped.Detail.IsDebtProtectionEligible);
|
||||
|
||||
externalActivity.YoungestBirthdateOnLoan = DateTime.Now.AddYears(-22).AddDays(-1);
|
||||
mapped = externalActivity.MapToActivity();
|
||||
Assert.AreEqual(true, mapped.Detail.IsDebtProtectionEligible);
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.GoalDispersal;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models
|
||||
{
|
||||
public class GoalDispersalReceiptTest
|
||||
{
|
||||
[Test]
|
||||
public void GoalDispersalReceiptItem_Does_Not_Require_Name()
|
||||
{
|
||||
var GDR = new GoalDispersalReceipt(10, GoalDispersalStrategy.ExtrapolateFromExistingGoals);
|
||||
GDR.AddNewDispersalError(GoalDispersalError.ErrorsDuringDisperse, "1", "ERROR");
|
||||
GDR.AddNewDispersalError(GoalDispersalError.ErrorsDuringDisperse, "2", "ERROR", null);
|
||||
var obj = new {name = "batman"};
|
||||
|
||||
var testFunc = new Func<string, string>((string name) =>
|
||||
{
|
||||
if (name == "batman") return null;
|
||||
return "name";
|
||||
});
|
||||
|
||||
GDR.AddNewDispersalError(GoalDispersalError.ErrorsDuringDisperse, "3", "ERROR", obj.name);
|
||||
GDR.AddNewDispersalError(GoalDispersalError.ErrorsDuringDisperse, "4", "ERROR", testFunc(obj.name));
|
||||
Assert.AreEqual(4,GDR.GoalDispersalErrors.Count);
|
||||
Assert.AreEqual(3, GDR.GoalDispersalErrors.Count(x => x.EmployeeName == null));
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models
|
||||
{
|
||||
public class PayDayTest
|
||||
{
|
||||
[Test]
|
||||
public void PayDay_Predict_2()
|
||||
{
|
||||
var service = new DateTimeService();
|
||||
var date = service.getNextBonusPeriod(new DateTime(2021,10,3));
|
||||
Assert.AreEqual("10/15/2021", date.ToString("MM/dd/yyyy"));
|
||||
date = service.getNextBonusPeriod(new DateTime(2021,10,22));
|
||||
Assert.AreEqual("11/26/2021", date.ToString("MM/dd/yyyy"));
|
||||
date = service.getNextBonusPeriod(new DateTime(2022,4,17));
|
||||
Assert.AreEqual("05/27/2022", date.ToString("MM/dd/yyyy"));
|
||||
}
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models
|
||||
{
|
||||
public class PersonnelGoalsTest
|
||||
{
|
||||
[Test]
|
||||
public void ApplyGoals_Basic()
|
||||
{
|
||||
var goals = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Vehicle,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11771",
|
||||
Value = 1
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11771",
|
||||
Value = 34
|
||||
},
|
||||
// This department shouldn't have this goal, but they do...
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11772",
|
||||
Value = 44
|
||||
},
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55
|
||||
}
|
||||
}
|
||||
};
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
var personnelGoals = new PersonnelGoals(55, DateTime.Now.Year, DateTime.Now.Month, users);
|
||||
Assert.NotNull(personnelGoals.Personnel);
|
||||
Assert.AreEqual(1, personnelGoals.Personnel.Count);
|
||||
|
||||
Assert.AreEqual(0,personnelGoals.Goals["11771"].ProductGoals[Product.Vehicle] );
|
||||
Assert.AreEqual(0,personnelGoals.Goals["11771"].ProductGoals[Product.CheckCard] );
|
||||
personnelGoals.ApplyAll(goals);
|
||||
Assert.AreEqual(1,personnelGoals.Goals["11771"].ProductGoals[Product.Vehicle]);
|
||||
Assert.AreEqual(34,personnelGoals.Goals["11771"].ProductGoals[Product.CheckCard]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models
|
||||
{
|
||||
public class ProductDetailTest
|
||||
{
|
||||
[Test]
|
||||
public void AssertProductDetailList()
|
||||
{
|
||||
// Ensure every product has a detail
|
||||
foreach (Product product in Enum.GetValues(typeof(Product)))
|
||||
{
|
||||
Assert.NotNull(ProductDetail.DetailsForProduct(product));
|
||||
}
|
||||
|
||||
// Ensure there isn't more than one detail per product.
|
||||
var checkList = new Dictionary<Product, ProductDetail>();
|
||||
foreach (var detail in ProductDetail.ProductDetails)
|
||||
{
|
||||
Assert.False(checkList.ContainsKey(detail.Product));
|
||||
checkList[detail.Product] = detail;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Models
|
||||
{
|
||||
public class SettingsTest
|
||||
{
|
||||
private Settings _settings;
|
||||
|
||||
[Test]
|
||||
public void Constructs_OrganizationSet_OK()
|
||||
{
|
||||
_settings = new Settings();
|
||||
|
||||
Assert.AreEqual(_settings.OrganizationSet.Count, 1);
|
||||
Assert.Contains("MEMEXP", _settings.OrganizationSet.Keys);
|
||||
Assert.Contains("Member Experience", _settings.OrganizationSet.Values);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructs_BusinessLineSet_OK()
|
||||
{
|
||||
_settings = new Settings();
|
||||
|
||||
Assert.AreEqual(_settings.BusinessLines.Count, 3);
|
||||
Assert.Contains(BusinessLine.Operations, _settings.BusinessLines);
|
||||
Assert.Contains(BusinessLine.BranchOperations, _settings.BusinessLines);
|
||||
Assert.Contains(BusinessLine.MemberServices, _settings.BusinessLines);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructs_RegionSet_OK()
|
||||
{
|
||||
_settings = new Settings();
|
||||
|
||||
Assert.Contains(Region.North, _settings.Regions);
|
||||
Assert.Contains(Region.South, _settings.Regions);
|
||||
Assert.Contains(Region.East, _settings.Regions);
|
||||
Assert.Contains(Region.West, _settings.Regions);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructs_PermissionSet_OK()
|
||||
{
|
||||
_settings = new Settings();
|
||||
|
||||
var permissionCount = Permission.GetAllPermissions().Count;
|
||||
Assert.AreEqual(permissionCount, _settings.Permissions.Count);
|
||||
Assert.Contains(Permission.Unknown, _settings.Permissions);
|
||||
Assert.Contains(Permission.EligibleForReferrals, _settings.Permissions);
|
||||
Assert.Contains(Permission.HaveSalesGoals, _settings.Permissions);
|
||||
Assert.Contains(Permission.ViewDashboard, _settings.Permissions);
|
||||
Assert.Contains(Permission.ViewPerformanceForDepartment, _settings.Permissions);
|
||||
Assert.Contains(Permission.ViewPerformanceForRegion, _settings.Permissions);
|
||||
Assert.Contains(Permission.ViewPerformanceForBusinessLine, _settings.Permissions);
|
||||
Assert.Contains(Permission.ManageDepartmentGoals, _settings.Permissions);
|
||||
Assert.Contains(Permission.ManageCommissions, _settings.Permissions);
|
||||
Assert.Contains(Permission.CreateActivity, _settings.Permissions);
|
||||
Assert.Contains(Permission.AssignPermissionsToAssociates, _settings.Permissions);
|
||||
Assert.Contains(Permission.AssignAssociatesToDepartment, _settings.Permissions);
|
||||
Assert.Contains(Permission.TransferActivitiesBetweenDepartments, _settings.Permissions);
|
||||
Assert.Contains(Permission.TransferActivitiesBetweenAssociates, _settings.Permissions);
|
||||
Assert.Contains(Permission.GeneratePayoutFiles, _settings.Permissions);
|
||||
Assert.Contains(Permission.AssignRegionalManager, _settings.Permissions);
|
||||
Assert.Contains(Permission.AccessTestEnvironments, _settings.Permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class AccountingRepositoryTest
|
||||
{
|
||||
private IAccountingRepository _repository;
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var mockDateTime = new DateTimeService();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
||||
_repository = new AccountingRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_Flow_Test()
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var saved = await _repository.GetAccountingSummaryAsync(today);
|
||||
Assert.IsNull(saved);
|
||||
|
||||
var deptNames = new Dictionary<int, string>();
|
||||
deptNames.Add(1, "Dept1");
|
||||
|
||||
var lineItem = new PayoutLineItem(Product.Mortgage, PayoutProfile.BMMortgage, new Goal(),
|
||||
100m, new List<Activity>(), today);
|
||||
lineItem.DepartmentId = 1;
|
||||
lineItem.PayoutTotal = 1000;
|
||||
List<PayoutLineItem> allNewPayouts = new List<PayoutLineItem>()
|
||||
{
|
||||
lineItem
|
||||
};
|
||||
var summary = new AccountingSummary(today);
|
||||
summary.Apply(allNewPayouts, deptNames);
|
||||
|
||||
var newId = await _repository.SaveAccountingSummaryAsync(summary);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
saved = await _repository.GetAccountingSummaryAsync(today);
|
||||
Assert.NotNull(saved);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1947
File diff suppressed because it is too large
Load Diff
+265
@@ -0,0 +1,265 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class ActivityTransferActionRepositoryTest
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private ActivityTransferActionRepository _repository;
|
||||
private Mock<IDateTime> _mockDateTime;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDateTime = new Mock<IDateTime>();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, _mockDateTime.Object);
|
||||
_repository = new ActivityTransferActionRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveTransferAsync_Basic()
|
||||
{
|
||||
_mockDateTime.SetupGet(mock => mock.Now).Returns(new DateTime(2021, 9, 10, 1, 2, 3, 456));
|
||||
|
||||
var activityToTransfer = new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
EmployeeId = "C0000",
|
||||
DepartmentId = 5,
|
||||
Product = Product.CheckCard,
|
||||
SourceId = "2",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
MemberName = "Tester 1",
|
||||
AgreementNumber = "234"
|
||||
}
|
||||
};
|
||||
_context.Add(activityToTransfer);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var activtyTransferAction = new ActivityTransferAction
|
||||
{
|
||||
Id = 0,
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 2,
|
||||
State = ActivityTransferState.Requested,
|
||||
NewActivityDepartmentId = 3,
|
||||
NewActivityEmployeeId = "C0000"
|
||||
};
|
||||
|
||||
var savedId = await _repository.SaveTransferAsync(activtyTransferAction);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _context.ActivityTransferActions.FindAsync(savedId);
|
||||
|
||||
Assert.NotNull(found);
|
||||
Assert.AreEqual(ActivityState.Accepted, found.ActivityStateBeforeTransfer);
|
||||
Assert.AreEqual(2, found.RequestedActivityId);
|
||||
Assert.AreEqual(ActivityTransferState.Requested, found.State);
|
||||
Assert.AreEqual(3, found.NewActivityDepartmentId);
|
||||
Assert.IsNull(found.NewActivityId);
|
||||
Assert.AreEqual("C0000", found.NewActivityEmployeeId);
|
||||
Assert.AreEqual(new DateTime(2021, 9, 10, 1, 2, 3, 456), found.Created);
|
||||
Assert.AreEqual("[email protected]", found.CreatedBy);
|
||||
Assert.AreEqual(UserType.Associate, found.CreatedByType);
|
||||
Assert.AreEqual(new DateTime(2021, 9, 10, 1, 2, 3, 456), found.LastUpdated);
|
||||
Assert.AreEqual("[email protected]", found.LastUpdatedBy);
|
||||
Assert.AreEqual(UserType.Associate, found.LastUpdatedByType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTransferActionById_Basic()
|
||||
{
|
||||
var activityToTransfer = new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
EmployeeId = "C0000",
|
||||
DepartmentId = 5,
|
||||
Product = Product.CheckCard,
|
||||
SourceId = "2",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
MemberName = "Tester 1",
|
||||
AgreementNumber = "234"
|
||||
}
|
||||
};
|
||||
_context.Add(activityToTransfer);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var activtyTransferAction1 = new ActivityTransferAction
|
||||
{
|
||||
Id = 1,
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 2,
|
||||
State = ActivityTransferState.Accepted,
|
||||
NewActivityDepartmentId = 3,
|
||||
NewActivityEmployeeId = "C0001"
|
||||
};
|
||||
|
||||
var activtyTransferAction2 = new ActivityTransferAction
|
||||
{
|
||||
Id = 2,
|
||||
ActivityStateBeforeTransfer = ActivityState.Rejected,
|
||||
RequestedActivityId = 2,
|
||||
State = ActivityTransferState.Requested,
|
||||
NewActivityDepartmentId = 4,
|
||||
NewActivityEmployeeId = "C0002"
|
||||
};
|
||||
_context.Add(activtyTransferAction1);
|
||||
_context.Add(activtyTransferAction2);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.GetTransferActionById(2);
|
||||
|
||||
Assert.AreEqual(2, found.Id);
|
||||
Assert.AreEqual(ActivityState.Rejected, found.ActivityStateBeforeTransfer);
|
||||
Assert.AreEqual(2, found.RequestedActivityId);
|
||||
Assert.AreEqual(ActivityTransferState.Requested, found.State);
|
||||
Assert.AreEqual(4, found.NewActivityDepartmentId);
|
||||
Assert.AreEqual("C0002", found.NewActivityEmployeeId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetRequestedTransferActionByActivityId_Basic()
|
||||
{
|
||||
var activityToTransfer = new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
EmployeeId = "C0000",
|
||||
DepartmentId = 5,
|
||||
Product = Product.CheckCard,
|
||||
SourceId = "2",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
MemberName = "Tester 1",
|
||||
AgreementNumber = "234"
|
||||
}
|
||||
};
|
||||
_context.Add(activityToTransfer);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var activtyTransferAction1 = new ActivityTransferAction
|
||||
{
|
||||
Id = 1,
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 2,
|
||||
State = ActivityTransferState.Accepted,
|
||||
NewActivityDepartmentId = 3,
|
||||
NewActivityEmployeeId = "C0001"
|
||||
};
|
||||
|
||||
var activtyTransferAction2 = new ActivityTransferAction
|
||||
{
|
||||
Id = 2,
|
||||
ActivityStateBeforeTransfer = ActivityState.Rejected,
|
||||
RequestedActivityId = 2,
|
||||
State = ActivityTransferState.Requested,
|
||||
NewActivityDepartmentId = 4,
|
||||
NewActivityEmployeeId = "C0002"
|
||||
};
|
||||
_context.Add(activtyTransferAction1);
|
||||
_context.Add(activtyTransferAction2);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.GetRequestedTransferActionByActivityId(2);
|
||||
|
||||
Assert.AreEqual(2, found.Id);
|
||||
Assert.AreEqual(ActivityState.Rejected, found.ActivityStateBeforeTransfer);
|
||||
Assert.AreEqual(2, found.RequestedActivityId);
|
||||
Assert.AreEqual(ActivityTransferState.Requested, found.State);
|
||||
Assert.AreEqual(4, found.NewActivityDepartmentId);
|
||||
Assert.AreEqual("C0002", found.NewActivityEmployeeId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActiveTransfersByState_Basic()
|
||||
{
|
||||
var activityToTransfer = new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
EmployeeId = "C0000",
|
||||
DepartmentId = 5,
|
||||
Product = Product.CheckCard,
|
||||
SourceId = "2",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
MemberName = "Tester 1",
|
||||
AgreementNumber = "234"
|
||||
}
|
||||
};
|
||||
_context.Add(activityToTransfer);
|
||||
var activityToTransfer2 = new Activity()
|
||||
{
|
||||
Id = 3,
|
||||
EmployeeId = "C0000",
|
||||
DepartmentId = 5,
|
||||
Product = Product.CheckCard,
|
||||
SourceId = "3",
|
||||
State = ActivityState.PendingReferral,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
MemberName = "Tester 1",
|
||||
AgreementNumber = "234"
|
||||
}
|
||||
};
|
||||
_context.Add(activityToTransfer);
|
||||
_context.Add(activityToTransfer2);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var activityTransferAction1 = new ActivityTransferAction
|
||||
{
|
||||
Id = 1,
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 2,
|
||||
State = ActivityTransferState.Requested,
|
||||
NewActivityDepartmentId = 3,
|
||||
NewActivityEmployeeId = "C0001",
|
||||
RequestedActivity = activityToTransfer
|
||||
};
|
||||
|
||||
var activityTransferAction2 = new ActivityTransferAction
|
||||
{
|
||||
Id = 2,
|
||||
ActivityStateBeforeTransfer = ActivityState.PendingReferral,
|
||||
RequestedActivityId = 3,
|
||||
State = ActivityTransferState.Requested,
|
||||
NewActivityDepartmentId = 4,
|
||||
NewActivityEmployeeId = "C0002",
|
||||
RequestedActivity = activityToTransfer2
|
||||
};
|
||||
_context.Add(activityTransferAction1);
|
||||
_context.Add(activityTransferAction2);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.GetActiveTransfersForStateAsync(ActivityState.Accepted);
|
||||
|
||||
Assert.AreEqual(1, found.Count());
|
||||
Assert.AreEqual(1, found.First().Id);
|
||||
Assert.AreEqual(ActivityState.Accepted, found.First().ActivityStateBeforeTransfer);
|
||||
}
|
||||
}
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class CommissionRepositoryTest
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private CommissionRepository _repository;
|
||||
private Mock<IDateTime> _mockDateTime;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDateTime = new Mock<IDateTime>();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, _mockDateTime.Object);
|
||||
_repository = new CommissionRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindExistingCommission_FoundById()
|
||||
{
|
||||
var commission = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.NewChecking,
|
||||
RatePerProduct = 2,
|
||||
Role = Role.Teller
|
||||
};
|
||||
await _repository.SaveCommission(commission);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.FindExistingCommission(1);
|
||||
|
||||
Assert.NotNull(found);
|
||||
Assert.AreEqual(1, found.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindExistingCommission_FoundByRole()
|
||||
{
|
||||
var commission = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.NewChecking,
|
||||
RatePerProduct = 2,
|
||||
Role = Role.Teller
|
||||
};
|
||||
await _repository.SaveCommission(commission);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.FindProductCommissions(Role.Teller);
|
||||
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found);
|
||||
Assert.AreEqual(1, found.First().Id);
|
||||
Assert.AreEqual(Role.Teller, found.First().Role);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindExistingCommission_NotFoundById()
|
||||
{
|
||||
var commission = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.NewChecking,
|
||||
RatePerProduct = 2,
|
||||
Role = Role.Teller
|
||||
};
|
||||
await _repository.SaveCommission(commission);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.FindExistingCommission(2);
|
||||
|
||||
Assert.Null(found);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindExistingCommission_FoundByRoleAndProduct()
|
||||
{
|
||||
var commission = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.NewChecking,
|
||||
RatePerProduct = 2,
|
||||
Role = Role.Teller
|
||||
};
|
||||
await _repository.SaveCommission(commission);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.FindExistingCommission(Role.Teller, Product.NewChecking);
|
||||
|
||||
Assert.NotNull(found);
|
||||
Assert.AreEqual(Role.Teller, found.Role);
|
||||
Assert.AreEqual(Product.NewChecking, found.Product);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindExistingCommission_NotFoundByRoleAndProduct()
|
||||
{
|
||||
var commission = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.NewChecking,
|
||||
RatePerProduct = 2,
|
||||
Role = Role.Teller
|
||||
};
|
||||
await _repository.SaveCommission(commission);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.FindExistingCommission(Role.Admin, Product.NewChecking);
|
||||
|
||||
Assert.Null(found);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveCommission_Basic()
|
||||
{
|
||||
_mockDateTime.SetupGet(mock => mock.Now).Returns(new DateTime(2021, 7, 9, 1, 2, 3, 456));
|
||||
var commission = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.ATMCard,
|
||||
RatePerProduct = 3,
|
||||
Role = Role.BM
|
||||
};
|
||||
await _repository.SaveCommission(commission);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.FindExistingCommission(1);
|
||||
|
||||
Assert.NotNull(found);
|
||||
Assert.AreEqual(1, found.Id);
|
||||
Assert.AreEqual(Product.ATMCard, found.Product);
|
||||
Assert.AreEqual(3, found.RatePerProduct);
|
||||
Assert.AreEqual(Role.BM, found.Role);
|
||||
Assert.AreEqual(new DateTime(2021, 7, 9, 1, 2, 3, 456), found.Created);
|
||||
Assert.AreEqual("[email protected]", found.CreatedBy);
|
||||
Assert.AreEqual(UserType.Associate, found.CreatedByType);
|
||||
Assert.AreEqual(new DateTime(2021, 7, 9, 1, 2, 3, 456), found.LastUpdated);
|
||||
Assert.AreEqual("[email protected]", found.LastUpdatedBy);
|
||||
Assert.AreEqual(UserType.Associate, found.LastUpdatedByType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetCommissionsAsync_Basic()
|
||||
{
|
||||
var commission1 = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.NewChecking,
|
||||
RatePerProduct = 2,
|
||||
Role = Role.Teller
|
||||
};
|
||||
var commission2 = new Commission
|
||||
{
|
||||
Id = 2,
|
||||
Product = Product.ATMCard,
|
||||
RatePerProduct = 3,
|
||||
Role = Role.BM
|
||||
};
|
||||
await _repository.SaveCommission(commission1);
|
||||
await _repository.SaveCommission(commission2);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.GetCommissionsAsync();
|
||||
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found);
|
||||
Assert.AreEqual(2, found.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+714
@@ -0,0 +1,714 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class DeadActivityRepositoryTest
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private DeadActivityRepository _repository;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var mockDateTime = new DateTimeService();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging()
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
||||
_repository = new DeadActivityRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivitiesAsync_Paginated_OK()
|
||||
{
|
||||
var activity1 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "1",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(7))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity1);
|
||||
|
||||
var activity2 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "2",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity2);
|
||||
|
||||
var activity3 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "3",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Rejected,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity3);
|
||||
|
||||
var activity4 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "4",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Created,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(5))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity4);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
var found = await _repository.GetPagedDeadActivities(1, 3);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(3, found.Items.Count());
|
||||
Assert.AreEqual(4, found.Total);
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "4"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "1"));
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "2"));
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "3"));
|
||||
|
||||
found = await _repository.GetPagedDeadActivities(2, 3);
|
||||
Assert.AreEqual(1, found.Items.Count());
|
||||
Assert.AreEqual(4, found.Total);
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "4"));
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
|
||||
|
||||
found = await _repository.GetPagedDeadActivities(100, 3);
|
||||
Assert.AreEqual(4, found.Total);
|
||||
Assert.IsEmpty(found.Items);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDeadActivitiesByActivityProductAsync_OK()
|
||||
{
|
||||
var activity1 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "1",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-3),
|
||||
State = ActivityState.Accepted,
|
||||
LastUpdated = new DateTime(2021, 1, 4)
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
|
||||
await _repository.SaveDeadActivity(activity1);
|
||||
var activity2 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "2",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.NewChecking,
|
||||
Accepted = DateTime.Today.AddMinutes(-2),
|
||||
State = ActivityState.Accepted,
|
||||
LastUpdated = new DateTime(2021, 1, 3)
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity2);
|
||||
|
||||
var activity3 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "3",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.NewChecking,
|
||||
Accepted = DateTime.Today.AddMinutes(-1),
|
||||
State = ActivityState.Rejected,
|
||||
LastUpdated = new DateTime(2021, 1, 2)
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity3);
|
||||
|
||||
var activity4 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "4",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.NewChecking,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
LastUpdated = new DateTime(2021, 1, 1)
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity4);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var filter = new DeadActivityFilter
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 2,
|
||||
Product = new List<Product> { Product.CheckCard }
|
||||
};
|
||||
var found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(1, found.Items.Count());
|
||||
Assert.AreEqual(1, found.Total);
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDeadActivitiesByActivityTypeAsync_OK()
|
||||
{
|
||||
var activity1 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "1",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-3),
|
||||
State = ActivityState.Accepted,
|
||||
LastUpdated = new DateTime(2021, 1, 4)
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity1);
|
||||
|
||||
var activity2 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "2",
|
||||
Type = ActivityType.Referral,
|
||||
Product = Product.NewChecking,
|
||||
Accepted = DateTime.Today.AddMinutes(-2),
|
||||
State = ActivityState.Accepted,
|
||||
LastUpdated = new DateTime(2021, 1, 3)
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity2);
|
||||
|
||||
var activity3 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "3",
|
||||
Type = ActivityType.Referral,
|
||||
Product = Product.NewChecking,
|
||||
Accepted = DateTime.Today.AddMinutes(-1),
|
||||
State = ActivityState.Rejected,
|
||||
LastUpdated = new DateTime(2021, 1, 2)
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity3);
|
||||
|
||||
var activity4 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "4",
|
||||
Type = ActivityType.Referral,
|
||||
Product = Product.NewChecking,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
LastUpdated = new DateTime(2021, 1, 1)
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity4);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var filter = new DeadActivityFilter
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 2,
|
||||
Type = new List<ActivityType> { ActivityType.Sale }
|
||||
};
|
||||
var found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(1, found.Items.Count());
|
||||
Assert.AreEqual(1, found.Total);
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetFilteredDeadActivities_OK()
|
||||
{
|
||||
// You can't set last updated. So you'll get these back in reverse order you saved them.
|
||||
var activity1 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "1",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-5),
|
||||
State = ActivityState.Accepted,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(7))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity1);
|
||||
|
||||
var activity2 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "2",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-4),
|
||||
State = ActivityState.Rejected,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity2);
|
||||
|
||||
var activity3 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "3",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-3),
|
||||
State = ActivityState.Accepted,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity3);
|
||||
|
||||
var activity4 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "4",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-2),
|
||||
State = ActivityState.Created,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(5))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity4);
|
||||
|
||||
//null state
|
||||
var activity5 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "5",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-1),
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity5);
|
||||
|
||||
var activity6 = new DeadActivity(new Activity
|
||||
{
|
||||
Detail = new ActivityDetail(),
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "6",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
Created = DateTime.Today.Subtract(TimeSpan.FromDays(6))
|
||||
}, DeadActivityReason.MissingRequiredField, "Test");
|
||||
await _repository.SaveDeadActivity(activity6);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var filter = new DeadActivityFilter
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 2,
|
||||
State = new List<ActivityState> { ActivityState.Accepted }
|
||||
};
|
||||
var found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(2, found.Items.Count());
|
||||
Assert.AreEqual(3, found.Total);
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "3"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "4")); // not accepted
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "1")); // not on this page
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "5")); // not accepted
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "6"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "2")); // not accepted
|
||||
filter.Page = 2;
|
||||
found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.AreEqual(1, found.Items.Count());
|
||||
Assert.AreEqual(3, found.Total);
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "4"));
|
||||
|
||||
var filter2 = new DeadActivityFilter
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 100,
|
||||
State = new List<ActivityState> { ActivityState.ManualReview }
|
||||
};
|
||||
found = await _repository.GetFilteredDeadActivities(filter2);
|
||||
Assert.AreEqual(0, found.Total);
|
||||
Assert.IsEmpty(found.Items);
|
||||
|
||||
filter2.Page = 20;
|
||||
found = await _repository.GetFilteredDeadActivities(filter2);
|
||||
Assert.AreEqual(0, found.Total);
|
||||
Assert.IsEmpty(found.Items);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetFilteredDeadActivities_More()
|
||||
{
|
||||
// You can't set last updated. So you'll get these back in reverse order you saved them.
|
||||
var activity1 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "1",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-4),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
MemberName = "John Doe"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test1");
|
||||
await _repository.SaveDeadActivity(activity1);
|
||||
var activity2 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "2",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-3),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
SubjectPersonNbr = "1Jane3Doe"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test2");
|
||||
await _repository.SaveDeadActivity(activity2);
|
||||
var activity3 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "3",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-2),
|
||||
State = ActivityState.Rejected,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "1234"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test3");
|
||||
await _repository.SaveDeadActivity(activity3);
|
||||
var activity4 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "4",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-1),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12DOE35"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test4");
|
||||
await _repository.SaveDeadActivity(activity4);
|
||||
|
||||
//Everything in Query is null. should not match, should not error
|
||||
var activity5 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "4",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
}, DeadActivityReason.Other, "Test4");
|
||||
await _repository.SaveDeadActivity(activity5);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var filter = new DeadActivityFilter
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 2,
|
||||
Query = "DoE"
|
||||
};
|
||||
var found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(2, found.Items.Count());
|
||||
Assert.AreEqual(3, found.Total);
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "4"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "1")); // not on this page
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "2"));
|
||||
|
||||
filter.Page = 2;
|
||||
found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.AreEqual(1, found.Items.Count());
|
||||
Assert.AreEqual(3, found.Total);
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "1"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "4"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivitiesByFilter_Employee_Department()
|
||||
{
|
||||
var activity1 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "1",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-4),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
MemberName = "John Doe"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test1");
|
||||
await _repository.SaveDeadActivity(activity1);
|
||||
var activity2 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "2",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-3),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
SubjectPersonNbr = "1Jane3Doe"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test2");
|
||||
await _repository.SaveDeadActivity(activity2);
|
||||
var activity3 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "3",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-2),
|
||||
State = ActivityState.Rejected,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "1234"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test3");
|
||||
await _repository.SaveDeadActivity(activity3);
|
||||
var activity4 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "4",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-1),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12DOE35"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test4");
|
||||
await _repository.SaveDeadActivity(activity4);
|
||||
|
||||
//Everything in Query is null. should not match, should not error
|
||||
var activity5 = new DeadActivity(new Activity
|
||||
{
|
||||
EmployeeId = "4",
|
||||
DepartmentId = -1,
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
}, DeadActivityReason.Other, "Test5");
|
||||
await _repository.SaveDeadActivity(activity5);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var filter = new DeadActivityFilter
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 2,
|
||||
DepartmentId = 55
|
||||
};
|
||||
var found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(2, found.Items.Count());
|
||||
Assert.AreEqual(3, found.Total);
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "3"));
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "4"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "1")); // not on this page
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
|
||||
|
||||
filter.EmployeeId = "4";
|
||||
found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.AreEqual(1, found.Items.Count());
|
||||
Assert.AreEqual(1, found.Total);
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "3"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "2"));
|
||||
Assert.False(found.Items.Any(x => x.EmployeeId == "1"));
|
||||
Assert.True(found.Items.Any(x => x.EmployeeId == "4"));
|
||||
|
||||
filter.DepartmentId = 99;
|
||||
found = await _repository.GetFilteredDeadActivities(filter);
|
||||
Assert.AreEqual(0, found.Items.Count());
|
||||
Assert.AreEqual(0, found.Total);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivitiesByFilter_Sort()
|
||||
{
|
||||
var activity1 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "1",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-4),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
MemberName = "John Doe"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test1");
|
||||
await _repository.SaveDeadActivity(activity1);
|
||||
var activity2 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "2",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-3),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
SubjectPersonNbr = "1Jane3Doe"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test2");
|
||||
await _repository.SaveDeadActivity(activity2);
|
||||
var activity3 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-2),
|
||||
State = ActivityState.Rejected,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "1234"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test3");
|
||||
await _repository.SaveDeadActivity(activity3);
|
||||
var activity4 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "4",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today.AddMinutes(-1),
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12DOE35"
|
||||
}
|
||||
}, DeadActivityReason.Other, "Test4");
|
||||
await _repository.SaveDeadActivity(activity4);
|
||||
//Everything in Query is null. should not match, should not error
|
||||
var activity5 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = -1,
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
}, DeadActivityReason.Other, "Test5");
|
||||
await _repository.SaveDeadActivity(activity5);
|
||||
await _context.SaveChangesAsync();
|
||||
//Everything in Query is null. should not match, should not error
|
||||
var activity6 = new DeadActivity(new Activity
|
||||
{
|
||||
DepartmentId = -1,
|
||||
EmployeeId = "6",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
}, DeadActivityReason.Other, "Test6");
|
||||
await _repository.SaveDeadActivity(activity6);
|
||||
var filter = new DeadActivityFilter
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 99,
|
||||
DepartmentId = 55,
|
||||
SortBy = "EmployeeId"
|
||||
};
|
||||
//NOTE: Null EmployeeId first
|
||||
var found = await _repository.GetFilteredDeadActivities(filter);
|
||||
var expected = new[] { "Test3", "Test1", "Test4" };
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(3, found.Items.Count());
|
||||
Assert.AreEqual(3, found.Total);
|
||||
var ordered = found.Items.Select(x => x.ReasonNote).ToArray();
|
||||
Assert.AreEqual(expected, ordered);
|
||||
|
||||
//NOTE: Null EmployeeId Last
|
||||
filter.SortDescending = true;
|
||||
found = await _repository.GetFilteredDeadActivities(filter);
|
||||
expected = new[] { "Test4", "Test1", "Test3" };
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(3, found.Items.Count());
|
||||
Assert.AreEqual(3, found.Total);
|
||||
ordered = found.Items.Select(x => x.ReasonNote).ToArray();
|
||||
Assert.AreEqual(expected, ordered);
|
||||
|
||||
filter.SortDescending = false;
|
||||
filter.SortBy = null;
|
||||
found = await _repository.GetFilteredDeadActivities(filter);
|
||||
expected = new[] { "Test4", "Test3", "Test1" };
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.Items);
|
||||
Assert.AreEqual(3, found.Items.Count());
|
||||
Assert.AreEqual(3, found.Total);
|
||||
ordered = found.Items.Select(x => x.ReasonNote).ToArray();
|
||||
Assert.AreEqual(expected, ordered);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1154
File diff suppressed because it is too large
Load Diff
+55
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class GoalChangeRepositoryTest
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private GoalChangeRepository _repository;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var mockDateTime = new DateTimeService();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
||||
_repository = new GoalChangeRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_Flow_Test()
|
||||
{
|
||||
var saved = await _repository.GetGoalChangesAsync();
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var newId = await _repository.SaveGoalChangeAsync(new GoalChange());
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
saved = await _repository.GetGoalChangesAsync();
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
var first = saved.First();
|
||||
// Make sure our Auditable is working.
|
||||
Assert.NotNull(first.CreatedBy);
|
||||
Assert.NotNull(first.Created);
|
||||
}
|
||||
}
|
||||
}
|
||||
+762
@@ -0,0 +1,762 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Extensions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class GoalRepositoryTest
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private GoalRepository _repository;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var mockDateTime = new DateTimeService();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
||||
_repository = new GoalRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_Flow_Test()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var newId = await _repository.SaveGoalAsync(new Goal()
|
||||
{
|
||||
DepartmentId = 6,
|
||||
StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1),
|
||||
EndDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).Subtract(TimeSpan.FromDays(1)),
|
||||
EmployeeId = null
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
|
||||
{
|
||||
IncludePersonnel = false
|
||||
}
|
||||
);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
var first = saved.First();
|
||||
// Make sure our Auditable is working.
|
||||
Assert.NotNull(first.CreatedBy);
|
||||
Assert.NotNull(first.Created);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_Search_Test()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var startDate = new DateTime(2021, 3, 1);
|
||||
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
|
||||
|
||||
|
||||
var goalPersonnel = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 8,
|
||||
DepartmentId = 2,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal3 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 11,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 4, 1),
|
||||
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth()
|
||||
};
|
||||
|
||||
await _repository.SaveGoalAsync(goalPersonnel);
|
||||
await _repository.SaveGoalAsync(goal);
|
||||
await _repository.SaveGoalAsync(goal2);
|
||||
await _repository.SaveGoalAsync(goal3);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
|
||||
{
|
||||
IncludePersonnel = false
|
||||
}
|
||||
);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
Assert.AreEqual(3, saved.Count);
|
||||
|
||||
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
|
||||
{
|
||||
IncludePersonnel = true
|
||||
}
|
||||
);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
Assert.AreEqual(1, saved.Count);
|
||||
|
||||
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
|
||||
{
|
||||
IncludePersonnel = false,
|
||||
departmentId = 1
|
||||
}
|
||||
);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
Assert.AreEqual(2, saved.Count);
|
||||
|
||||
|
||||
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
|
||||
{
|
||||
IncludePersonnel = true,
|
||||
departmentId = 1
|
||||
}
|
||||
);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
Assert.AreEqual(1, saved.Count);
|
||||
|
||||
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
|
||||
{
|
||||
IncludePersonnel = false,
|
||||
DateRange = new MonthRange(2021,3)
|
||||
}
|
||||
);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
Assert.AreEqual(2, saved.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Multi_Year_Search_Test()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var startDate = new DateTime(2021, 6, 1);
|
||||
var endDate = (new DateTime(2021, 6, 1)).EndOfMonth();
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 11,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2022, 4, 1),
|
||||
EndDate = (new DateTime(2022, 4, 1)).EndOfMonth()
|
||||
};
|
||||
|
||||
await _repository.SaveGoalAsync(goal);
|
||||
await _repository.SaveGoalAsync(goal2);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
saved = await _repository.GetGoalsAsync(new GoalSearchRequest()
|
||||
{
|
||||
DateRange = new MonthRange(2021,6, 2022,6),
|
||||
IncludePersonnel = false
|
||||
}
|
||||
);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
Assert.AreEqual(2, saved.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Find_Goal_Basic()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var goalChange = new GoalChange()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 3, 1),
|
||||
EndDate = (new DateTime(2021, 3, 1)).EndOfMonth(),
|
||||
PersonId = "[email protected]"
|
||||
};
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 3, 1),
|
||||
EndDate = (new DateTime(2021, 3, 1)).EndOfMonth(),
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
var newId = await _repository.SaveGoalAsync(goal);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var foundGoal = await _repository.FindExistingGoal(goalChange);
|
||||
Assert.NotNull(foundGoal);
|
||||
// Make sure our Auditable is working.
|
||||
Assert.NotNull(foundGoal.CreatedBy);
|
||||
Assert.NotNull(foundGoal.Created);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Find_Goal_UsesDate()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var goalChange = new GoalChange()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 3, 1),
|
||||
EndDate = (new DateTime(2021, 3, 1)).EndOfMonth(),
|
||||
PersonId = "[email protected]"
|
||||
};
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 3, 1),
|
||||
EndDate = (new DateTime(2021, 3, 1)).AddMonths(1).AddMilliseconds(-1),
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
var newId = await _repository.SaveGoalAsync(goal);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var foundGoal = await _repository.FindExistingGoal(goalChange);
|
||||
Assert.NotNull(foundGoal);
|
||||
// Make sure our Auditable is working.
|
||||
Assert.NotNull(foundGoal.CreatedBy);
|
||||
Assert.NotNull(foundGoal.Created);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Find_Goal_Department_Basic()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var startDate = new DateTime(2021, 3, 1);
|
||||
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
|
||||
|
||||
// This personnel goal shouldn't be returned.
|
||||
var goalPersonnel = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 8,
|
||||
DepartmentId = 2,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal3 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 11,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 4, 1),
|
||||
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth()
|
||||
};
|
||||
|
||||
await _repository.SaveGoalAsync(goalPersonnel);
|
||||
await _repository.SaveGoalAsync(goal);
|
||||
await _repository.SaveGoalAsync(goal2);
|
||||
await _repository.SaveGoalAsync(goal3);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var foundGoals = await _repository.FindDepartmentGoals(1, startDate, endDate);
|
||||
Assert.NotNull(foundGoals);
|
||||
Assert.IsNotEmpty(foundGoals);
|
||||
Assert.AreEqual(1, foundGoals.Count);
|
||||
Assert.AreEqual(10, foundGoals.First().Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Find_Goal_Department_Annual()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var startDate = new DateTime(2021, 3, 1);
|
||||
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
|
||||
|
||||
// This personnel goal shouldn't be returned.
|
||||
var goalPersonnel = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 7,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 8,
|
||||
DepartmentId = 2,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal3 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 11,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 4, 1),
|
||||
EndDate = (new DateTime(2021, 3, 1)).EndOfMonth()
|
||||
};
|
||||
|
||||
await _repository.SaveGoalAsync(goalPersonnel);
|
||||
await _repository.SaveGoalAsync(goal);
|
||||
await _repository.SaveGoalAsync(goal2);
|
||||
await _repository.SaveGoalAsync(goal3);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var foundGoals = await _repository.FindAnnualDepartmentGoals(1, startDate.Year);
|
||||
Assert.NotNull(foundGoals);
|
||||
Assert.IsNotEmpty(foundGoals);
|
||||
Assert.AreEqual(2, foundGoals.Count);
|
||||
Assert.AreEqual(10, foundGoals.First().Value);
|
||||
Assert.AreEqual(11, foundGoals.ElementAt(1).Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Find_Goal_Personnel_Basic()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var startDate = new DateTime(2021, 3, 1);
|
||||
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
|
||||
|
||||
// This department goal shouldn't be returned
|
||||
var departmentGoal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
var goalx = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 8,
|
||||
DepartmentId = 2,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
var goal3 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 11,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 4, 1),
|
||||
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth(),
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
await _repository.SaveGoalAsync(departmentGoal);
|
||||
await _repository.SaveGoalAsync(goal);
|
||||
await _repository.SaveGoalAsync(goalx);
|
||||
await _repository.SaveGoalAsync(goal2);
|
||||
await _repository.SaveGoalAsync(goal3);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "[email protected]",
|
||||
FullName = "John McTester",
|
||||
HomeDepartment = "QA",
|
||||
BaseRole = "Tester",
|
||||
Role = Role.Developer,
|
||||
}
|
||||
};
|
||||
var foundGoals = await _repository.FindPersonnelGoals(1, users, startDate, endDate);
|
||||
Assert.NotNull(foundGoals);
|
||||
Assert.IsNotEmpty(foundGoals);
|
||||
Assert.AreEqual(1, foundGoals.Count);
|
||||
Assert.AreEqual(10, foundGoals.First().Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Find_Goal_Personnel_Monthly()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var startDate = new DateTime(2021, 3, 1);
|
||||
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
|
||||
|
||||
// This department goal shouldn't be returned
|
||||
var departmentGoal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
// Not the same person.
|
||||
var goalx = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
// Not the same department
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 8,
|
||||
DepartmentId = 2,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
// not the same month
|
||||
var goal3 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 11,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 4, 1),
|
||||
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth(),
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
await _repository.SaveGoalAsync(departmentGoal);
|
||||
await _repository.SaveGoalAsync(goal);
|
||||
await _repository.SaveGoalAsync(goalx);
|
||||
await _repository.SaveGoalAsync(goal2);
|
||||
await _repository.SaveGoalAsync(goal3);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "[email protected]",
|
||||
FullName = "John McTester",
|
||||
HomeDepartment = "QA",
|
||||
BaseRole = "Tester",
|
||||
Role = Role.Developer,
|
||||
}
|
||||
};
|
||||
var foundGoals = await _repository.FindMonthlyPersonnelGoals(1, users, startDate.Year, startDate.Month);
|
||||
Assert.NotNull(foundGoals);
|
||||
Assert.IsNotEmpty(foundGoals);
|
||||
Assert.AreEqual(1, foundGoals.Count);
|
||||
Assert.AreEqual(10, foundGoals.First().Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Find_Goal_Personnel_Month_Range()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var startDate = new DateTime(2021, 3, 1);
|
||||
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
|
||||
|
||||
// This department goal shouldn't be returned
|
||||
var departmentGoal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
// Not the same person.
|
||||
var goalx = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
// Not the same department
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 8,
|
||||
DepartmentId = 2,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
// not the same month
|
||||
var goal3 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 11,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 4, 1),
|
||||
EndDate = (new DateTime(2021, 4, 1)).EndOfMonth(),
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
// not in month range
|
||||
var goal4 = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 12,
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 5, 1),
|
||||
EndDate = (new DateTime(2021, 5, 1)).EndOfMonth(),
|
||||
EmployeeId = "[email protected]"
|
||||
};
|
||||
|
||||
await _repository.SaveGoalAsync(departmentGoal);
|
||||
await _repository.SaveGoalAsync(goal);
|
||||
await _repository.SaveGoalAsync(goalx);
|
||||
await _repository.SaveGoalAsync(goal2);
|
||||
await _repository.SaveGoalAsync(goal3);
|
||||
await _repository.SaveGoalAsync(goal4);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "[email protected]",
|
||||
FullName = "John McTester",
|
||||
HomeDepartment = "QA",
|
||||
BaseRole = "Tester",
|
||||
Role = Role.Developer,
|
||||
}
|
||||
};
|
||||
var range = new MonthRange
|
||||
(
|
||||
startDate.Year,
|
||||
startDate.Month,
|
||||
endDate.Year,
|
||||
endDate.Month + 1
|
||||
);
|
||||
var foundGoals = await _repository.FindPersonnelGoalsByMonthRange(1, users, range);
|
||||
Assert.NotNull(foundGoals);
|
||||
Assert.IsNotEmpty(foundGoals);
|
||||
Assert.AreEqual(2, foundGoals.Count);
|
||||
Assert.AreEqual(10, foundGoals.First().Value);
|
||||
Assert.AreEqual(11, foundGoals.ElementAt(1).Value);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindDepartmentGoalsByMonthRange()
|
||||
{
|
||||
var saved = await _repository.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var startDate = new DateTime(2021, 3, 1);
|
||||
var endDate = (new DateTime(2021, 3, 1)).EndOfMonth();
|
||||
|
||||
var goalInRange = new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
Value = 10,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var goalNotInRange = new Goal()
|
||||
{
|
||||
Product = Product.ATMCard,
|
||||
Value = 2,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate.AddMonths(-2),
|
||||
EndDate = endDate.AddMonths(-2)
|
||||
};
|
||||
|
||||
var goalWithPersonId = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
Value = 2,
|
||||
DepartmentId = 1,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate,
|
||||
EmployeeId = "E1"
|
||||
};
|
||||
|
||||
var goalForOtherDepartment = new Goal()
|
||||
{
|
||||
Product = Product.CreditCard,
|
||||
Value = 2,
|
||||
DepartmentId = 2,
|
||||
StartDate = startDate,
|
||||
EndDate = endDate
|
||||
};
|
||||
|
||||
var range = new MonthRange(2021, 3, 2021, 4);
|
||||
|
||||
await _repository.SaveGoalAsync(goalInRange);
|
||||
await _repository.SaveGoalAsync(goalNotInRange);
|
||||
await _repository.SaveGoalAsync(goalWithPersonId);
|
||||
await _repository.SaveGoalAsync(goalForOtherDepartment);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var found = await _repository.FindDepartmentGoalsByMonthRange(1, range);
|
||||
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found);
|
||||
Assert.AreEqual(1, found.Count);
|
||||
Assert.AreEqual(10, found.First().Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class PayoutRepositoryTest
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private PayoutRepository _repository;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var mockDateTime = new DateTimeService();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
||||
_repository = new PayoutRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_Flow_Test()
|
||||
{
|
||||
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||||
var saved = await _repository.GetPayoutLineItemsForPeriodAsync(period);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var newId = await _repository.SavePayoutLineItemAsync(new PayoutLineItem()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
Role = Role.Teller,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 999,
|
||||
ActivityTotal = 1,
|
||||
PayoutTotal = 10,
|
||||
CommissionId = 99,
|
||||
CommissionValue = 10,
|
||||
ActivityPeriod = period
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
saved = await _repository.GetPayoutLineItemsForPeriodAsync(period);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
var first = saved.First();
|
||||
// Make sure our Auditable is working.
|
||||
Assert.NotNull(first.CreatedBy);
|
||||
Assert.NotNull(first.Created);
|
||||
|
||||
var savedPayout = await _repository.GetPayoutLineItemById(saved.First().Id);
|
||||
Assert.AreSame(saved.First(), savedPayout);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_RangeFlow_Test()
|
||||
{
|
||||
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||||
var saved = await _repository.GetPayoutLineItemsForPeriodAsync(period);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var lineItems = new List<PayoutLineItem>()
|
||||
{
|
||||
new PayoutLineItem()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
Role = Role.Teller,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 999,
|
||||
ActivityTotal = 1,
|
||||
PayoutTotal = 10,
|
||||
CommissionId = 99,
|
||||
CommissionValue = 10,
|
||||
ActivityPeriod = period
|
||||
},
|
||||
new PayoutLineItem()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
Role = Role.Teller,
|
||||
EmployeeId = "11772",
|
||||
DepartmentId = 999,
|
||||
ActivityTotal = 1,
|
||||
PayoutTotal = 10,
|
||||
CommissionId = 99,
|
||||
CommissionValue = 10,
|
||||
ActivityPeriod = period
|
||||
}
|
||||
};
|
||||
await _repository.SavePayoutLineItemRangeAsync(lineItems);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
saved = await _repository.GetPayoutLineItemsForPeriodAsync(period);
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
Assert.AreEqual(2, saved.Count());
|
||||
var first = saved.First();
|
||||
// Make sure our Auditable is working.
|
||||
Assert.NotNull(first.CreatedBy);
|
||||
Assert.NotNull(first.Created);
|
||||
|
||||
var savedPayout = await _repository.GetPayoutLineItemById(saved.First().Id);
|
||||
Assert.AreSame(saved.First(), savedPayout);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetEmployeePayoutsForPeriod_None()
|
||||
{
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565
|
||||
};
|
||||
|
||||
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||||
var found = await _repository.GetEmployeePayoutsForPeriod(user, period);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsEmpty(found);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetEmployeePayoutsForPeriod_Basic()
|
||||
{
|
||||
var period = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||||
var period2 = new DateTime(DateTime.Today.Year + 1, DateTime.Today.Month, 1);
|
||||
var payout1 = new PayoutLineItem()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
Role = Role.Teller,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 999,
|
||||
ActivityTotal = 1,
|
||||
PayoutTotal = 10,
|
||||
CommissionId = 99,
|
||||
CommissionValue = 10,
|
||||
ActivityPeriod = period
|
||||
};
|
||||
await _repository.SavePayoutLineItemAsync(payout1);
|
||||
var payout2 = new PayoutLineItem()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
Role = Role.Teller,
|
||||
EmployeeId = "11772",
|
||||
DepartmentId = 999,
|
||||
ActivityTotal = 1,
|
||||
PayoutTotal = 10,
|
||||
CommissionId = 99,
|
||||
CommissionValue = 10,
|
||||
ActivityPeriod = period
|
||||
};
|
||||
await _repository.SavePayoutLineItemAsync(payout2);
|
||||
var payout3 = new PayoutLineItem()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
Role = Role.Teller,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 999,
|
||||
ActivityTotal = 1,
|
||||
PayoutTotal = 10,
|
||||
CommissionId = 99,
|
||||
CommissionValue = 10,
|
||||
ActivityPeriod = period
|
||||
};
|
||||
await _repository.SavePayoutLineItemAsync(payout3);
|
||||
var payout4 = new PayoutLineItem()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
Role = Role.Teller,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 999,
|
||||
ActivityTotal = 1,
|
||||
PayoutTotal = 10,
|
||||
CommissionId = 99,
|
||||
CommissionValue = 10,
|
||||
ActivityPeriod = period2
|
||||
};
|
||||
await _repository.SavePayoutLineItemAsync(payout4);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 11771,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 55,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var found = await _repository.GetEmployeePayoutsForPeriod(user, period);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found);
|
||||
Assert.AreEqual(2, found.Count);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class ProcessorHistoryRepositoryTest
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private ProcessorHistoryRepository _repository;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var mockDateTime = new DateTimeService();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
||||
_repository = new ProcessorHistoryRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_Flow_test()
|
||||
{
|
||||
var res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
|
||||
{
|
||||
Process = Process.ImportCheckingAccountSalesFromDna,
|
||||
LastSuccessfulRunTime = DateTime.Now,
|
||||
LastProcessedRecordId = 5,
|
||||
LastProcessedRecordTimestamp = DateTime.Now,
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
Assert.NotNull(res);
|
||||
Assert.AreEqual(res, Process.ImportCheckingAccountSalesFromDna);
|
||||
|
||||
res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
|
||||
{
|
||||
Process = Process.ImportGapMbpFromAlliedFile,
|
||||
LastSuccessfulRunTime = DateTime.Parse("2021-04-05"),
|
||||
LastProcessedRecordId = 3,
|
||||
LastProcessedRecordTimestamp = DateTime.Parse("2021-04-05")
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
Assert.NotNull(res);
|
||||
Assert.AreEqual(Process.ImportGapMbpFromAlliedFile, res);
|
||||
|
||||
var list = await _repository.GetAllProcessorRunHistory();
|
||||
Assert.NotNull(list);
|
||||
Assert.AreEqual(2, list.Count);
|
||||
|
||||
//Saving existing Process causes update
|
||||
res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
|
||||
{
|
||||
Process = Process.ImportGapMbpFromAlliedFile,
|
||||
LastSuccessfulRunTime = DateTime.Parse("2021-05-08"),
|
||||
LastProcessedRecordId = 200,
|
||||
LastProcessedRecordTimestamp = DateTime.Parse("2021-05-07"),
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
list = await _repository.GetAllProcessorRunHistory();
|
||||
|
||||
Assert.NotNull(list);
|
||||
Assert.AreEqual(2, list.Count);
|
||||
|
||||
var updatedHistoryRecord = list.Find(x => x.Process == Process.ImportGapMbpFromAlliedFile);
|
||||
Assert.AreEqual(200, updatedHistoryRecord.LastProcessedRecordId);
|
||||
Assert.AreEqual(DateTime.Parse("2021-05-08"), updatedHistoryRecord.LastSuccessfulRunTime);
|
||||
Assert.AreEqual(DateTime.Parse("2021-05-07"), updatedHistoryRecord.LastProcessedRecordTimestamp);
|
||||
|
||||
updatedHistoryRecord = await _repository.GetProcessorRunHistory(Process.ImportGapMbpFromAlliedFile);
|
||||
Assert.AreEqual(200, updatedHistoryRecord.LastProcessedRecordId);
|
||||
Assert.AreEqual(DateTime.Parse("2021-05-08"), updatedHistoryRecord.LastSuccessfulRunTime);
|
||||
Assert.AreEqual(DateTime.Parse("2021-05-07"), updatedHistoryRecord.LastProcessedRecordTimestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
|
||||
namespace Application.UnitTests.Repository
|
||||
{
|
||||
public class UserAssignmentRepositoryTest
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private UserAssignmentRepository _repository;
|
||||
private Mock<IDateTime> _mockDateTime;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDateTime = new Mock<IDateTime>();
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
_context = new ApplicationDbContext(options, mockCurrentUserService, _mockDateTime.Object);
|
||||
_repository = new UserAssignmentRepository(_context);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_Flow_test()
|
||||
{
|
||||
var mockDate = new DateTime(2021, 8, 17, 1, 2, 3, 456);
|
||||
_mockDateTime.SetupGet(mock => mock.Now).Returns(mockDate);
|
||||
var saved = await _repository.GetAllUserAssignmentsAsync();
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var newAssignment = new UserAssignment
|
||||
{
|
||||
Id = 1,
|
||||
Key = "key",
|
||||
Type = AssignmentType.RegionalManager,
|
||||
AppUser = new AppUser {
|
||||
BaseRole = "Role",
|
||||
FullName = "Test",
|
||||
HomeDepartment = "Test",
|
||||
Role = Role.Admin,
|
||||
EmployeeId = "123",
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 456
|
||||
}
|
||||
};
|
||||
|
||||
var newId = await _context.AddAsync(newAssignment);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
saved = await _repository.GetAllUserAssignmentsAsync();
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
var first = saved.First();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindExistingAssignment_Match()
|
||||
{
|
||||
var mockDate = new DateTime(2021, 8, 17, 1, 2, 3, 456);
|
||||
_mockDateTime.SetupGet(mock => mock.Now).Returns(mockDate);
|
||||
var saved = await _repository.GetAllUserAssignmentsAsync();
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var newAssignment = new UserAssignment
|
||||
{
|
||||
Id = 1,
|
||||
Key = "NORTH",
|
||||
Type = AssignmentType.RegionalManager,
|
||||
AppUser = new AppUser
|
||||
{
|
||||
BaseRole = "Role",
|
||||
FullName = "Test",
|
||||
HomeDepartment = "Test",
|
||||
Role = Role.Admin,
|
||||
EmployeeId = "123",
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 456
|
||||
}
|
||||
};
|
||||
|
||||
var newId = await _context.AddAsync(newAssignment);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var notFound = await _repository.FindExistingAssignmentAsync(AssignmentType.RegionalManager, "CENTRAL");
|
||||
Assert.Null(notFound);
|
||||
|
||||
var found = await _repository.FindExistingAssignmentAsync(AssignmentType.RegionalManager, "NORTH");
|
||||
Assert.NotNull(found);
|
||||
Assert.AreEqual(1, found.Id);
|
||||
Assert.AreEqual("NORTH", found.Key);
|
||||
Assert.AreEqual(AssignmentType.RegionalManager, found.Type);
|
||||
Assert.AreEqual("123", found.AppUser.EmployeeId);
|
||||
Assert.AreEqual("[email protected]", found.AppUser.AdEmail);
|
||||
Assert.AreEqual(456, found.AppUser.PersonId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1033
File diff suppressed because it is too large
Load Diff
+382
@@ -0,0 +1,382 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using CsvHelper;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Action;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Action;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
|
||||
namespace Application.UnitTests.Services.Action
|
||||
{
|
||||
public class ActionCreditCardImportServiceTest
|
||||
{
|
||||
private IActionCreditCardImportService _actionCreditCardImportService;
|
||||
private IUserRepository _userRepository;
|
||||
private IActivityService _activityService;
|
||||
private IFileOperationsApiService _fileOperationsApiService;
|
||||
private Mock<IDeadActivityService> _deadActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_userRepository = Mock.Of<IUserRepository>();
|
||||
_fileOperationsApiService = Mock.Of<IFileOperationsApiService>();
|
||||
_activityService = Mock.Of<IActivityService>();
|
||||
_deadActivityService = new Mock<IDeadActivityService>();
|
||||
_actionCreditCardImportService = new ActionCreditCardImportService(_userRepository, _fileOperationsApiService, _activityService,_deadActivityService.Object);
|
||||
}
|
||||
|
||||
private static StreamReader GetActionFile()
|
||||
{
|
||||
var path = @"Services/Action/Action_CreditCardPersonal.csv";
|
||||
var reader = new StreamReader(path);
|
||||
return reader;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessFileNames_OK()
|
||||
{
|
||||
var department = new Department
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
user.Departments.Add(assignment);
|
||||
|
||||
var request = new ActionCreditCardRequest
|
||||
{
|
||||
DynamicFileName = "credit",
|
||||
FilePath = "clean",
|
||||
DynamicFileSettings = new DynamicNameSetting() { }
|
||||
};
|
||||
|
||||
var files = new[]
|
||||
{
|
||||
"x"
|
||||
};
|
||||
|
||||
var array = await File.ReadAllBytesAsync( @"Services/Action/Action_CreditCardPersonal.csv");
|
||||
|
||||
//Setup
|
||||
Mock.Get(_fileOperationsApiService).Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(files);
|
||||
Mock.Get(_fileOperationsApiService).Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(array.ToString());
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
Mock.Get(_activityService).Setup(x => x.SaveActivityRangeAsync(It.IsAny<IReadOnlyCollection<Activity>>())).Verifiable();
|
||||
|
||||
await _actionCreditCardImportService.ImportTransactions<ActionCreditCardPersonalRow>("personal", request);
|
||||
|
||||
Mock.Get(_fileOperationsApiService).Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
Mock.Get(_activityService).Verify(x => x.SaveActivityRangeAsync(It.IsAny<IReadOnlyCollection<Activity>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessCsv_OK()
|
||||
{
|
||||
var department = new Department
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
user.Departments.Add(assignment);
|
||||
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
var actionCreditCardPersonalRows = transactions.ToList();
|
||||
Assert.IsNotEmpty(actionCreditCardPersonalRows);
|
||||
Assert.AreEqual(15, actionCreditCardPersonalRows.Count);
|
||||
|
||||
// Should lose the duplicate.
|
||||
var results = await _actionCreditCardImportService.CreateActivity(actionCreditCardPersonalRows);
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(14, results.Count);
|
||||
}
|
||||
|
||||
private IEnumerable<ActionCreditCardPersonalRow> ImportTestTransactions()
|
||||
{
|
||||
var input = GetActionFile();
|
||||
var csvReader = new CsvReader(input, CultureInfo.InvariantCulture);
|
||||
return csvReader.GetRecords<ActionCreditCardPersonalRow>().ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenNoUserFound()
|
||||
{
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
var actionCreditCardPersonalRows = transactions.ToList();
|
||||
Assert.IsNotEmpty(actionCreditCardPersonalRows);
|
||||
Assert.AreEqual(15, actionCreditCardPersonalRows.Count);
|
||||
|
||||
var results = await _actionCreditCardImportService.CreateActivity(actionCreditCardPersonalRows);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count == 15 &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")))));
|
||||
|
||||
//Our test CSV has email information for every row except 1
|
||||
_deadActivityService.Verify(x =>x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(deadActivity => !string.IsNullOrWhiteSpace(deadActivity.EmployeeEmail)) == 14)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenFindingUserFails()
|
||||
{
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>()))
|
||||
.Throws(new Exception("OOops"));
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
var actionCreditCardPersonalRows = transactions.ToList();
|
||||
Assert.IsNotEmpty(actionCreditCardPersonalRows);
|
||||
Assert.AreEqual(15, actionCreditCardPersonalRows.Count);
|
||||
|
||||
var results = await _actionCreditCardImportService.CreateActivity(actionCreditCardPersonalRows);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count == 15 &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")))));
|
||||
|
||||
//Our test CSV has email information for every row except 1
|
||||
_deadActivityService.Verify(x =>x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(deadActivity => !string.IsNullOrWhiteSpace(deadActivity.EmployeeEmail)) == 14)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenNoHomeDepartmentFound()
|
||||
{
|
||||
//Use one user for all lines for simplicity
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
var actionCreditCardPersonalRows = transactions.ToList();
|
||||
Assert.IsNotEmpty(actionCreditCardPersonalRows);
|
||||
Assert.AreEqual(15, actionCreditCardPersonalRows.Count);
|
||||
|
||||
var results = await _actionCreditCardImportService.CreateActivity(actionCreditCardPersonalRows);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count == 15 &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("reliably determinable home")))));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_MissingEmployeeId_MissingDepartmentId()
|
||||
{
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
|
||||
//There are 2 entries with this email, they will have a user but no home department
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.Is<string>(x => x.ToLowerInvariant() == "[email protected]"))).ReturnsAsync(user);
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
var actionCreditCardPersonalRows = transactions.ToList();
|
||||
Assert.IsNotEmpty(actionCreditCardPersonalRows);
|
||||
Assert.AreEqual(15, actionCreditCardPersonalRows.Count);
|
||||
|
||||
var results = await _actionCreditCardImportService.CreateActivity(actionCreditCardPersonalRows);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")) == 13)));
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("reliably determinable home")) == 2)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SomeActivitiesAreDeadJim_Ok()
|
||||
{
|
||||
var john = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "John",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
//There are 2 entries with this email, they will have a user but no home department
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.Is<string>(x => x.ToLowerInvariant() == "[email protected]"))).ReturnsAsync(john);
|
||||
|
||||
var department = new Department
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var mary = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "Mary",
|
||||
FullName = "Mary Deer",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = mary,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
mary.Departments.Add(assignment);
|
||||
//There are 2 entries with this email, they will not have a home department assigned
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.Is<string>(x => x.ToLowerInvariant() == "[email protected]"))).ReturnsAsync(john);
|
||||
//There are 2 entries with this email, they will have a home department assigned
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.Is<string>(x => x.ToLowerInvariant() == "[email protected]"))).ReturnsAsync(mary);
|
||||
|
||||
//Everyone else won't exist
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
var actionCreditCardPersonalRows = transactions.ToList();
|
||||
Assert.IsNotEmpty(actionCreditCardPersonalRows);
|
||||
Assert.AreEqual(15, actionCreditCardPersonalRows.Count);
|
||||
|
||||
//Mary should have 2 successful results
|
||||
var results = await _actionCreditCardImportService.CreateActivity(actionCreditCardPersonalRows);
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2,results.Count);
|
||||
Assert.True(results.All(x => x.EmployeeId == "Mary"));
|
||||
|
||||
//John should have 2 entries in dead activity for not having a home department
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
y.EmployeeId == john.EmployeeId &&
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("reliably determinable home")) == 2)));
|
||||
|
||||
//Everyone else could not be identified
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
(y.EmployeeId != john.EmployeeId && y.EmployeeId != mary.EmployeeId) &&
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")) == 11)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailToSaveDeadActivity_DoesntThrow()
|
||||
{
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
_deadActivityService.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
var actionCreditCardPersonalRows = transactions.ToList();
|
||||
Assert.IsNotEmpty(actionCreditCardPersonalRows);
|
||||
Assert.AreEqual(15, actionCreditCardPersonalRows.Count);
|
||||
|
||||
List<Activity> results = null;
|
||||
Assert.DoesNotThrowAsync(async () =>
|
||||
{
|
||||
var res = await _actionCreditCardImportService.CreateActivity(actionCreditCardPersonalRows);
|
||||
results = res.ToList();
|
||||
});
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count == 15 &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")))));
|
||||
|
||||
//Our test CSV has email information for every row except 1
|
||||
_deadActivityService.Verify(x =>x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(deadActivity => !string.IsNullOrWhiteSpace(deadActivity.EmployeeEmail)) == 14)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+374
@@ -0,0 +1,374 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using CsvHelper;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Action;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Action;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
|
||||
|
||||
namespace Application.UnitTests.Services.Action
|
||||
{
|
||||
public class ActionVehicleImportServiceTest
|
||||
{
|
||||
private IActionVehicleImportService _service;
|
||||
private IUserRepository _userRepository;
|
||||
private IActivityService _activityService;
|
||||
private IFileOperationsApiService _fileOperationsApiService;
|
||||
private Mock<IDeadActivityService> _deadActivityService;
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_userRepository = Mock.Of<IUserRepository>();
|
||||
_fileOperationsApiService = Mock.Of<IFileOperationsApiService>();
|
||||
_activityService = Mock.Of<IActivityService>();
|
||||
_deadActivityService = new Mock<IDeadActivityService>();
|
||||
_service = new ActionVehicleImportService(_userRepository, _fileOperationsApiService, _activityService, _deadActivityService.Object);
|
||||
}
|
||||
|
||||
public StreamReader GetActionFile()
|
||||
{
|
||||
var path = @"Services/Action/Action_IndirectVehicleLoanSales.csv";
|
||||
var reader = new StreamReader(path);
|
||||
return reader;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessFileNames_OK()
|
||||
{
|
||||
var department = new Department()
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment()
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
user.Departments.Add(assignment);
|
||||
|
||||
var request = new ActionVehicleRequest
|
||||
{
|
||||
DynamicFileName = "vehiclesales",
|
||||
FilePath = "clean",
|
||||
DynamicFileSettings = new DynamicNameSetting() { }
|
||||
};
|
||||
|
||||
var files = new string[]
|
||||
{
|
||||
"x"
|
||||
};
|
||||
|
||||
byte[] array = File.ReadAllBytes( @"Services/Action/Action_IndirectVehicleLoanSales.csv");
|
||||
|
||||
//Setup
|
||||
Mock.Get(_fileOperationsApiService).Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(files);
|
||||
Mock.Get(_fileOperationsApiService).Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(array.ToString());
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
Mock.Get(_activityService).Setup(x => x.SaveActivityRangeAsync(It.IsAny<IReadOnlyCollection<Activity>>())).Verifiable();
|
||||
|
||||
await _service.ImportTransactions<ActionSaleRow>(request);
|
||||
|
||||
Mock.Get(_fileOperationsApiService).Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
Mock.Get(_activityService).Verify(x => x.SaveActivityRangeAsync(It.IsAny<IReadOnlyCollection<Activity>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessCsv_OK()
|
||||
{
|
||||
var department = new Department()
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment()
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
user.Departments.Add(assignment);
|
||||
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(7, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(7, results.Count());
|
||||
}
|
||||
|
||||
public IEnumerable<ActionSaleRow> ImportTestTransactions()
|
||||
{
|
||||
var input = GetActionFile();
|
||||
var csvReader = new CsvReader(input, CultureInfo.InvariantCulture);
|
||||
return csvReader.GetRecords<ActionSaleRow>().ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenNoUserFound()
|
||||
{
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(7, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == 7 &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")))));
|
||||
|
||||
//Our test CSV has email information for every row except 1
|
||||
_deadActivityService.Verify(x =>x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(x => !string.IsNullOrWhiteSpace(x.EmployeeEmail)) == 6)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenFindingUserFails()
|
||||
{
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>()))
|
||||
.Throws(new Exception("OOops"));
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(7, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == 7 &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")))));
|
||||
|
||||
//Our test CSV has email information for every row except 1
|
||||
_deadActivityService.Verify(x =>x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(x => !string.IsNullOrWhiteSpace(x.EmployeeEmail)) == 6)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenNoHomeDepartmentFound()
|
||||
{
|
||||
//Use one user for all lines for simplicity
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(7, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == 7 &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("reliably determinable home"))))); }
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_BothKinds()
|
||||
{
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
|
||||
//There are 2 entries with this email, they will have a user but no home department
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.Is<string>(x => x.ToLowerInvariant() == "[email protected]"))).ReturnsAsync(user);
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(7, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")) == 5)));
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("reliably determinable home")) == 2)));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SomeActivitiesAreDeadJim_Ok()
|
||||
{
|
||||
var john = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "John",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
//There are 2 entries with this email, they will have a user but no home department
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.Is<string>(x => x.ToLowerInvariant() == "[email protected]"))).ReturnsAsync(john);
|
||||
|
||||
var department = new Department()
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var mary = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "Mary",
|
||||
FullName = "Mary Deer",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment()
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = mary,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
mary.Departments.Add(assignment);
|
||||
//There are 2 entries with this email, they will not have a home department assigned
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.Is<string>(x => x.ToLowerInvariant() == "[email protected]"))).ReturnsAsync(john);
|
||||
//There are 2 entries with this email, they will have a home department assigned
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.Is<string>(x => x.ToLowerInvariant() == "[email protected]"))).ReturnsAsync(mary);
|
||||
|
||||
//Everyone else won't exist
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(7, transactions.Count());
|
||||
|
||||
//Mary should have 2 successful results
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2,results.Count);
|
||||
Assert.True(results.All(x => x.EmployeeId == "Mary"));
|
||||
|
||||
//John should have 2 entries in dead activity for not having a home department
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
y.EmployeeId == john.EmployeeId &&
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("reliably determinable home")) == 2)));
|
||||
|
||||
//Everyone else could not be identified
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
(y.EmployeeId != john.EmployeeId && y.EmployeeId != mary.EmployeeId) &&
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")) == 3)));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FailToSaveDeadActivity_DoesntThrow()
|
||||
{
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
_deadActivityService.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(7, transactions.Count());
|
||||
|
||||
List<Activity> results = null;
|
||||
Assert.DoesNotThrowAsync(async () =>
|
||||
{
|
||||
var res = await _service.CreateActivity(transactions);
|
||||
results = res.ToList();
|
||||
});
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == 7 &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("action import, no user for")))));
|
||||
|
||||
//Our test CSV has email information for every row except 1
|
||||
_deadActivityService.Verify(x =>x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(x => !string.IsNullOrWhiteSpace(x.EmployeeEmail)) == 6)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
BookedDate,MemberFirstName,MemberLastName,AppID,Principal,ProdDetailFirstName,ProdDetailLastName,ProdDetailEmail,ProdDetailEmployeeNum,IncentiveEarnedEmail,ProductShortName
|
||||
11/4/2021 16:03,CHRISTOPHER,Doe,1721467,7800,Laurie,Doerson,[email protected],5306,,Rewards Credit Card
|
||||
11/4/2021 15:52,Joseph,Doe,1721422,500,Michael,Doerson,[email protected],546,[email protected],Starter Credit Card
|
||||
11/4/2021 15:27,Dalia,Doe,1721404,10000,Michael,Doerson,[email protected],546,[email protected],Qualifile CC
|
||||
11/4/2021 15:50,Pablo,Doe,1721379,2000,Valerie,Doerson,[email protected],835,,Rewards Credit Card
|
||||
11/4/2021 15:54,Antonio,Doe,1721245,500,Valerie,Doerson,[email protected],835,,Rewards Credit Card
|
||||
11/4/2021 10:52,BARRY,Doe,1721090,5000,Alexandria,Doerson,[email protected],5313,,Rewards Credit Card
|
||||
11/4/2021 9:31,SAMANTHA,Doe,1721022,500,Joseph,Doerson,[email protected],817,,Starter Credit Card
|
||||
11/4/2021 10:08,EDWIN,Doe,1720844,500,Jeanfred,Doerson,[email protected],2455,,Rewards Credit Card
|
||||
11/4/2021 10:49,DANIEL,Doe,1720766,500,Laurie,Doerson,[email protected],5306,,Student Rewards CC
|
||||
11/4/2021 9:38,Traeci,Doe,1720546,12000,Monica,Doerson,[email protected],5503,,Rewards Credit Card
|
||||
11/4/2021 11:00,CELINA,Doe,1720088,4500,Shannon,Doerson,[email protected],3723,[email protected],Rewards Credit Card
|
||||
11/4/2021 13:34,CHAD,Doe,1719634,5000,Alexandria,Doerson,[email protected],5313,,Cash Back CC
|
||||
11/4/2021 9:11,ELVIRA,Duplicate,1714817,1000,Daisy,Doerson,[email protected],822,,Rewards Credit Card
|
||||
11/4/2021 9:11,Poppy,Doe,1714818,1000,Popeye,Doerson,,823,,Rewards Credit Card
|
||||
11/4/2021 9:11,ELVIRA,Duplicate,1714817,1000,Daisy,,[email protected],822,,Rewards Credit Card
|
||||
|
+10
@@ -0,0 +1,10 @@
|
||||
EmailAddress,Member_Number,Account_Number,Borrower_Name,APP_START_DATE,OPEN_DATE,PBorrowerSSN_Ind,CBorrowerName_Ind,CBorrowerSSN_Ind,SBorrowerName_Ind,SBorrowerSSN_Ind,IndAppID,IndProduct,IndAmtFinanced,IndCreationDate,IndAccountNumber,PBorrowerName_Veh,PBorrowerSSN_Veh,CBorrowerName_Veh,CBorrowerSSN_Veh,SBorrowerName_Veh,SBorrowerSSN_Veh,VehAppID,VehProduct,VehAmtFinanced,DistributionChannel,DistributionChannelCode
|
||||
[email protected],69714,144,kenneth doerson,8/31/2021,9/8/2021,222334444,,,,,1692568,Ind Auto Truck,"$32,890.70",9/3/2021,69714-144,KENNETH doerson,222334444,,,,,1691319,Vehicle Pre-Approval,"47,000.00",New Berlin,2
|
||||
[email protected],8091110,144,LOUIS DOE,9/1/2021,9/22/2021,333445555,JUNE DOE,111223333,,,1696816,Ind Prem Auto Truck,"$49,683.36",9/13/2021,8091110-144,LOUIS DOE,333445555,JUNE DOE,111223333,,,1691794,Vehicle,"45,147.36",Hartland,7
|
||||
[email protected],8091110,144,LOUIS DOE,9/1/2021,9/22/2021,333445555,JUNE DOE,111223333,,,1696816,Ind Prem Auto Truck,"$49,683.36",9/13/2021,8091110-144,LOUIS DOE,333445555,JUNE DOE,111223333,,,1691794,Vehicle,"45,147.36",Hartland,7
|
||||
[email protected],8091110,144,LOUIS DOE,9/1/2021,9/22/2021,333445555,JUNE DOE,111223333,,,1696816,Ind Prem Auto Truck,"$49,683.36",9/13/2021,8091110-144,LOUIS DOE,333445555,JUNE DOE,111223333,,,1691794,Vehicle,"45,147.36",Hartland,7
|
||||
[email protected],8091110,144,LOUIS DOE,9/1/2021,9/22/2021,333445555,JUNE DOE,111223333,,,1696816,Ind Prem Auto Truck,"$49,683.36",9/13/2021,8091110-144,LOUIS DOE,333445555,JUNE DOE,111223333,,,1691794,Vehicle,"45,147.36",Hartland,7
|
||||
[email protected],8091110,144,LOUIS DOE,9/1/2021,9/22/2021,333445555,JUNE DOE,111223333,,,1696816,Ind Prem Auto Truck,"$49,683.36",9/13/2021,8091110-144,LOUIS DOE,333445555,JUNE DOE,111223333,,,1691794,Vehicle,"45,147.36",Hartland,7
|
||||
,8091110,144,LOUIS DOE,9/1/2021,9/22/2021,333445555,JUNE DOE,111223333,,,1696816,Ind Prem Auto Truck,"$49,683.36",9/13/2021,8091110-144,LOUIS DOE,333445555,JUNE DOE,111223333,,,1691794,Vehicle,"45,147.36",Hartland,7
|
||||
|
||||
|
||||
|
+911
@@ -0,0 +1,911 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Accounts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.DuplicateDetection;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class ActivityDetailServiceTest
|
||||
{
|
||||
private IActivityDetailService _activityDetailService;
|
||||
private IActivityDetailUpdateRepository _activityDetailUpdateRepository;
|
||||
private Mock<IDnaService> _mockDnaService;
|
||||
|
||||
private ActivityService _activityService;
|
||||
private IActivityRepository _activityRepository;
|
||||
private IActivityChangeRepository _activityChangeRepository;
|
||||
private IActivityTransferActionRepository _activityTransferActionRepository;
|
||||
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<INotificationApiService> _mockNotificationService;
|
||||
private Mock<IDuplicateDetectionService> _mockDuplicateDetector;
|
||||
private Mock<IAuthorizationService> _mockAuthorizationService;
|
||||
|
||||
[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())
|
||||
.Options;
|
||||
var context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
||||
_activityDetailUpdateRepository = new ActivityDetailUpdateRepository(context);
|
||||
|
||||
_mockDnaService = new Mock<IDnaService>();
|
||||
_activityDetailService = new ActivityDetailService(_activityDetailUpdateRepository, new UnitOfWork(context), _mockDnaService.Object);
|
||||
|
||||
|
||||
_activityRepository = new ActivityRepository(context);
|
||||
_activityChangeRepository = new ActivityChangeRepository(context);
|
||||
_activityTransferActionRepository = new ActivityTransferActionRepository(context);
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockNotificationService = new Mock<INotificationApiService>();
|
||||
_mockDuplicateDetector = new Mock<IDuplicateDetectionService>();
|
||||
_mockAuthorizationService = new Mock<IAuthorizationService>();
|
||||
|
||||
_activityService =
|
||||
new ActivityService(_activityRepository, _activityChangeRepository, _activityTransferActionRepository,
|
||||
_mockUserService.Object, _mockNotificationService.Object, _mockDuplicateDetector.Object,
|
||||
_mockAuthorizationService.Object, new UnitOfWork(context));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateActivityAccountDetails_Basic_Flow_OK()
|
||||
{
|
||||
await _activityService.SaveActivityRangeAsync(new[]
|
||||
{
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "5",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "APPR",
|
||||
IsGapInsuranceEligible = false
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1", SourceId = "6",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "123",
|
||||
AccountStatus = "APPR",
|
||||
IsGapInsuranceEligible = true
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1", SourceId = "7",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "ORIG",
|
||||
IsGapInsuranceEligible = false
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1", SourceId = "8",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "10",
|
||||
AccountStatus = "ACT",
|
||||
IsGapInsuranceEligible = true
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1", SourceId = "9",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "11",
|
||||
AccountStatus = "ORIG",
|
||||
IsGapInsuranceEligible = true
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1", SourceId = "100",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "120",
|
||||
AccountStatus = "ORIG",
|
||||
IsGapInsuranceEligible = true
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var activities = await _activityService.GetActivitiesAsync();
|
||||
Assert.NotNull(activities);
|
||||
Assert.AreEqual(6, activities.Count);
|
||||
Assert.AreEqual(2, activities.Count(x => x.Detail.AccountStatus == "APPR"));
|
||||
Assert.AreEqual(3, activities.Count(x => x.Detail.AccountStatus == "ORIG"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.AccountStatus == "ACT"));
|
||||
Assert.AreEqual(4, activities.Count(x => x.Detail.IsGapInsuranceEligible == true));
|
||||
|
||||
var accountUpdates = new List<ActivityAccountDetails>
|
||||
{
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 123,
|
||||
CurrentAccountStatus = "CLS"
|
||||
},
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 345,
|
||||
CurrentAccountStatus = "ACT"
|
||||
},
|
||||
//Account Update Found, but account did was not in "AccountsToUpdate"
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 20000,
|
||||
CurrentAccountStatus = "BOO"
|
||||
},
|
||||
//Account Update Found, but account did was not in "AccountsToUpdate"
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 10,
|
||||
CurrentAccountStatus = "CLS"
|
||||
},
|
||||
//Same Account Status, no Change
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 120,
|
||||
CurrentAccountStatus = "ORIG"
|
||||
}
|
||||
};
|
||||
|
||||
_mockDnaService.Setup(x => x.GetNewAccountDetailsForActivities(It.IsAny<List<Activity>>())).ReturnsAsync(accountUpdates);
|
||||
|
||||
var results = await _activityDetailService.TryUpdateActivityAccountDetails(activities.Where(x => x.Detail.AccountStatus != "ACT").ToList());
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(3, results.Count);
|
||||
Assert.False(results.Exists(x => x.Detail.AccountNumber == "120"));
|
||||
|
||||
activities = await _activityService.GetActivitiesAsync();
|
||||
Assert.NotNull(activities);
|
||||
Assert.AreEqual(6, activities.Count);
|
||||
Assert.AreEqual(0, activities.Count(x => x.Detail.AccountStatus == "APPR"));
|
||||
Assert.AreEqual(2, activities.Count(x => x.Detail.AccountStatus == "ORIG"));
|
||||
Assert.AreEqual(3, activities.Count(x => x.Detail.AccountStatus == "ACT"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.AccountStatus == "CLS"));
|
||||
Assert.AreEqual(4, activities.Count(x => x.Detail.IsGapInsuranceEligible == true));
|
||||
|
||||
Assert.AreEqual("ACT", activities.Single(x => x.SourceId == "5").Detail.AccountStatus);
|
||||
Assert.AreEqual("CLS", activities.Single(x => x.SourceId == "6").Detail.AccountStatus);
|
||||
Assert.AreEqual("ACT", activities.Single(x => x.SourceId == "7").Detail.AccountStatus);
|
||||
Assert.AreEqual("ACT", activities.Single(x => x.SourceId == "8").Detail.AccountStatus);
|
||||
Assert.AreEqual("ORIG", activities.Single(x => x.SourceId == "9").Detail.AccountStatus);
|
||||
|
||||
Assert.AreEqual(false, activities.Single(x => x.SourceId == "5").Detail.IsGapInsuranceEligible);
|
||||
Assert.AreEqual(true, activities.Single(x => x.SourceId == "6").Detail.IsGapInsuranceEligible);
|
||||
Assert.AreEqual(false, activities.Single(x => x.SourceId == "7").Detail.IsGapInsuranceEligible);
|
||||
Assert.AreEqual(true, activities.Single(x => x.SourceId == "8").Detail.IsGapInsuranceEligible);
|
||||
Assert.AreEqual(true, activities.Single(x => x.SourceId == "9").Detail.IsGapInsuranceEligible);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateActivityAccountDetails_NoUpdates_OK()
|
||||
{
|
||||
await _activityService.SaveActivityRangeAsync(new[]
|
||||
{
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "5",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "APPR"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "6",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "123",
|
||||
AccountStatus = "APPR"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "7",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "ORIG"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "8",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "10",
|
||||
AccountStatus = "ACT"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "9",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "11",
|
||||
AccountStatus = "ORIG"
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var activities = await _activityService.GetActivitiesAsync();
|
||||
|
||||
Assert.NotNull(activities);
|
||||
Assert.AreEqual(5, activities.Count);
|
||||
Assert.AreEqual(2, activities.Count(x => x.Detail.AccountStatus == "APPR"));
|
||||
Assert.AreEqual(2, activities.Count(x => x.Detail.AccountStatus == "ORIG"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.AccountStatus == "ACT"));
|
||||
|
||||
var accountUpdates = new List<ActivityAccountDetails>
|
||||
{
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 199,
|
||||
CurrentAccountStatus = "CLS"
|
||||
},
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 299,
|
||||
CurrentAccountStatus = "ACT"
|
||||
},
|
||||
//Account Update Found, but account did was not in "AccountsToUpdate"
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 399,
|
||||
CurrentAccountStatus = "BOO"
|
||||
},
|
||||
//Account Update Found, but account did was not in "AccountsToUpdate"
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 499,
|
||||
CurrentAccountStatus = "CLS"
|
||||
}
|
||||
};
|
||||
|
||||
_mockDnaService.Setup(x => x.GetNewAccountDetailsForActivities(It.IsAny<List<Activity>>())).ReturnsAsync(accountUpdates);
|
||||
|
||||
var results = await _activityDetailService.TryUpdateActivityAccountDetails(activities.Where(x => x.Detail.AccountStatus != "ACT").ToList());
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
activities = await _activityService.GetActivitiesAsync();
|
||||
Assert.NotNull(activities);
|
||||
Assert.AreEqual(5, activities.Count);
|
||||
Assert.AreEqual(2, activities.Count(x => x.Detail.AccountStatus == "APPR"));
|
||||
Assert.AreEqual(2, activities.Count(x => x.Detail.AccountStatus == "ORIG"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.AccountStatus == "ACT"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateActivityAccountDetails_NoAccountDetails_OK()
|
||||
{
|
||||
_mockDnaService.Setup(x => x.GetNewAccountDetailsForActivities(It.IsAny<List<Activity>>())).ReturnsAsync(new List<ActivityAccountDetails>());
|
||||
|
||||
var results = await _activityDetailService.TryUpdateActivityAccountDetails(new List<Activity>
|
||||
{
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "5",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "APPR"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "6",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "123",
|
||||
AccountStatus = "APPR"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "7",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "ORIG"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1", SourceId = "8",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "10",
|
||||
AccountStatus = "ACT"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "9",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "11",
|
||||
AccountStatus = "ORIG"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateActivityAccountDetails_NoActivities_OK()
|
||||
{
|
||||
var accountUpdates = new List<ActivityAccountDetails>
|
||||
{
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 199,
|
||||
CurrentAccountStatus = "CLS"
|
||||
},
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 299,
|
||||
CurrentAccountStatus = "ACT"
|
||||
},
|
||||
//Account Update Found, but account did was not in "AccountsToUpdate"
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 399,
|
||||
CurrentAccountStatus = "BOO"
|
||||
},
|
||||
//Account Update Found, but account did was not in "AccountsToUpdate"
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 499,
|
||||
CurrentAccountStatus = "CLS"
|
||||
}
|
||||
};
|
||||
|
||||
_mockDnaService.Setup(x => x.GetNewAccountDetailsForActivities(It.IsAny<List<Activity>>())).ReturnsAsync(accountUpdates);
|
||||
|
||||
var results = await _activityDetailService.TryUpdateActivityAccountDetails(new List<Activity>());
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateLicReferralStationDetail_Basic_Flow_OK()
|
||||
{
|
||||
var daysBeforeStationChange = 10;
|
||||
var activityAcceptedDate = DateTime.Now.AddDays(daysBeforeStationChange);
|
||||
await _activityService.SaveActivityRangeAsync(new[]
|
||||
{
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "5",
|
||||
Accepted = activityAcceptedDate,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "APPR",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "6",
|
||||
Accepted = activityAcceptedDate,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "123",
|
||||
AccountStatus = "APPR",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "7",
|
||||
Accepted = activityAcceptedDate,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "ORIG",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "8",
|
||||
Accepted = activityAcceptedDate,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "10",
|
||||
AccountStatus = "ACT",
|
||||
StationName = "LIC- In Progress"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1", SourceId = "9",
|
||||
Accepted = activityAcceptedDate,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "11",
|
||||
StationName = "LIC- SomethingElse"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var activities = await _activityService.GetActivitiesAsync();
|
||||
Assert.NotNull(activities);
|
||||
Assert.AreEqual(5, activities.Count);
|
||||
|
||||
var inStationDate = DateTime.Now;
|
||||
|
||||
var reQueriedActivityManagerIncentiveReferrals = new List<NewActivityManagerReferral>
|
||||
{
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 5,
|
||||
ReferralStation = "LIC Referral- Not Qualified",
|
||||
StationDateTime = inStationDate
|
||||
},
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 6,
|
||||
ReferralStation = "LIC Referral-Qualified",
|
||||
StationDateTime = inStationDate
|
||||
},
|
||||
//No change, should not be added to results
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 7,
|
||||
ReferralStation = "LIC- Submitted",
|
||||
StationDateTime = activityAcceptedDate
|
||||
},
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 8,
|
||||
ReferralStation = "LIC Referral- Not Qualified",
|
||||
StationDateTime = inStationDate
|
||||
},
|
||||
//Account Update Found, but account did was not in "AccountsToUpdate"
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 100,
|
||||
ReferralStation = "LIC- Station",
|
||||
StationDateTime = inStationDate
|
||||
}
|
||||
};
|
||||
|
||||
_mockDnaService.Setup(x => x.QueryActivityManagerForActivities(It.IsAny<List<string>>())).ReturnsAsync(reQueriedActivityManagerIncentiveReferrals);
|
||||
|
||||
var results = await _activityDetailService.TryUpdateLicReferralStationDetail(activities.ToList());
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(3, results.Count);
|
||||
Assert.False(results.Exists(x => x.SourceId == "7"));
|
||||
Assert.False(results.Exists(x => x.SourceId == "100"));
|
||||
|
||||
activities = await _activityService.GetActivitiesAsync();
|
||||
Assert.NotNull(activities);
|
||||
Assert.AreEqual(5, activities.Count);
|
||||
Assert.AreEqual(2, activities.Count(x => x.Detail.StationName == "LIC Referral- Not Qualified"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.StationName == "LIC- Submitted"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.StationName == "LIC Referral-Qualified"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.StationName == "LIC- SomethingElse"));
|
||||
|
||||
Assert.AreEqual("LIC Referral- Not Qualified", activities.Single(x => x.SourceId == "5").Detail.StationName);
|
||||
Assert.AreEqual(inStationDate.Date, results.Single(x => x.SourceId == "5").Accepted.Date);
|
||||
Assert.AreEqual("LIC Referral-Qualified", activities.Single(x => x.SourceId == "6").Detail.StationName);
|
||||
Assert.AreEqual(inStationDate.Date, results.Single(x => x.SourceId == "6").Accepted.Date);
|
||||
Assert.AreEqual("LIC- Submitted", activities.Single(x => x.SourceId == "7").Detail.StationName);
|
||||
Assert.AreEqual("LIC Referral- Not Qualified", activities.Single(x => x.SourceId == "8").Detail.StationName);
|
||||
Assert.AreEqual(inStationDate.Date, results.Single(x => x.SourceId == "8").Accepted.Date);
|
||||
Assert.AreEqual("LIC- SomethingElse", activities.Single(x => x.SourceId == "9").Detail.StationName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateLicReferralStationDetail_NoUpdates_OK()
|
||||
{
|
||||
await _activityService.SaveActivityRangeAsync(new[]
|
||||
{
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "5",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "APPR",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "6",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "123",
|
||||
AccountStatus = "APPR",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "7",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "ORIG",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "8",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "10",
|
||||
AccountStatus = "ACT",
|
||||
StationName = "LIC- In Progress"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "9",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "11",
|
||||
StationName = "LIC- SomethingElse"
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var activities = await _activityService.GetActivitiesAsync();
|
||||
Assert.NotNull(activities);
|
||||
Assert.AreEqual(5, activities.Count);
|
||||
Assert.AreEqual(5, activities.Count);
|
||||
Assert.AreEqual(3, activities.Count(x => x.Detail.StationName == "LIC- Submitted"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.StationName == "LIC- In Progress"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.StationName == "LIC- SomethingElse"));
|
||||
|
||||
var reQueriedActivityManagerIncentiveReferrals = new List<NewActivityManagerReferral>
|
||||
{
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 5000,
|
||||
ReferralStation = "LIC- Not Qualified"
|
||||
},
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 6000,
|
||||
ReferralStation = "LIC-Qualified"
|
||||
}
|
||||
};
|
||||
|
||||
_mockDnaService.Setup(x => x.QueryActivityManagerForActivities(It.IsAny<List<string>>())).ReturnsAsync(reQueriedActivityManagerIncentiveReferrals);
|
||||
|
||||
var results = await _activityDetailService.TryUpdateLicReferralStationDetail(activities.ToList());
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
activities = await _activityService.GetActivitiesAsync();
|
||||
Assert.NotNull(activities);
|
||||
Assert.AreEqual(5, activities.Count);
|
||||
Assert.AreEqual(3, activities.Count(x => x.Detail.StationName == "LIC- Submitted"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.StationName == "LIC- In Progress"));
|
||||
Assert.AreEqual(1, activities.Count(x => x.Detail.StationName == "LIC- SomethingElse"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateLicReferralStationDetail_NoAccountDetails_OK()
|
||||
{
|
||||
_mockDnaService.Setup(x => x.QueryActivityManagerForActivities(It.IsAny<List<string>>())).ReturnsAsync(new List<NewActivityManagerReferral>());
|
||||
|
||||
var results = await _activityDetailService.TryUpdateLicReferralStationDetail(new List<Activity>
|
||||
{
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "5",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "APPR",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "6",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "123",
|
||||
AccountStatus = "APPR",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "7",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "345",
|
||||
AccountStatus = "ORIG",
|
||||
StationName = "LIC- Submitted"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "8",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "10",
|
||||
AccountStatus = "ACT",
|
||||
StationName = "LIC- In Progress"
|
||||
}
|
||||
},
|
||||
new Activity
|
||||
{
|
||||
EmployeeId = "1",
|
||||
SourceId = "9",
|
||||
Accepted = DateTime.Now,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "11",
|
||||
StationName = "LIC- SomethingElse"
|
||||
}
|
||||
},
|
||||
});
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateLicReferralStationDetail_NoActivities_OK()
|
||||
{
|
||||
var reQueriedActivityManagerIncentiveReferrals = new List<NewActivityManagerReferral>
|
||||
{
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 5,
|
||||
ReferralStation = "LIC- Not Qualified"
|
||||
},
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 6,
|
||||
ReferralStation = "LIC-Qualified"
|
||||
},
|
||||
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 7,
|
||||
ReferralStation = "LIC- Submitted"
|
||||
},
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 8,
|
||||
ReferralStation = "LIC- Not Qualified"
|
||||
},
|
||||
//Account Update Found, but account did was not in "AccountsToUpdate"
|
||||
new NewActivityManagerReferral
|
||||
{
|
||||
ActivityId = 100,
|
||||
ReferralStation = "LIC- Station"
|
||||
}
|
||||
};
|
||||
|
||||
_mockDnaService.Setup(x => x.QueryActivityManagerForActivities(It.IsAny<List<string>>())).ReturnsAsync(reQueriedActivityManagerIncentiveReferrals);
|
||||
|
||||
var results = await _activityDetailService.TryUpdateLicReferralStationDetail(new List<Activity>());
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateDpEligibleLoanDetail_UpdatesActivity_OK()
|
||||
{
|
||||
var existingActivities = new List<Activity>
|
||||
{
|
||||
new Activity
|
||||
{
|
||||
Id = 1,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Product = Product.Vehicle,
|
||||
Type = ActivityType.Sale,
|
||||
Accepted = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceCreated = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
Id = 23786,
|
||||
AccountBalance = 12000,
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "ACT",
|
||||
DebtProtectionAddDate = null,
|
||||
DebtProtectionRemoveDate = null,
|
||||
IsDebtProtectionEligible = true,
|
||||
IsGapInsuranceEligible = true,
|
||||
MemberName = "ORLANDO TESTCUSTOMER10"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var accountUpdates = new List<ActivityAccountDetails>
|
||||
{
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 867530989,
|
||||
CurrentAccountStatus = "ACT",
|
||||
DebtProtectionEffectiveDate = DateTime.Parse("12/3/2021"),
|
||||
DebtProtectionInactiveDate = DateTime.Parse("1/18/2022")
|
||||
},
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 867530986,
|
||||
CurrentAccountStatus = "ACT",
|
||||
DebtProtectionEffectiveDate = DateTime.Parse("1/18/2022"),
|
||||
DebtProtectionInactiveDate = DateTime.Parse("1/18/2022")
|
||||
},
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 867530988,
|
||||
CurrentAccountStatus = "ACT",
|
||||
DebtProtectionEffectiveDate = DateTime.Parse("1/18/2022"),
|
||||
DebtProtectionInactiveDate = null
|
||||
}
|
||||
};
|
||||
|
||||
_mockDnaService.Setup(x => x.GetNewAccountDetailsForActivities(It.IsAny<List<Activity>>())).ReturnsAsync(accountUpdates);
|
||||
var results = await _activityDetailService.TryUpdateDpEligibleLoanDetail(existingActivities);
|
||||
|
||||
Assert.AreEqual(DateTime.Parse("1/18/2022").Date.AddHours(12), existingActivities.FirstOrDefault()?.Detail.DebtProtectionAddDate);
|
||||
Assert.AreEqual(DateTime.Parse("1/18/2022").Date.AddHours(12), existingActivities.FirstOrDefault()?.Detail.DebtProtectionRemoveDate);
|
||||
Assert.AreEqual(true, existingActivities.FirstOrDefault()?.Detail.IsDebtProtectionEligible);
|
||||
Assert.AreEqual(true, existingActivities.FirstOrDefault()?.Detail.IsGapInsuranceEligible);
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsNotEmpty(results);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryUpdateDpEligibleLoanDetail_ReturnsEmpty_OK()
|
||||
{
|
||||
var existingActivities = new List<Activity>
|
||||
{
|
||||
new Activity
|
||||
{
|
||||
Id = 1,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Accepted = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceCreated = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
Id = 23786,
|
||||
AccountBalance = 12000,
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "ACT",
|
||||
DebtProtectionAddDate = DateTime.Parse("1/18/2022").Date.AddHours(12),
|
||||
DebtProtectionRemoveDate = null,
|
||||
IsDebtProtectionEligible = true,
|
||||
IsGapInsuranceEligible = true,
|
||||
MemberName = "ORLANDO TESTCUSTOMER10"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var accountUpdates = new List<ActivityAccountDetails>
|
||||
{
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 867530986,
|
||||
CurrentAccountStatus = "ACT",
|
||||
DebtProtectionEffectiveDate = DateTime.Parse("12/3/2021"),
|
||||
DebtProtectionInactiveDate = DateTime.Parse("1/18/2022")
|
||||
},
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 867530986,
|
||||
CurrentAccountStatus = "ACT",
|
||||
DebtProtectionEffectiveDate = DateTime.Parse("1/18/2022"),
|
||||
DebtProtectionInactiveDate = DateTime.Parse("1/18/2022")
|
||||
},
|
||||
new ActivityAccountDetails
|
||||
{
|
||||
AccountNumber = 867530986,
|
||||
CurrentAccountStatus = "ACT",
|
||||
DebtProtectionEffectiveDate = DateTime.Parse("1/18/2022"),
|
||||
DebtProtectionInactiveDate = null
|
||||
}
|
||||
};
|
||||
|
||||
_mockDnaService.Setup(x => x.GetNewAccountDetailsForActivities(It.IsAny<List<Activity>>())).ReturnsAsync(accountUpdates);
|
||||
|
||||
var results = await _activityDetailService.TryUpdateDpEligibleLoanDetail(existingActivities);
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
Assert.AreEqual(true, existingActivities.FirstOrDefault()?.Detail.IsDebtProtectionEligible);
|
||||
Assert.AreEqual(true, existingActivities.FirstOrDefault()?.Detail.IsGapInsuranceEligible);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2951
File diff suppressed because it is too large
Load Diff
+945
@@ -0,0 +1,945 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using CsvHelper;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Allied;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.AutoDecision;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Allied;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
|
||||
namespace Application.UnitTests.Services.Allied
|
||||
{
|
||||
public class AlliedTransactionImportServiceTest
|
||||
{
|
||||
private IAlliedGapMbpTransactionImportService _service;
|
||||
private IUserRepository _userRepository;
|
||||
private IActivityService _activityService;
|
||||
private IActivityDecisionService _activityDecisionService;
|
||||
private IActivityDetailService _activityDetailService;
|
||||
private DebtProtectionAccessoryService _debtProtectionAccessoryService;
|
||||
private IDnaService _dnaService;
|
||||
private IFileOperationsApiService _fileOperationsApiService;
|
||||
private Mock<IDeadActivityService> _deadActivityService;
|
||||
private IGapInsuranceActivityService _gapInsuranceActivityService;
|
||||
private Mock<IActivityRepository> _activityRepository;
|
||||
private Mock<IUnitOfWork> _unitOfWork;
|
||||
private int _expectedRecordCount;
|
||||
private string _testDataFilePath;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var strategies = new List<IDecisionStrategy>
|
||||
{
|
||||
new DebtProtectionEligibleLoanDecisionStrategy(),
|
||||
new GapDecisionStrategy(),
|
||||
new ManualDecisionStrategy(),
|
||||
new MbpDecisionStrategy(),
|
||||
new MortgageSaleDecisionStrategy(),
|
||||
new NewCheckingDecisionStrategy(),
|
||||
new ReferralDecisionStrategy(),
|
||||
new VehicleDecisionStrategy()
|
||||
};
|
||||
_userRepository = Mock.Of<IUserRepository>();
|
||||
_fileOperationsApiService = Mock.Of<IFileOperationsApiService>();
|
||||
_activityService = Mock.Of<IActivityService>();
|
||||
_activityDetailService = Mock.Of<IActivityDetailService>();
|
||||
_debtProtectionAccessoryService = new DebtProtectionAccessoryService(_activityService, _activityDetailService);
|
||||
_dnaService = Mock.Of<IDnaService>();
|
||||
_activityDecisionService = new ActivityDecisionService(strategies, _activityService, _activityDetailService, _debtProtectionAccessoryService, _dnaService);
|
||||
_deadActivityService = new Mock<IDeadActivityService>();
|
||||
_activityRepository = new Mock<IActivityRepository>();
|
||||
_unitOfWork = new Mock<IUnitOfWork>();
|
||||
_gapInsuranceActivityService = new GapInsuranceActivityService(_activityDetailService, _activityRepository.Object, _activityService, _unitOfWork.Object);
|
||||
_service = new AlliedGapMbpTransactionImportService(
|
||||
_userRepository,
|
||||
_gapInsuranceActivityService,
|
||||
_fileOperationsApiService,
|
||||
_activityService,
|
||||
_activityDecisionService,
|
||||
_activityDetailService,
|
||||
_deadActivityService.Object
|
||||
);
|
||||
_expectedRecordCount = 12;
|
||||
_testDataFilePath = @"Services/Allied/SalesWithCancellationsByEmployee.csv";
|
||||
}
|
||||
|
||||
public StreamReader GetAlliedFile()
|
||||
{
|
||||
var path = _testDataFilePath;
|
||||
var reader = new StreamReader(path);
|
||||
return reader;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessFileNames_OK()
|
||||
{
|
||||
var department = new Department()
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment()
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
user.Departments.Add(assignment);
|
||||
|
||||
var request = new AlliedGapMbpRequest
|
||||
{
|
||||
DynamicFileName = "alliedgapmbp",
|
||||
FilePath = "clean",
|
||||
DynamicFileSettings = new DynamicNameSetting() { }
|
||||
};
|
||||
|
||||
var files = new string[]
|
||||
{
|
||||
"x"
|
||||
};
|
||||
|
||||
byte[] array = File.ReadAllBytes(_testDataFilePath);
|
||||
|
||||
//Setup
|
||||
Mock.Get(_fileOperationsApiService).Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(files);
|
||||
Mock.Get(_fileOperationsApiService).Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(array.ToString());
|
||||
Mock.Get(_userRepository).Setup(s => s.SearchUsersAsync(It.IsAny<UserSearchRequest>())).ReturnsAsync(new List<AppUser>() { user });
|
||||
|
||||
var results = await _service.ImportTransactions<AlliedSaleRow>(request);
|
||||
var activities = await _service.CreateActivity(It.IsAny<IEnumerable<AlliedSaleRow>>());
|
||||
Mock.Get(_fileOperationsApiService).Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
Assert.AreEqual("alliedgapmbp", request.DynamicFileName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessCsv_OK()
|
||||
{
|
||||
SetupTestUsers();
|
||||
SetupTestActivities();
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
var alliedSaleRows = transactions.ToList();
|
||||
Assert.IsNotEmpty(alliedSaleRows);
|
||||
Assert.AreEqual(_expectedRecordCount, alliedSaleRows.Count());
|
||||
|
||||
var results = await _service.CreateActivity(alliedSaleRows);
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(_expectedRecordCount, results.Count);
|
||||
Assert.AreEqual(_expectedRecordCount, results.Count(x => x.SourceSystem == SystemType.Allied));
|
||||
}
|
||||
|
||||
public IEnumerable<AlliedSaleRow> ImportTestTransactions()
|
||||
{
|
||||
var input = GetAlliedFile();
|
||||
var csvReader = new CsvReader(input, CultureInfo.InvariantCulture);
|
||||
return csvReader.GetRecords<AlliedSaleRow>().ToList();
|
||||
}
|
||||
|
||||
public void SetupTestUsers()
|
||||
{
|
||||
var department = new Department()
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
|
||||
var testUsers = new List<AppUser>
|
||||
{
|
||||
new()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Abraham TestAssociate1",
|
||||
Id = Guid.NewGuid(),
|
||||
Departments = new List<UserDepartment>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = null,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
}
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11772",
|
||||
FullName = "Franchelie TestAssociate2",
|
||||
Id = Guid.NewGuid(),
|
||||
Departments = new List<UserDepartment>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 100,
|
||||
Department = department,
|
||||
Employee = null,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
}
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11773",
|
||||
FullName = "Stefani TestAssociate3",
|
||||
Id = Guid.NewGuid(),
|
||||
Departments = new List<UserDepartment>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 101,
|
||||
Department = department,
|
||||
Employee = null,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
}
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11774",
|
||||
FullName = "Amarisa TestAssociate4",
|
||||
Id = Guid.NewGuid(),
|
||||
Departments = new List<UserDepartment>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 102,
|
||||
Department = department,
|
||||
Employee = null,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
}
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11774",
|
||||
FullName = "Amalia TestAssociate5",
|
||||
Id = Guid.NewGuid(),
|
||||
Departments = new List<UserDepartment>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 103,
|
||||
Department = department,
|
||||
Employee = null,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var user in testUsers)
|
||||
{
|
||||
user.Departments.First().Employee = user;
|
||||
Mock.Get(_userRepository)
|
||||
.Setup(r => r.SearchUsersAsync(It.Is<UserSearchRequest>(x => x.Query == user.FullName)))
|
||||
.ReturnsAsync(new List<AppUser> { testUsers.First(x => x.FullName == user.FullName) });
|
||||
}
|
||||
}
|
||||
|
||||
public void SetupTestActivities()
|
||||
{
|
||||
var existingActivities = new List<Activity>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.GAPInsurance,
|
||||
Accepted = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceCreated = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceSystem = SystemType.Allied,
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.GAPInsurance,
|
||||
Accepted = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceCreated = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceSystem = SystemType.Allied,
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "8675309861",
|
||||
MemberName = "ORLANDO TESTCUSTOMER11"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 3,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.GAPInsurance,
|
||||
Accepted = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceCreated = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceSystem = SystemType.Allied,
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "8675309862",
|
||||
MemberName = "ORLANDO TESTCUSTOMER12"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var queryActivity in existingActivities)
|
||||
{
|
||||
Mock.Get(_activityService)
|
||||
.Setup(r => r
|
||||
.GetActivityForStateUpdate(It.Is<Activity>(x => x.EmployeeId == queryActivity.EmployeeId
|
||||
&& x.Product == queryActivity.Product
|
||||
&& x.Detail.AccountNumber == queryActivity.Detail.AccountNumber
|
||||
)))
|
||||
.ReturnsAsync(existingActivities.First(x => x.EmployeeId == queryActivity.EmployeeId
|
||||
&& x.Product == queryActivity.Product
|
||||
&& x.Detail.AccountNumber == queryActivity.Detail.AccountNumber
|
||||
));
|
||||
|
||||
Mock.Get(_activityService)
|
||||
.Setup(r => r
|
||||
.GetActivityForDetailUpdate(It.Is<Activity>(x => x.EmployeeId == queryActivity.EmployeeId
|
||||
&& x.Product == queryActivity.Product
|
||||
&& x.Detail.AccountNumber == queryActivity.Detail.AccountNumber
|
||||
)))
|
||||
.ReturnsAsync(existingActivities.First(x => x.EmployeeId == queryActivity.EmployeeId
|
||||
&& x.Product == queryActivity.Product
|
||||
&& x.Detail.AccountNumber == queryActivity.Detail.AccountNumber
|
||||
));
|
||||
|
||||
Mock.Get(_activityService)
|
||||
.Setup(r => r
|
||||
.GetActivity(It.IsAny<int>()))
|
||||
.ReturnsAsync(existingActivities.First(x => x.Id == queryActivity.Id
|
||||
));
|
||||
|
||||
Mock.Get(_activityService)
|
||||
.Setup(r => r
|
||||
.CreateAndRetrieveActivity(It.Is<Activity>(x =>
|
||||
x.AppUserId == queryActivity.AppUserId
|
||||
&& x.EmployeeId == queryActivity.EmployeeId
|
||||
&& x.Product == queryActivity.Product
|
||||
&& x.Detail.AccountNumber == queryActivity.Detail.AccountNumber
|
||||
&& x.Detail.SubAccountNumber == queryActivity.Detail.SubAccountNumber
|
||||
)))
|
||||
.ReturnsAsync(existingActivities.First(x =>
|
||||
x.AppUserId == queryActivity.AppUserId
|
||||
&& x.EmployeeId == queryActivity.EmployeeId
|
||||
&& x.Product == queryActivity.Product
|
||||
&& x.Detail.AccountNumber == queryActivity.Detail.AccountNumber
|
||||
&& x.Detail.SubAccountNumber == queryActivity.Detail.SubAccountNumber
|
||||
));
|
||||
}
|
||||
|
||||
Mock.Get(_activityService)
|
||||
.Setup(r => r
|
||||
.CreateAndRetrieveActivity(It.IsAny<Activity>()))
|
||||
.ReturnsAsync(new Activity()
|
||||
{
|
||||
AppUserId = Guid.NewGuid(),
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.GAPInsurance,
|
||||
Accepted = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceCreated = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceSystem = SystemType.Allied,
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "8675309862",
|
||||
MemberName = "ORLANDO TESTCUSTOMER12"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenNoUserFound()
|
||||
{
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(_expectedRecordCount, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == _expectedRecordCount &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("allied import, no user for")))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenFindingUserFails()
|
||||
{
|
||||
Mock.Get(_userRepository)
|
||||
.Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>()))
|
||||
.Throws(new Exception("OOops"));
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(_expectedRecordCount, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == _expectedRecordCount &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("allied import, no user for")))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenTooManyUserFound()
|
||||
{
|
||||
Mock.Get(_userRepository)
|
||||
.Setup(s => s.SearchUsersAsync(It.IsAny<UserSearchRequest>()))
|
||||
.ReturnsAsync(new List<AppUser>()
|
||||
{ new() { EmployeeId = "One" }, new() { EmployeeId = "Two" } });
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(_expectedRecordCount, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == _expectedRecordCount &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("allied import, no user for")))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_WhenNoHomeDepartmentFound()
|
||||
{
|
||||
//Use one user for all lines for simplicity
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
|
||||
Mock.Get(_userRepository).Setup(s => s.SearchUsersAsync(It.IsAny<UserSearchRequest>())).ReturnsAsync(new List<AppUser> { user });
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(_expectedRecordCount, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == _expectedRecordCount &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("reliably determinable home")))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SavesDeadActivity_BothKinds()
|
||||
{
|
||||
var noHomeDepartmentUser = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11773",
|
||||
FullName = "Stefani TestAssociate3",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
|
||||
Mock.Get(_userRepository)
|
||||
.Setup(s => s.SearchUsersAsync(It.Is<UserSearchRequest>(x => x.Query == noHomeDepartmentUser.FullName)))
|
||||
.ReturnsAsync(new List<AppUser> { noHomeDepartmentUser });
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
var expectedHomelessDeadRecordCount = transactions.Count(x => x.Quoter == noHomeDepartmentUser.FullName);
|
||||
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(_expectedRecordCount, transactions.Count());
|
||||
|
||||
var results = await _service.CreateActivity(transactions);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("allied import, no user for")) ==
|
||||
_expectedRecordCount - expectedHomelessDeadRecordCount)));
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count(y =>
|
||||
y.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
y.ReasonNote.ToLowerInvariant().Contains("reliably determinable home")) == expectedHomelessDeadRecordCount)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FailToSaveDeadActivity_DoesntThrow()
|
||||
{
|
||||
Mock.Get(_userRepository).Setup(s => s.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
_deadActivityService.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var transactions = ImportTestTransactions();
|
||||
Assert.NotNull(transactions);
|
||||
Assert.IsNotEmpty(transactions);
|
||||
Assert.AreEqual(_expectedRecordCount, transactions.Count());
|
||||
|
||||
List<Activity> results = null;
|
||||
Assert.DoesNotThrowAsync(async () =>
|
||||
{
|
||||
var res = await _service.CreateActivity(transactions);
|
||||
results = res.ToList();
|
||||
});
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
|
||||
_deadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(
|
||||
da =>
|
||||
da.Count() == _expectedRecordCount &&
|
||||
da.All(y => y.Reason == DeadActivityReason.MissingRequiredField) &&
|
||||
da.All(y => y.ReasonNote.ToLowerInvariant().Contains("allied import, no user for")))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FilterAndOrderUpdates_DefaultWithNullExisting()
|
||||
{
|
||||
var sourceCreatedNewer = DateTime.Today.Subtract(TimeSpan.FromDays(3));
|
||||
var sourceCreatedOlder = DateTime.Today.Subtract(TimeSpan.FromDays(7));
|
||||
|
||||
var activityProcessingOrder = new ActivityProcessingOrder
|
||||
{
|
||||
ExistingActivity = null,
|
||||
ActivityUpdateItems = new List<Activity>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Cancelled",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Flagged",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedNewer,
|
||||
SourceCreated = sourceCreatedNewer,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Sold",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Reinstated",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Sold",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Cancelled/Re-Quoted",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
activityProcessingOrder = _service.FilterAndOrderUpdates(activityProcessingOrder);
|
||||
|
||||
Assert.AreEqual(6, activityProcessingOrder.ActivityUpdateItems.Count);
|
||||
|
||||
Assert.AreEqual(0, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Flagged"));
|
||||
Assert.AreEqual(1, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Sold" && x.SourceCreated == sourceCreatedOlder));
|
||||
Assert.AreEqual(2, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Cancelled/Re-Quoted"));
|
||||
Assert.AreEqual(3, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Cancelled"));
|
||||
Assert.AreEqual(4, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Reinstated"));
|
||||
Assert.AreEqual(5, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.SourceCreated == sourceCreatedNewer));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FilterAndOrderUpdates_DefaultWithNonNullExisting()
|
||||
{
|
||||
var sourceCreatedNewer = DateTime.Today.Subtract(TimeSpan.FromDays(3));
|
||||
var sourceCreatedOlder = DateTime.Today.Subtract(TimeSpan.FromDays(7));
|
||||
|
||||
var activityProcessingOrder = new ActivityProcessingOrder
|
||||
{
|
||||
ExistingActivity = new Activity
|
||||
{
|
||||
Id = 1,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Cancelled/Re-Quoted",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
ActivityUpdateItems = new List<Activity>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Cancelled",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Flagged",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedNewer,
|
||||
SourceCreated = sourceCreatedNewer,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Sold",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Reinstated",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Sold",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.MechanicalBreakdownProtection,
|
||||
Accepted = sourceCreatedOlder,
|
||||
SourceCreated = sourceCreatedOlder,
|
||||
SourceId = "1",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
AccountStatus = "Cancelled/Re-Quoted",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "8675309-AAG"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
activityProcessingOrder = _service.FilterAndOrderUpdates(activityProcessingOrder);
|
||||
|
||||
Assert.AreEqual(4, activityProcessingOrder.ActivityUpdateItems.Count);
|
||||
|
||||
// These items should return an index of -1 since they should be removed in order to not run already run updates against the existing item
|
||||
Assert.AreEqual(-1, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Flagged"));
|
||||
Assert.AreEqual(-1, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Sold" && x.SourceCreated == sourceCreatedOlder));
|
||||
Assert.AreEqual(0, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Cancelled/Re-Quoted"));
|
||||
Assert.AreEqual(1, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Cancelled"));
|
||||
Assert.AreEqual(2, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.Detail.AccountStatus == "Reinstated"));
|
||||
Assert.AreEqual(3, activityProcessingOrder.ActivityUpdateItems.FindIndex(x => x.SourceCreated == sourceCreatedNewer));
|
||||
}
|
||||
|
||||
[TestCase(ActivityState.PendingTransfer, 0, true)] // Activity exists, is pending transfer, and not updated
|
||||
[TestCase(ActivityState.Rejected, 0, true)] // Activity exists, is pending transfer, and not updated
|
||||
[TestCase(ActivityState.Transferred, 0, true)] // Activity exists, is pending transfer, and not updated
|
||||
[TestCase(ActivityState.Accepted, 1, false)] // Activity does not exist and is created
|
||||
[TestCase(ActivityState.Accepted, 0, true)] // Activity exists and is not created
|
||||
[Test]
|
||||
public async Task CreateActivity_ExistingActivityInVariousStates_ReturnsExpectedResultsCount(ActivityState activityState, int expectedResultCount, bool returnsActivity)
|
||||
{
|
||||
SetupTestUsers();
|
||||
var transactions = new List<AlliedSaleRow>()
|
||||
{
|
||||
new AlliedSaleRow()
|
||||
{
|
||||
AccountNumber = "1234",
|
||||
Origin = "LenderWebsite",
|
||||
ProductType = "GAP",
|
||||
Status = "Sold",
|
||||
SaleDate = DateTime.Now.ToString(),
|
||||
Buyer = "Buyer",
|
||||
SalesContractNumber = "1",
|
||||
Issuer = "Abraham TestAssociate1"
|
||||
}
|
||||
};
|
||||
|
||||
var existingActivity = new Activity()
|
||||
{
|
||||
Id = 1,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.GAPInsurance,
|
||||
Accepted = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceCreated = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceSystem = SystemType.Allied,
|
||||
State = activityState,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "1",
|
||||
AccountStatus = "Sold"
|
||||
}
|
||||
};
|
||||
|
||||
var newlyCreatedActivity = new Activity()
|
||||
{
|
||||
Id = 1,
|
||||
DepartmentId = 55,
|
||||
EmployeeId = "11774",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.GAPInsurance,
|
||||
Accepted = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceCreated = DateTime.Today.Subtract(TimeSpan.FromDays(7)),
|
||||
SourceSystem = SystemType.Allied,
|
||||
State = returnsActivity == true ? activityState : ActivityState.Created, // if an activity does not exist, the new activity is initially in Created state
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "867530986",
|
||||
MemberName = "ORLANDO TESTCUSTOMER10",
|
||||
SubAccountNumber = "1",
|
||||
AccountStatus = "Sold"
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_activityService)
|
||||
.Setup(a => a.GetActivityForDetailUpdate(It.IsAny<Activity>()))
|
||||
.ReturnsAsync(returnsActivity == true ? existingActivity : (Activity)null);
|
||||
|
||||
Mock.Get(_activityService)
|
||||
.Setup(a => a.CreateAndRetrieveActivity(It.IsAny<Activity>()))
|
||||
.ReturnsAsync(newlyCreatedActivity);
|
||||
|
||||
var resutls = await _service.CreateActivity(transactions);
|
||||
|
||||
Assert.IsNotNull(resutls);
|
||||
Assert.AreEqual(expectedResultCount, resutls.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
Quoter,Issuer,Origin,Product_Type,Status,Sale_Date,Sale_Effective_Date,Cancellation_Date,Cancellation_Reason,Cancelled_By,Sales_Contract_Number,Buyer,Account_Number,LOS_LOAN_APP_ID_TX,Program_Type,Buyer_Cost,Flagged_Reasons
|
||||
Abraham TestAssociate1,Abraham TestAssociate1,Lender Website,GAP,Sold,11/13/2021,11/13/2021,,,,,RENEE TESTCUSTOMER1,1234567,,Standard,395.00,
|
||||
Franchelie TestAssociate2,Franchelie TestAssociate2,Lender Website,MBP,Sold,11/13/2021,11/13/2021,,,,86753619-AAG,MAYRIN TESTCUSTOMER2,9876543,,Standard,395.00,
|
||||
Stefani TestAssociate3,Stefani TestAssociate3,Lender Website,GAP,Sold,11/13/2021,11/13/2021,,,,,JAMES TESTCUSTOMER3,11234567844,,Standard,395.00,
|
||||
Franchelie TestAssociate2,Franchelie TestAssociate2,Lender Website,GAP,Sold,11/12/2021,11/12/2021,,,,,JOSE TESTCUSTOMER4,19618823214,,Standard,395.00,
|
||||
Franchelie TestAssociate2,Franchelie TestAssociate2,Lender Website,GAP,Sold,11/12/2021,11/12/2021,,,,,GUSTAVO TESTCUSTOMER5,97456322603,,Standard,395.00,
|
||||
Amarisa TestAssociate4,Amarisa TestAssociate4,Lender Website,MBP,Sold,11/12/2021,11/12/2021,,,,10253867-AAG,ALESSANDRO TESTCUSTOMER6,75315927194,,Standard,395.00,
|
||||
Amarisa TestAssociate4,Amarisa TestAssociate4,Lender Website,GAP,Sold,11/12/2021,11/12/2021,,,,,JACOB TESTCUSTOMER7,19137958748,,Standard,395.00,
|
||||
Amarisa TestAssociate4,Amarisa TestAssociate4,Lender Website,GAP,Sold,11/12/2021,11/15/2021,,,,,FRANK TESTCUSTOMER8,19852347569,,Standard,395.00,
|
||||
Abraham TestAssociate1,Abraham TestAssociate1,Lender Website,GAP,Flagged,11/12/2021,11/12/2021,,,,,MARIA TESTCUSTOMER9,11103254770,,Standard,395.00,
|
||||
Amalia TestAssociate5,Amalia TestAssociate5,Lender Website,GAP,Cancelled/Re-Quoted,10/25/2021,10/25/2021,10/26/2021,Buyer Changed Mind,[email protected],,ORLANDO TESTCUSTOMER10,867530986,,Standard,395.00,
|
||||
Amalia TestAssociate5,Amalia TestAssociate5,Lender Website,GAP,Cancelled,10/23/2021,10/23/2021,,,,,ORLANDO TESTCUSTOMER11,8675309861,,Standard,395.00, Quoter Changed,
|
||||
Amalia TestAssociate5,Amalia TestAssociate5,Lender Website,GAP,Cancelled,10/22/2021,10/22/2021,10/27/2021,Loan Did Not Close,[email protected],,ORLANDO TESTCUSTOMER12,8675309862,,Standard,395.00,
|
||||
|
+491
@@ -0,0 +1,491 @@
|
||||
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.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class AuthorizationServiceTest
|
||||
{
|
||||
private IAuthorizationService _service;
|
||||
private IDepartmentRepository _departmentRepository;
|
||||
private IUserAssignmentRepository _userAssignmentRepository;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_departmentRepository = Mock.Of<IDepartmentRepository>();
|
||||
_userAssignmentRepository = Mock.Of<IUserAssignmentRepository>();
|
||||
_service = new AuthorizationService(_departmentRepository, _userAssignmentRepository);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AppUserCanMakeStateChange_UserIsAdmin_ReturnsTrue()
|
||||
{
|
||||
var inThePast = DateTime.Now.AddDays(-90);
|
||||
|
||||
var user = new AppUser
|
||||
{
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
StartDate = inThePast,
|
||||
EndDate = inThePast.AddDays(-30),
|
||||
Role = Role.BM
|
||||
},
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 2,
|
||||
StartDate = inThePast,
|
||||
EndDate = null,
|
||||
Role = Role.Admin
|
||||
},
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 3,
|
||||
StartDate = inThePast,
|
||||
EndDate = null,
|
||||
Role = Role.Mortgage
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _service.AppUserCanMakeStateChange(user, It.IsAny<Activity>(), It.IsAny<ActivityState>(), It.IsAny<int>());
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AppUserCanMakeStateChange_UserHasPermissionInTargetDepartment_ReturnsTrue()
|
||||
{
|
||||
var inThePast = DateTime.Now.AddDays(-90);
|
||||
var targetDepartmentId = 2;
|
||||
var activity = new Activity()
|
||||
{
|
||||
State = ActivityState.PendingTransfer,
|
||||
DepartmentId = 1,
|
||||
};
|
||||
|
||||
var user = new AppUser
|
||||
{
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
StartDate = inThePast,
|
||||
EndDate = inThePast.AddDays(-30),
|
||||
Role = Role.Manager
|
||||
},
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
StartDate = inThePast,
|
||||
EndDate = null,
|
||||
Role = Role.Mortgage
|
||||
},
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = targetDepartmentId,
|
||||
StartDate = inThePast,
|
||||
EndDate = null,
|
||||
Role = Role.Manager
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _service.AppUserCanMakeStateChange(user, activity, ActivityState.Accepted, targetDepartmentId);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AppUserCanMakeStateChange_UserDoesNotHavePermissionInTargetDepartment_ReturnsFalse()
|
||||
{
|
||||
var inThePast = DateTime.Now.AddDays(-90);
|
||||
var targetDepartmentId = 5;
|
||||
var activity = new Activity()
|
||||
{
|
||||
State = ActivityState.PendingTransfer,
|
||||
DepartmentId = 1,
|
||||
};
|
||||
|
||||
var user = new AppUser
|
||||
{
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
StartDate = inThePast,
|
||||
EndDate = inThePast.AddDays(-30),
|
||||
Role = Role.Manager
|
||||
},
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 2,
|
||||
StartDate = inThePast,
|
||||
EndDate = null,
|
||||
Role = Role.Mortgage
|
||||
},
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 3,
|
||||
StartDate = inThePast,
|
||||
EndDate = null,
|
||||
Role = Role.Manager
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _service.AppUserCanMakeStateChange(user, activity, ActivityState.Accepted, targetDepartmentId);
|
||||
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AppUserCanMakeStateChange_UserHasAdditionalPermissions_ReturnsTrue()
|
||||
{
|
||||
var inThePast = DateTime.Now.AddDays(-90);
|
||||
var targetDepartmentId = 5;
|
||||
var activity = new Activity()
|
||||
{
|
||||
State = ActivityState.PendingTransfer,
|
||||
DepartmentId = 1,
|
||||
};
|
||||
|
||||
var user = new AppUser
|
||||
{
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
StartDate = inThePast,
|
||||
EndDate = null,
|
||||
Role = Role.Mortgage
|
||||
}
|
||||
},
|
||||
AdditionalPermissions = new List<UserPermission>() {
|
||||
new UserPermission()
|
||||
{
|
||||
Permission = Permission.SetActivityToAcceptedFromPendingTransfer
|
||||
},
|
||||
new UserPermission()
|
||||
{
|
||||
Permission = Permission.SetActivityToTransferredFromPendingTransfer
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _service.AppUserCanMakeStateChange(user, activity, ActivityState.Accepted, targetDepartmentId);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HierarchicalDepartmentPermissionTest_Direct()
|
||||
{
|
||||
var testDepartment = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
DepartmentName = "TestName",
|
||||
RegionCode = Region.North.Code
|
||||
};
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]", EmployeeId = "C0000",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Department = testDepartment,
|
||||
StartDate = yesterday,
|
||||
Role = Role.BOM
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_departmentRepository).Setup(mock => mock.FindDepartmentsByRegionAsync(Region.North)).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
testDepartment
|
||||
});
|
||||
|
||||
var result = await _service.ValidateHierarchicalDepartmentPermission(user, new List<Role>() { Role.BOM }, testDepartment.Id.Value);
|
||||
Assert.True(result);
|
||||
result = await _service.ValidateHierarchicalDepartmentPermission(user, new List<Role>() { Role.BOM }, 99);
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HierarchicalDepartmentPermissionTest_Admin()
|
||||
{
|
||||
var testDepartment = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
DepartmentName = "TestName"
|
||||
};
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]", EmployeeId = "C0000",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Department = testDepartment,
|
||||
StartDate = yesterday,
|
||||
Role = Role.Admin
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _service.ValidateHierarchicalDepartmentPermission(user, new List<Role>(), testDepartment.Id.Value);
|
||||
Assert.True(result);
|
||||
result = await _service.ValidateHierarchicalDepartmentPermission(user, new List<Role>(), 99);
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[TestCase(true, 1, true)]
|
||||
[TestCase(false, 1, false)]
|
||||
public async Task HierarchicalDepartmentPermissionTest_VariedActiveRoleForDepartment(bool isAdmin, int activeDeptId, bool expected)
|
||||
{
|
||||
var inThePast = DateTime.Now.AddDays(-90);
|
||||
|
||||
var user = new AppUser
|
||||
{
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 2,
|
||||
StartDate = inThePast,
|
||||
EndDate = inThePast.AddDays(-30),
|
||||
Role = isAdmin ? Role.Admin : Role.ABM
|
||||
},
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = activeDeptId,
|
||||
StartDate = inThePast,
|
||||
EndDate = null,
|
||||
Role = isAdmin ? Role.Admin : Role.ManagementTraineePFO
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = await _service.ValidateHierarchicalDepartmentPermission(user, Role.DepartmentManagerRoles, activeDeptId);
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RegionalManagerTest()
|
||||
{
|
||||
var testDepartment = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
DepartmentName = "TestName",
|
||||
RegionCode = Region.North.Code
|
||||
};
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]", EmployeeId = "C0000",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Department = testDepartment,
|
||||
StartDate = yesterday,
|
||||
Role = Role.RegionalManager
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_departmentRepository).Setup(mock => mock.FindDepartmentsByRegionAsync(Region.North)).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
testDepartment
|
||||
});
|
||||
|
||||
var result = await _service.ValidateIsRegionalManager(user, testDepartment.Id.Value);
|
||||
Assert.True(result);
|
||||
result = await _service.ValidateIsRegionalManager(user, 99);
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RegionalManager_NoRegion_Test()
|
||||
{
|
||||
var testDepartment = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
DepartmentName = "TestName"
|
||||
};
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]", EmployeeId = "C0000",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Department = testDepartment,
|
||||
StartDate = yesterday,
|
||||
Role = Role.RegionalManager
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_departmentRepository).Setup(mock => mock.FindDepartmentsByRegionAsync(Region.North)).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
testDepartment
|
||||
});
|
||||
|
||||
var result = await _service.ValidateIsRegionalManager(user, testDepartment.Id.Value);
|
||||
Assert.True(result);
|
||||
result = await _service.ValidateIsRegionalManager(user, 99);
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
// User is RM in a non-region department, but is RM of NORTH.
|
||||
[Test]
|
||||
public async Task RegionalManager_NoRegion_OfficialRM_Test()
|
||||
{
|
||||
var testDepartment = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
DepartmentName = "TestName"
|
||||
};
|
||||
var testDepartmentNorth = new Department()
|
||||
{
|
||||
Id = 6,
|
||||
DepartmentName = "TestName",
|
||||
RegionCode = Region.North.Code
|
||||
};
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]", EmployeeId = "C0000",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Department = testDepartment,
|
||||
StartDate = yesterday,
|
||||
Role = Role.RegionalManager
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_userAssignmentRepository).Setup(mock => mock.IsUserAssigned(AssignmentType.RegionalManager, user))
|
||||
.ReturnsAsync(
|
||||
new UserAssignment()
|
||||
{
|
||||
Key = Region.North.Code
|
||||
});
|
||||
Mock.Get(_departmentRepository).Setup(mock => mock.FindDepartmentsByRegionAsync(Region.North)).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
testDepartmentNorth
|
||||
});
|
||||
|
||||
var result = await _service.ValidateIsRegionalManager(user, testDepartmentNorth.Id.Value);
|
||||
Assert.True(result);
|
||||
result = await _service.ValidateIsRegionalManager(user, 99);
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task BusinessLineManagerTest()
|
||||
{
|
||||
var testDepartment = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
DepartmentName = "TestName",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
};
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]", EmployeeId = "C0000",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Department = testDepartment,
|
||||
StartDate = yesterday,
|
||||
Role = Role.BusinessLineManager
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_departmentRepository)
|
||||
.Setup(mock => mock.FindDepartmentsByBusinessLineAsync(BusinessLine.Operations)).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
testDepartment
|
||||
});
|
||||
|
||||
var result = await _service.ValidateIsBusinessLineManager(user, testDepartment.Id.Value);
|
||||
Assert.True(result);
|
||||
result = await _service.ValidateIsBusinessLineManager(user, 99);
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task BusinessLineManager_NoBusinessLine_Test()
|
||||
{
|
||||
var testDepartment = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
DepartmentName = "TestName"
|
||||
};
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]", EmployeeId = "C0000",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 5,
|
||||
Department = testDepartment,
|
||||
StartDate = yesterday,
|
||||
Role = Role.BusinessLineManager
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_departmentRepository)
|
||||
.Setup(mock => mock.FindDepartmentsByBusinessLineAsync(BusinessLine.Operations)).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
testDepartment
|
||||
});
|
||||
|
||||
var result = await _service.ValidateIsBusinessLineManager(user, testDepartment.Id.Value);
|
||||
Assert.True(result);
|
||||
result = await _service.ValidateIsBusinessLineManager(user, 99);
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
+677
@@ -0,0 +1,677 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Transaction;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.AutoDecision;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
|
||||
namespace Application.UnitTests.Services.AutoDecision
|
||||
{
|
||||
public class ActivityDecisionServiceTest
|
||||
{
|
||||
private ActivityDecisionService _activityDecisionService;
|
||||
private IActivityService _activityService;
|
||||
private IActivityDetailService _activityDetailService;
|
||||
private DebtProtectionAccessoryService _debtProtectionAccessoryService;
|
||||
private IDnaService _dnaService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var strategies = new List<IDecisionStrategy>()
|
||||
{
|
||||
new ManualDecisionStrategy(),
|
||||
new ReferralDecisionStrategy(),
|
||||
new NewCheckingDecisionStrategy(),
|
||||
new CardSaleDecisionStrategy(),
|
||||
new MortgageSaleDecisionStrategy(),
|
||||
new VehicleDecisionStrategy(),
|
||||
new DebtProtectionEligibleLoanDecisionStrategy()
|
||||
};
|
||||
_activityService = Mock.Of<IActivityService>();
|
||||
_activityDetailService = Mock.Of<IActivityDetailService>();
|
||||
_debtProtectionAccessoryService = new DebtProtectionAccessoryService(_activityService, _activityDetailService);
|
||||
_dnaService = Mock.Of<IDnaService>();
|
||||
_activityDecisionService = new ActivityDecisionService(strategies, _activityService, _activityDetailService, _debtProtectionAccessoryService, _dnaService);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Decision_Basic_Accept()
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Other,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = "ACT"
|
||||
}
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreNotEqual(activity.State, decision.State);
|
||||
Assert.AreEqual(ActivityState.Accepted, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Decision_ByState_Basic()
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Other,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = "ACT"
|
||||
},
|
||||
State = ActivityState.Created
|
||||
};
|
||||
var pagedResult = new PagedResult<Activity>()
|
||||
{
|
||||
Total = 1,
|
||||
Items = new List<Activity>() { activity }
|
||||
};
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.IsAny<ActivityFilter>()))
|
||||
.ReturnsAsync(pagedResult);
|
||||
Mock.Get(_activityService).Setup(x => x.ApplyStateChange(It.IsAny<ActivityStateChange>(),true))
|
||||
.Verifiable();
|
||||
|
||||
var changes = await _activityDecisionService.DecisionActivityByState(ActivityState.Created);
|
||||
|
||||
Assert.NotNull(changes);
|
||||
Assert.IsNotEmpty(changes);
|
||||
var decision = changes.FirstOrDefault();
|
||||
Assert.NotNull(decision);
|
||||
Assert.AreNotEqual(activity.State, decision.State);
|
||||
Assert.AreEqual(ActivityState.Accepted, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
|
||||
Mock.Get(_activityService).Verify(x => x.ListByFilterAsync(It.IsAny<ActivityFilter>()), Times.Once);
|
||||
Mock.Get(_activityService).Verify(x => x.ApplyStateChange(It.IsAny<ActivityStateChange>(),true), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Decision_ManualReview_Basic()
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Other,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = "ACT"
|
||||
},
|
||||
State = ActivityState.Created
|
||||
};
|
||||
var pagedResult = new PagedResult<Activity>()
|
||||
{
|
||||
Total = 1,
|
||||
Items = new List<Activity>() { activity }
|
||||
};
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.IsAny<ActivityFilter>()))
|
||||
.ReturnsAsync(pagedResult).Verifiable();
|
||||
Mock.Get(_activityDetailService)
|
||||
.Setup(x => x.TryUpdateActivityAccountDetails(It.IsAny<List<Activity>>()))
|
||||
.ReturnsAsync(new List<Activity>() { activity }).Verifiable();
|
||||
Mock.Get(_activityService).Setup(x => x.ApplyStateChange(It.IsAny<ActivityStateChange>(),true))
|
||||
.Verifiable();
|
||||
|
||||
var changes = await _activityDecisionService.UpdateAndDecideManualReviewActivities();
|
||||
|
||||
Assert.NotNull(changes);
|
||||
Assert.IsNotEmpty(changes);
|
||||
var decision = changes.FirstOrDefault();
|
||||
Assert.NotNull(decision);
|
||||
Assert.AreNotEqual(activity.State, decision.State);
|
||||
Assert.AreEqual(ActivityState.Accepted, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
|
||||
Mock.Get(_activityService).Verify();
|
||||
Mock.Get(_activityDetailService).Verify();
|
||||
|
||||
Mock.Get(_activityService).Verify(x => x.ListByFilterAsync(It.IsAny<ActivityFilter>()), Times.Once);
|
||||
Mock.Get(_activityService).Verify(x => x.ApplyStateChange(It.IsAny<ActivityStateChange>(),true), Times.Once);
|
||||
}
|
||||
|
||||
[TestCase(Product.LIC, ActivityType.Sale)]
|
||||
[TestCase(Product.DirectDeposit, ActivityType.Sale)]
|
||||
[TestCase(Product.CreditCardBalanceTransfer, ActivityType.Sale)]
|
||||
public async Task Decision_Basic_NoDecision(Product product, ActivityType type)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = type,
|
||||
Product = product,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreNotEqual(activity.State, decision.State);
|
||||
Assert.AreEqual(ActivityState.ManualReview, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[TestCase("APPR", ActivityState.ManualReview)]
|
||||
[TestCase("ACT", ActivityState.Accepted)]
|
||||
[TestCase("CLS", ActivityState.Rejected)]
|
||||
[TestCase("YeeHaw", ActivityState.ManualReview)]
|
||||
[TestCase(null, ActivityState.Rejected)]
|
||||
public async Task Decision_Mortgage(string status, ActivityState state)
|
||||
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = status
|
||||
},
|
||||
Product = Product.Mortgage,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreEqual(state, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[TestCase(Product.ATMCard, ActivityState.PendingReferral, "60")]
|
||||
[TestCase(Product.CheckCard, ActivityState.PendingReferral, "60")]
|
||||
[TestCase(Product.NewChecking, ActivityState.PendingReferral, "60")]
|
||||
[TestCase(Product.Mortgage, ActivityState.PendingReferral, "60")]
|
||||
[TestCase(Product.FirstMortgageReferral, ActivityState.PendingReferral, "120")]
|
||||
[TestCase(Product.DirectDeposit, ActivityState.PendingReferral, "60")]
|
||||
[TestCase(Product.CreditCardBalanceTransfer, ActivityState.PendingReferral, "60")]
|
||||
[TestCase(Product.LIC, ActivityState.ManualReview, "Not In Final Station")]
|
||||
public async Task Decision_Referrals(Product product, ActivityState expectedState, string expectedExpirationDays)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Referral,
|
||||
Product = product,
|
||||
Accepted = DateTime.Today,
|
||||
Detail = new ActivityDetail()
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreEqual(expectedState, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
Assert.IsTrue(decision.Note.Contains(expectedExpirationDays));
|
||||
}
|
||||
|
||||
[TestCase(null, ActivityState.ManualReview)]
|
||||
[TestCase("NotRealStation", ActivityState.ManualReview)]
|
||||
[TestCase("LIC Referral-Qualified", ActivityState.Accepted)]
|
||||
[TestCase("LIC Referral- Not Qualified", ActivityState.Rejected)]
|
||||
public async Task Decision_LIC_Referrals(String stationName, ActivityState expectedState)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Referral,
|
||||
Product = Product.LIC,
|
||||
Accepted = DateTime.Today,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
StationName = stationName
|
||||
}
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreEqual(expectedState, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[TestCase(Product.GAPInsurance)]
|
||||
[TestCase(Product.MechanicalBreakdownProtection)]
|
||||
[TestCase(Product.DebtProtectionEligibleLoan)]
|
||||
[TestCase(Product.Vehicle)]
|
||||
[TestCase(Product.CreditCard)]
|
||||
public void Decision_Referrals_Throws(Product product)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Referral,
|
||||
Product = product,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
Assert.ThrowsAsync<NoAvailableDecisionStrategy>(async () => await _activityDecisionService.TryDecisionActivity(activity));
|
||||
}
|
||||
|
||||
|
||||
[TestCase(Product.ATMCard, "ACT", ActivityState.Accepted)]
|
||||
[TestCase(Product.CheckCard, "ACT", ActivityState.Accepted)]
|
||||
[TestCase(Product.ATMCard, "APPR", ActivityState.Accepted)]
|
||||
[TestCase(Product.CheckCard, "APPR", ActivityState.Accepted)]
|
||||
[TestCase(Product.ATMCard, "ORIG", ActivityState.Accepted)]
|
||||
[TestCase(Product.CheckCard, "ORIG", ActivityState.Accepted)]
|
||||
[TestCase(Product.ATMCard, "CLS", ActivityState.Accepted)]
|
||||
[TestCase(Product.CheckCard, "CLS", ActivityState.Accepted)]
|
||||
public async Task Decision_Cards(Product product, string status, ActivityState state)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Other,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = status
|
||||
},
|
||||
Product = product,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreEqual(state, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[TestCase("ACT", ActivityState.Accepted)]
|
||||
[TestCase("APPR", ActivityState.ManualReview)]
|
||||
[TestCase("ORIG", ActivityState.ManualReview)]
|
||||
[TestCase("CLS", ActivityState.Rejected)]
|
||||
[TestCase(null, ActivityState.Rejected)]
|
||||
public async Task Decision_NewChecking(string status, ActivityState state)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = status
|
||||
},
|
||||
Product = Product.NewChecking,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreEqual(state, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[TestCase("ACT", ActivityState.Accepted)]
|
||||
[TestCase("APPR", ActivityState.ManualReview)]
|
||||
[TestCase("ORIG", ActivityState.ManualReview)]
|
||||
[TestCase("CLS", ActivityState.Rejected)]
|
||||
[TestCase(null, ActivityState.Rejected)]
|
||||
public async Task Decision_NewDigitalBankingChecking(string status, ActivityState state)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 43,
|
||||
EmployeeId = "DigitalBankingAppUserEmployeeId",
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = status
|
||||
},
|
||||
Product = Product.NewChecking,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreEqual(state, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[TestCase("ACT", ActivityState.Accepted)]
|
||||
[TestCase("APPR", ActivityState.ManualReview)]
|
||||
[TestCase("CLS", ActivityState.Rejected)]
|
||||
[TestCase("ORIG", ActivityState.ManualReview)]
|
||||
[TestCase(null, ActivityState.Rejected)]
|
||||
public async Task Decision_Vehicle(string status, ActivityState state)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = status
|
||||
},
|
||||
Product = Product.Vehicle,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreEqual(state, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[TestCase("ACT", ActivityState.Accepted)]
|
||||
[TestCase("APPR", ActivityState.ManualReview)]
|
||||
[TestCase("CLS", ActivityState.Rejected)]
|
||||
[TestCase("ORIG", ActivityState.ManualReview)]
|
||||
[TestCase(null, ActivityState.Rejected)]
|
||||
public async Task Decision_DPEligibleLoan(string status, ActivityState state)
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountStatus = status
|
||||
},
|
||||
Product = Product.DebtProtectionEligibleLoan,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
var decision = await _activityDecisionService.TryDecisionActivity(activity);
|
||||
Assert.NotNull(activity);
|
||||
Assert.AreEqual(state, decision.State);
|
||||
Assert.AreEqual(activity.Id, decision.ActivityId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateAndDecideDirectDepositPendingReferralActivities_OK()
|
||||
{
|
||||
var activity = new Activity
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Referral,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345"
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.DebtProtectionEligibleLoan,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
|
||||
var pagedResult = new PagedResult<Activity>
|
||||
{
|
||||
Items = new[]
|
||||
{
|
||||
activity
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.Is<ActivityFilter>(x =>
|
||||
x.Limit.Equals(1000) && x.State.Contains(ActivityState.PendingReferral) && x.Product.Contains(Product.DirectDeposit))))
|
||||
.ReturnsAsync(pagedResult).Verifiable();
|
||||
|
||||
Mock.Get(_dnaService).Setup(x => x.GetTransactionHistory(It.Is<string>(x => x.Equals("12345")),
|
||||
It.Is<DateTime>(x => x.Equals(DateTime.Parse("2021/11/23 10:00:00"))), It.IsAny<DateTime>(), It.Is<List<string>>(x => x.Contains("XDEP"))))
|
||||
.ReturnsAsync(new List<TransactionHistory>
|
||||
{
|
||||
new TransactionHistory
|
||||
{
|
||||
Id = "1"
|
||||
}
|
||||
}).Verifiable();
|
||||
|
||||
var decision = await _activityDecisionService.UpdateAndDecideDirectDepositPendingReferralActivities();
|
||||
|
||||
Mock.Get(_activityService).Verify();
|
||||
Mock.Get(_dnaService).Verify();
|
||||
Assert.NotNull(decision);
|
||||
var firstDecision = decision.First();
|
||||
Assert.AreEqual(ActivityState.Accepted, firstDecision.State);
|
||||
Assert.AreEqual(123, firstDecision.ActivityId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateAndDecideDirectDepositPendingReferralActivities_NullReturned_RejectActivity()
|
||||
{
|
||||
var activity = new Activity
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Referral,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345"
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.DebtProtectionEligibleLoan,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
|
||||
var pagedResult = new PagedResult<Activity>
|
||||
{
|
||||
Items = new[]
|
||||
{
|
||||
activity
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.Is<ActivityFilter>(x =>
|
||||
x.Limit.Equals(1000) && x.State.Contains(ActivityState.PendingReferral) && x.Product.Contains(Product.DirectDeposit))))
|
||||
.ReturnsAsync(pagedResult).Verifiable();
|
||||
|
||||
Mock.Get(_dnaService).Setup(x => x.GetTransactionHistory(It.Is<string>(x => x.Equals("12345")),
|
||||
It.Is<DateTime>(x => x.Equals(DateTime.Parse("2021/11/23 10:00:00"))), It.IsAny<DateTime>(), It.Is<List<string>>(x => x.Contains("XDEP"))))
|
||||
.ReturnsAsync((List<TransactionHistory>)null).Verifiable();
|
||||
|
||||
var decision = await _activityDecisionService.UpdateAndDecideDirectDepositPendingReferralActivities();
|
||||
|
||||
Mock.Get(_activityService).Verify();
|
||||
Mock.Get(_dnaService).Verify();
|
||||
Assert.NotNull(decision);
|
||||
var firstDecision = decision.First();
|
||||
Assert.AreEqual(ActivityState.Rejected, firstDecision.State);
|
||||
Assert.AreEqual(123, firstDecision.ActivityId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateAndDecideDirectDepositPendingReferralActivities_None_NoActivitiesReturned()
|
||||
{
|
||||
var pagedResult = new PagedResult<Activity>();
|
||||
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.Is<ActivityFilter>(x =>
|
||||
x.Limit.Equals(1000) && x.State.Contains(ActivityState.PendingReferral) && x.Product.Contains(Product.DirectDeposit))))
|
||||
.ReturnsAsync(pagedResult).Verifiable();
|
||||
|
||||
var decision = await _activityDecisionService.UpdateAndDecideDirectDepositPendingReferralActivities();
|
||||
|
||||
Mock.Get(_activityService).Verify();
|
||||
Mock.Get(_dnaService).Verify(x => x.GetTransactionHistory(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<List<string>>()),
|
||||
Times.Never);
|
||||
Assert.IsEmpty(decision);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateAndDecideDirectDepositPendingReferralActivities_Empty_NoActivitiesReturned()
|
||||
{
|
||||
var pagedResult = new PagedResult<Activity>
|
||||
{
|
||||
Items = new Activity[] { }
|
||||
};
|
||||
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.Is<ActivityFilter>(x =>
|
||||
x.Limit.Equals(1000) && x.State.Contains(ActivityState.PendingReferral) && x.Product.Contains(Product.DirectDeposit))))
|
||||
.ReturnsAsync(pagedResult).Verifiable();
|
||||
|
||||
var decision = await _activityDecisionService.UpdateAndDecideDirectDepositPendingReferralActivities();
|
||||
|
||||
Mock.Get(_activityService).Verify();
|
||||
Mock.Get(_dnaService).Verify(x => x.GetTransactionHistory(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<List<string>>()),
|
||||
Times.Never);
|
||||
Assert.IsEmpty(decision);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateAndDecideDpEligibleLoanActivities_NoPagedResults_Ok()
|
||||
{
|
||||
var activity = new Activity
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
MatchingDpAccessoryActivityId = 0,
|
||||
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
DebtProtectionAddDate = DateTime.UtcNow,
|
||||
IsDebtProtectionEligible = true,
|
||||
IsGapInsuranceEligible = true
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.Vehicle,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
|
||||
var pagedResult = new PagedResult<Activity>
|
||||
{
|
||||
Items = null,
|
||||
Total = 0
|
||||
};
|
||||
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.Is<ActivityFilter>(x =>
|
||||
x.Limit.Equals(1000) && x.State.Contains(ActivityState.Accepted) && x.Product.Contains(Product.Vehicle))))
|
||||
.ReturnsAsync(pagedResult).Verifiable();
|
||||
|
||||
Mock.Get(_activityDetailService).Setup(x => x.TryUpdateActivityAccountDetails(It.IsAny<List<Activity>>()))
|
||||
.ReturnsAsync(new List<Activity>() { activity }).Verifiable();
|
||||
|
||||
Mock.Get(_activityDetailService).Setup(x => x.TryUpdateDpEligibleLoanDetail(It.IsAny<List<Activity>>()))
|
||||
.ReturnsAsync(new List<Activity>() { activity }).Verifiable();
|
||||
|
||||
var decision = await _activityDecisionService.UpdateAndDecideDpEligibleLoanActivities();
|
||||
|
||||
Mock.Get(_activityService).Verify();
|
||||
Mock.Get(_dnaService)
|
||||
.Verify(x => x.GetTransactionHistory(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<List<string>>()),
|
||||
Times.Never);
|
||||
Assert.IsEmpty(decision);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateAndDecideDpEligibleLoanActivities_GapInsuranceWasEligible_DebtProtectionAdded()
|
||||
{
|
||||
var activity = new Activity
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
MatchingDpAccessoryActivityId = 0,
|
||||
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
DebtProtectionAddDate = DateTime.UtcNow,
|
||||
IsDebtProtectionEligible = true,
|
||||
IsGapInsuranceEligible = true
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.Vehicle,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
|
||||
var pagedResult = new PagedResult<Activity>
|
||||
{
|
||||
Items = new[]
|
||||
{
|
||||
activity
|
||||
},
|
||||
Total = 1
|
||||
};
|
||||
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.Is<ActivityFilter>(x =>
|
||||
x.Limit.Equals(1000) && x.State.Contains(ActivityState.Accepted) && x.Product.Contains(Product.Vehicle))))
|
||||
.ReturnsAsync(pagedResult).Verifiable();
|
||||
|
||||
Mock.Get(_activityDetailService).Setup(x => x.TryUpdateActivityAccountDetails(It.IsAny<List<Activity>>()))
|
||||
.ReturnsAsync(new List<Activity>() { activity }).Verifiable();
|
||||
|
||||
Mock.Get(_activityDetailService).Setup(x => x.TryUpdateDpEligibleLoanDetail(It.IsAny<List<Activity>>()))
|
||||
.ReturnsAsync(new List<Activity>() { activity }).Verifiable();
|
||||
|
||||
var decision = await _activityDecisionService.UpdateAndDecideDpEligibleLoanActivities();
|
||||
|
||||
Mock.Get(_activityService).Verify();
|
||||
Mock.Get(_dnaService)
|
||||
.Verify(x => x.GetTransactionHistory(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<List<string>>()),
|
||||
Times.Never);
|
||||
Assert.NotNull(decision);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateAndDecideDpEligibleLoanActivities_GapInsuranceWasNotEligible_DebtProtectionAdded()
|
||||
{
|
||||
var activity = new Activity
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
MatchingDpAccessoryActivityId = 0,
|
||||
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
DebtProtectionAddDate = DateTime.UtcNow,
|
||||
IsDebtProtectionEligible = true,
|
||||
IsGapInsuranceEligible = false
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.Vehicle,
|
||||
Accepted = DateTime.Today
|
||||
};
|
||||
|
||||
var pagedResult = new PagedResult<Activity>
|
||||
{
|
||||
Items = new[]
|
||||
{
|
||||
activity
|
||||
},
|
||||
Total = 1
|
||||
};
|
||||
|
||||
Mock.Get(_activityService).Setup(x => x.ListByFilterAsync(It.Is<ActivityFilter>(x =>
|
||||
x.Limit.Equals(1000) && x.State.Contains(ActivityState.Accepted) && x.Product.Contains(Product.Vehicle))))
|
||||
.ReturnsAsync(pagedResult).Verifiable();
|
||||
|
||||
Mock.Get(_activityDetailService).Setup(x => x.TryUpdateActivityAccountDetails(It.IsAny<List<Activity>>()))
|
||||
.ReturnsAsync(new List<Activity>() { activity }).Verifiable();
|
||||
|
||||
Mock.Get(_activityDetailService).Setup(x => x.TryUpdateDpEligibleLoanDetail(It.IsAny<List<Activity>>()))
|
||||
.ReturnsAsync(new List<Activity>() { activity }).Verifiable();
|
||||
|
||||
var decision = await _activityDecisionService.UpdateAndDecideDpEligibleLoanActivities();
|
||||
|
||||
Mock.Get(_activityService).Verify();
|
||||
Mock.Get(_dnaService).Verify(x => x.GetTransactionHistory(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<List<string>>()),
|
||||
Times.Never);
|
||||
Assert.NotNull(decision);
|
||||
}
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.AutoDecision;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services.AutoDecision
|
||||
{
|
||||
public class DebtProtectionAccessoryServiceTest
|
||||
{
|
||||
private ActivityDecisionService _activityDecisionService;
|
||||
private IActivityService _activityService;
|
||||
private IActivityDetailService _activityDetailService;
|
||||
private DebtProtectionAccessoryService _debtProtectionAccessoryService;
|
||||
private IDnaService _dnaService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var strategies = new List<IDecisionStrategy>()
|
||||
{
|
||||
new ManualDecisionStrategy(),
|
||||
new ReferralDecisionStrategy(),
|
||||
new NewCheckingDecisionStrategy(),
|
||||
new CardSaleDecisionStrategy(),
|
||||
new MortgageSaleDecisionStrategy(),
|
||||
new VehicleDecisionStrategy(),
|
||||
new DebtProtectionEligibleLoanDecisionStrategy()
|
||||
};
|
||||
_activityService = Mock.Of<IActivityService>();
|
||||
_activityDetailService = Mock.Of<IActivityDetailService>();
|
||||
_debtProtectionAccessoryService = new DebtProtectionAccessoryService(_activityService, _activityDetailService);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessDpAccessoryUpdates_Product_Vehicle_DP_Eligible_GapEligible_Ok()
|
||||
{
|
||||
var saleactivity = new List<Activity>()
|
||||
{
|
||||
new Activity ()
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
MatchingDpAccessoryActivityId = 0,
|
||||
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
DebtProtectionAddDate = DateTime.UtcNow,
|
||||
IsDebtProtectionEligible = true,
|
||||
IsGapInsuranceEligible = true
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.Vehicle,
|
||||
Accepted = DateTime.Today
|
||||
}
|
||||
};
|
||||
|
||||
var updatedActivities = await _debtProtectionAccessoryService.ProcessDpAccessoryUpdates(saleactivity);
|
||||
Mock.Get(_activityService).Verify();
|
||||
Assert.NotNull(updatedActivities);
|
||||
Assert.AreEqual(updatedActivities.First().Detail.IsDebtProtectionEligible, true);
|
||||
Assert.AreEqual(updatedActivities.First().Detail.IsGapInsuranceEligible, true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessDpAccessoryUpdates_Product_Mortgage_DP_NotEligible_Gap_NotEligible_Ok()
|
||||
{
|
||||
var saleactivity = new List<Activity>()
|
||||
{
|
||||
new Activity ()
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
MatchingDpAccessoryActivityId = 0,
|
||||
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
DebtProtectionAddDate = DateTime.UtcNow,
|
||||
IsDebtProtectionEligible = false,
|
||||
IsGapInsuranceEligible = false
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.Vehicle,
|
||||
Accepted = DateTime.Today
|
||||
}
|
||||
};
|
||||
|
||||
var updatedActivities = await _debtProtectionAccessoryService.ProcessDpAccessoryUpdates(saleactivity);
|
||||
Mock.Get(_activityService).Verify();
|
||||
Assert.AreEqual(0, updatedActivities.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessDpAccessoryUpdates_Product_DebtProtection_DP_Eligible_Gap_NotEligible_Ok()
|
||||
{
|
||||
var saleactivity = new List<Activity>()
|
||||
{
|
||||
new Activity ()
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
MatchingDpAccessoryActivityId = 0,
|
||||
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
DebtProtectionRemoveDate = DateTime.UtcNow,
|
||||
DebtProtectionAddDate = DateTime.UtcNow.AddMonths(-1),
|
||||
IsDebtProtectionEligible = true,
|
||||
IsGapInsuranceEligible = false
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.DebtProtectionEligibleLoan,
|
||||
Accepted = DateTime.Today
|
||||
}
|
||||
};
|
||||
|
||||
var updatedActivities = await _debtProtectionAccessoryService.ProcessDpAccessoryUpdates(saleactivity);
|
||||
Mock.Get(_activityService).Verify();
|
||||
Assert.NotNull(updatedActivities);
|
||||
Assert.AreEqual(updatedActivities.First().Detail.IsDebtProtectionEligible, true);
|
||||
Assert.AreEqual(updatedActivities.First().Detail.IsGapInsuranceEligible, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessDpAccessoryUpdates_Product_Vehicle_NoMatchingAccessoryNoAddDate_Ok()
|
||||
{
|
||||
var saleactivity = new List<Activity>()
|
||||
{
|
||||
new Activity ()
|
||||
{
|
||||
Id = 123,
|
||||
DepartmentId = 56,
|
||||
EmployeeId = "11771",
|
||||
Type = ActivityType.Sale,
|
||||
MatchingDpAccessoryActivityId = 0,
|
||||
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
DebtProtectionAddDate = null,
|
||||
IsDebtProtectionEligible = true,
|
||||
IsGapInsuranceEligible = true
|
||||
},
|
||||
Created = DateTime.Parse("2021/11/23 10:00:00"),
|
||||
Product = Product.Vehicle,
|
||||
Accepted = DateTime.Today
|
||||
}
|
||||
};
|
||||
|
||||
var updatedActivities = await _debtProtectionAccessoryService.ProcessDpAccessoryUpdates(saleactivity);
|
||||
Mock.Get(_activityService).Verify();
|
||||
Assert.NotNull(updatedActivities);
|
||||
Assert.AreEqual(updatedActivities.Count(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class CommissionServiceTest
|
||||
{
|
||||
private CommissionService _service;
|
||||
private Mock<ICommissionRepository> _mockCommissionRepository;
|
||||
private Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCommissionRepository = new Mock<ICommissionRepository>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_service = new CommissionService(_mockCommissionRepository.Object, _mockUnitOfWork.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetCommissionsAsync_ReturnsCommissionsFromRepo()
|
||||
{
|
||||
var commissions = new List<Commission>
|
||||
{
|
||||
new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.ATMCard,
|
||||
RatePerProduct = 5,
|
||||
Role = Role.Teller
|
||||
},
|
||||
new Commission
|
||||
{
|
||||
Id = 2,
|
||||
Product = Product.CheckCard,
|
||||
RatePerProduct = 10,
|
||||
Role = Role.ABM
|
||||
}
|
||||
}.AsReadOnly();
|
||||
_mockCommissionRepository.Setup(repo => repo.GetCommissionsAsync()).ReturnsAsync(commissions);
|
||||
|
||||
var result = await _service.GetCommissionsAsync();
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(2, result.Count);
|
||||
Assert.AreEqual(commissions[0].Id, result.ElementAt(0).Id);
|
||||
Assert.AreEqual(commissions[0].Product, result.ElementAt(0).Product);
|
||||
Assert.AreEqual(commissions[0].RatePerProduct, result.ElementAt(0).RatePerProduct);
|
||||
Assert.AreEqual(commissions[0].Role, result.ElementAt(0).Role);
|
||||
Assert.AreEqual(commissions[1].Id, result.ElementAt(1).Id);
|
||||
Assert.AreEqual(commissions[1].Product, result.ElementAt(1).Product);
|
||||
Assert.AreEqual(commissions[1].RatePerProduct, result.ElementAt(1).RatePerProduct);
|
||||
Assert.AreEqual(commissions[1].Role, result.ElementAt(1).Role);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveCommissionsAsync_NewCommission_CallRepoWithCommissionToSave()
|
||||
{
|
||||
var actualUpdates = new List<Commission>();
|
||||
var newCommission = new Commission
|
||||
{
|
||||
Id = 0,
|
||||
Product = Product.ATMCard,
|
||||
RatePerProduct = 5,
|
||||
Role = Role.Teller
|
||||
};
|
||||
|
||||
var commissionsToUpdate = new List<Commission> { newCommission };
|
||||
|
||||
_mockCommissionRepository.Setup(repo => repo.FindExistingCommission(newCommission.Role, newCommission.Product))
|
||||
.ReturnsAsync((Commission)null);
|
||||
_mockCommissionRepository.Setup(repo => repo.SaveCommission(newCommission));
|
||||
|
||||
await _service.SaveCommissionsAsync(commissionsToUpdate);
|
||||
|
||||
_mockCommissionRepository.Verify(repo => repo.FindExistingCommission(newCommission.Role, newCommission.Product), Times.Once);
|
||||
_mockCommissionRepository.Verify(repo => repo.SaveCommission(newCommission), Times.Once);
|
||||
_mockUnitOfWork.Verify(context => context.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SaveCommissionsAsync_NewCommissionMatchInRepo_ThrowsCommissionExistsException()
|
||||
{
|
||||
var newCommission = new Commission
|
||||
{
|
||||
Id = 0,
|
||||
Product = Product.CheckCard,
|
||||
RatePerProduct = 10,
|
||||
Role = Role.ABM
|
||||
};
|
||||
var commissions = new List<Commission> { newCommission };
|
||||
|
||||
var existingInRepo = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.CheckCard,
|
||||
RatePerProduct = 15,
|
||||
Role = Role.ABM
|
||||
};
|
||||
|
||||
_mockCommissionRepository.Setup(repo => repo.FindExistingCommission(newCommission.Role, newCommission.Product))
|
||||
.ReturnsAsync(existingInRepo);
|
||||
|
||||
var ex = Assert.ThrowsAsync<CommissionExistsException>(async () =>
|
||||
{
|
||||
await _service.SaveCommissionsAsync(commissions);
|
||||
});
|
||||
|
||||
Assert.AreEqual("Commission already exists for Role=ABM, Product=CheckCard", ex.Message);
|
||||
_mockCommissionRepository.Verify(repo => repo.FindExistingCommission(newCommission.Role, newCommission.Product), Times.Once);
|
||||
_mockCommissionRepository.Verify(repo => repo.SaveCommission(It.IsAny<Commission>()), Times.Never);
|
||||
_mockUnitOfWork.Verify(context => context.CompleteAsync(), Times.Never);
|
||||
_mockCommissionRepository.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveCommissionsAsync_UpdateCommission_SetsRate()
|
||||
{
|
||||
var updates = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.CheckCard,
|
||||
RatePerProduct = 20,
|
||||
Role = Role.ABM
|
||||
};
|
||||
var commissions = new List<Commission> { updates };
|
||||
|
||||
var commissionToUpdate = new Commission
|
||||
{
|
||||
Id = 1,
|
||||
Product = Product.CheckCard,
|
||||
RatePerProduct = 15,
|
||||
Role = Role.ABM
|
||||
};
|
||||
Assert.AreEqual(15, commissionToUpdate.RatePerProduct);
|
||||
|
||||
_mockCommissionRepository.Setup(repo => repo.FindExistingCommission(updates.Id))
|
||||
.ReturnsAsync(commissionToUpdate);
|
||||
|
||||
await _service.SaveCommissionsAsync(commissions);
|
||||
|
||||
Assert.AreEqual(20, commissionToUpdate.RatePerProduct);
|
||||
_mockCommissionRepository.Verify(repo => repo.FindExistingCommission(updates.Id), Times.Once);
|
||||
_mockUnitOfWork.Verify(context => context.CompleteAsync(), Times.Once);
|
||||
_mockCommissionRepository.VerifyNoOtherCalls();
|
||||
}
|
||||
}
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Rules;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class DashboardServiceTest
|
||||
{
|
||||
private DashboardService _dashboardService;
|
||||
private IActivityRepository _mockActivityRepository;
|
||||
private IGoalRepository _mockGoalRepository;
|
||||
private IDepartmentService _mockDepartmentService;
|
||||
private IBusinessRuleService _mockBusinessRuleService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDepartmentService = Mock.Of<IDepartmentService>();
|
||||
_mockActivityRepository = Mock.Of<IActivityRepository>();
|
||||
_mockGoalRepository = Mock.Of<IGoalRepository>();
|
||||
_mockBusinessRuleService = Mock.Of<IBusinessRuleService>();
|
||||
_dashboardService = new DashboardService(_mockDepartmentService, _mockActivityRepository,
|
||||
_mockGoalRepository, _mockBusinessRuleService);
|
||||
}
|
||||
|
||||
// We need a test, given some activity, returns it differently for personal or department progress.
|
||||
// So we'll need some activities:
|
||||
// 1. A New Checking Referral
|
||||
// 2. A New Checking Sale
|
||||
// 3. An LIC Referral
|
||||
// 4. An CreditCard Sale
|
||||
// 5. A First Mortgage Referral and Sale
|
||||
// This should credit 2 to the person and 1 to the department, unless the department is Member Services.
|
||||
[TestCase(55, 1,2)]
|
||||
[TestCase(56 /* Member Services */, 2,2)]
|
||||
public async Task Special_Rules_Sample_NonMemberServices(int testDepartmentId, int expectedDepartmentTotal, int expectedPersonalTotal)
|
||||
{
|
||||
var range = new MonthRange(2021, 1, 2021, 2);
|
||||
var user = new AppUser()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test Worker"
|
||||
};
|
||||
var departments = new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
Id = testDepartmentId,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Developers",
|
||||
BusinessLineCode = BusinessLine.MemberServices.Code,
|
||||
RegionCode = Region.North.Code
|
||||
}
|
||||
};
|
||||
var userDepartments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Department = departments.First(x => x.Id == testDepartmentId),
|
||||
Role = Role.BM,
|
||||
Employee = user,
|
||||
StartDate = range.StartTime,
|
||||
EndDate = range.EndTime
|
||||
}
|
||||
};
|
||||
var goals = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
EndDate = range.EndTime,
|
||||
StartDate = range.StartTime,
|
||||
Value = 2,
|
||||
DepartmentId = testDepartmentId
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.NewChecking,
|
||||
EndDate = range.EndTime,
|
||||
StartDate = range.StartTime,
|
||||
Value = 2,
|
||||
DepartmentId = testDepartmentId,
|
||||
EmployeeId = "11771"
|
||||
}
|
||||
};
|
||||
var activities = new List<Activity>()
|
||||
{
|
||||
new Activity()
|
||||
{
|
||||
Id = 100,
|
||||
Product = Product.NewChecking,
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.Accepted,
|
||||
Accepted = range.StartTime,
|
||||
Created = range.StartTime,
|
||||
DepartmentId = testDepartmentId,
|
||||
EmployeeId = "11771",
|
||||
Detail = new ActivityDetail(),
|
||||
MatchingActivityId = 101
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 101,
|
||||
Product = Product.NewChecking,
|
||||
Type = ActivityType.Sale,
|
||||
State = ActivityState.Accepted,
|
||||
Accepted = range.StartTime,
|
||||
Created = range.StartTime,
|
||||
DepartmentId = testDepartmentId,
|
||||
EmployeeId = "11771",
|
||||
Detail = new ActivityDetail(),
|
||||
MatchingActivityId = 100
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 102,
|
||||
Product = Product.LIC,
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.Accepted,
|
||||
Accepted = range.StartTime,
|
||||
Created = range.StartTime,
|
||||
DepartmentId = testDepartmentId,
|
||||
EmployeeId = "11771",
|
||||
Detail = new ActivityDetail()
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 103,
|
||||
Product = Product.CreditCard,
|
||||
Type = ActivityType.Sale,
|
||||
State = ActivityState.Accepted,
|
||||
Accepted = range.StartTime,
|
||||
Created = range.StartTime,
|
||||
DepartmentId = testDepartmentId,
|
||||
EmployeeId = "11771",
|
||||
Detail = new ActivityDetail()
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 104,
|
||||
Product = Product.FirstMortgageReferral,
|
||||
Type = ActivityType.Sale,
|
||||
State = ActivityState.Accepted,
|
||||
Accepted = range.StartTime,
|
||||
Created = range.StartTime,
|
||||
DepartmentId = testDepartmentId,
|
||||
EmployeeId = "11771",
|
||||
Detail = new ActivityDetail()
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 105,
|
||||
Product = Product.FirstMortgageReferral,
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
Accepted = range.StartTime,
|
||||
Created = range.StartTime,
|
||||
DepartmentId = testDepartmentId,
|
||||
EmployeeId = "11771",
|
||||
Detail = new ActivityDetail()
|
||||
}
|
||||
};
|
||||
|
||||
var departmentRules = new List<IPayoutRule>()
|
||||
{
|
||||
new NewCheckingReferralRule(56) // this simulates looking up 200.
|
||||
};
|
||||
var personalRules = new List<IPayoutRule>()
|
||||
{
|
||||
};
|
||||
|
||||
Mock.Get(_mockDepartmentService).Setup(s => s.FindDepartmentAssignmentsForRange(testDepartmentId,range))
|
||||
.ReturnsAsync(userDepartments);
|
||||
Mock.Get(_mockActivityRepository).Setup(s => s.FindDepartmentActivityByMonthRange(testDepartmentId, range))
|
||||
.ReturnsAsync(activities);
|
||||
Mock.Get(_mockGoalRepository).Setup(s => s.FindDepartmentGoalsByMonthRange(testDepartmentId, range))
|
||||
.ReturnsAsync(goals.Where(x => x.EmployeeId == null).ToList());
|
||||
Mock.Get(_mockGoalRepository).Setup(s => s.FindPersonnelGoalsByMonthRange(testDepartmentId, It.IsAny<List<string>>(),range))
|
||||
.ReturnsAsync(goals.Where(x => x.EmployeeId != null).ToList());
|
||||
Mock.Get(_mockBusinessRuleService).Setup(x => x.GetRules(PayoutType.Department)).Returns(departmentRules);
|
||||
Mock.Get(_mockBusinessRuleService).Setup(x => x.GetRules(PayoutType.Personal)).Returns(personalRules);
|
||||
|
||||
var result = await _dashboardService.GetDepartmentProgressForMonthRangeAsync(testDepartmentId, range);
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(expectedDepartmentTotal, result.Progress.ProductActivity[Product.NewChecking]);
|
||||
Assert.AreEqual(1, result.Progress.ProductActivity[Product.CreditCard]);
|
||||
Assert.AreEqual(1, result.Progress.ProductActivity[Product.LIC]);
|
||||
Assert.AreEqual(1, result.Progress.ProductActivity[Product.FirstMortgageReferral]);
|
||||
Assert.AreEqual(expectedPersonalTotal, result.EmployeeProgress["11771"].ProductActivity[Product.NewChecking]);
|
||||
Assert.AreEqual(1, result.EmployeeProgress["11771"].ProductActivity[Product.CreditCard]);
|
||||
Assert.AreEqual(1, result.EmployeeProgress["11771"].ProductActivity[Product.LIC]);
|
||||
|
||||
Mock.Get(_mockDepartmentService).Verify(s => s.FindDepartmentAssignmentsForRange(testDepartmentId, range),
|
||||
Times.Once);
|
||||
Mock.Get(_mockActivityRepository).Verify(s => s.FindDepartmentActivityByMonthRange(testDepartmentId, range),
|
||||
Times.Once);
|
||||
Mock.Get(_mockGoalRepository).Verify(s => s.FindDepartmentGoalsByMonthRange(testDepartmentId, range),
|
||||
Times.Once);
|
||||
Mock.Get(_mockGoalRepository).Verify(s => s.FindPersonnelGoalsByMonthRange(testDepartmentId, It.IsAny<List<string>>(),range),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services;
|
||||
|
||||
public class DataCleaningServiceTest
|
||||
{
|
||||
[Test]
|
||||
public void BasicParsePhoneTest()
|
||||
{
|
||||
var result = DataCleaningService.CleanedPhoneNumber("+1( 123\\/-4567890)");
|
||||
Assert.AreEqual("1234567890", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasicParsePhoneTestTwo()
|
||||
{
|
||||
var result = DataCleaningService.CleanedPhoneNumber("+1( ^~`&$$*^^<>??:;|[]!##%*-123\\/-4567890)");
|
||||
Assert.AreEqual("1234567890", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasicParsePhoneTestThree()
|
||||
{
|
||||
var result = DataCleaningService.CleanedPhoneNumber("262-6064142");
|
||||
Assert.AreEqual("2626064142", result);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services;
|
||||
|
||||
public class DataParsingServiceTest
|
||||
{
|
||||
[Test]
|
||||
public void BasicParsePhoneTest()
|
||||
{
|
||||
var result = DataParsingService.MapActivityMetaData(new List<string>
|
||||
{
|
||||
"262-6064142"
|
||||
});
|
||||
Assert.AreEqual("2626064142", result.FirstOrDefault()?.MetaData);
|
||||
Assert.AreEqual(MetaDataType.Phone, result.FirstOrDefault()?.MetaDataType);
|
||||
}
|
||||
}
|
||||
+783
@@ -0,0 +1,783 @@
|
||||
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<IDayForceClientService>();
|
||||
_notificationService = Mock.Of<INotificationApiService>();
|
||||
_payoutService = Mock.Of<IPayoutService>();
|
||||
_settingsService = Mock.Of<ISettingsService>();
|
||||
_unitOfWork = Mock.Of<IUnitOfWork>();
|
||||
_userService = Mock.Of<IUserService>();
|
||||
_dayForceConfig = Mock.Of<DayForceConfiguration>();
|
||||
_dayForceConfig.DayForceActiveUserReport = "INCENTIVE_MANAGER_ACTIVE";
|
||||
_dayForceConfig.DayForceTerminatedUserReport = "INCENTIVE_MANAGER_TERMINATED";
|
||||
_dayForceConfig.DayForceManualReportRecipients = new List<string>() { "[email protected]" };
|
||||
|
||||
_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<Exception>(() => { _dayForceSyncService.SyncActiveDayForceUsers(new List<string>()).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<Exception>(() => { _dayForceSyncService.SyncTerminatedDayForceUsers(new List<string>()).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<Dictionary<string, string>>()
|
||||
});
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_notificationService)
|
||||
.Setup(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>())).Verifiable();
|
||||
|
||||
Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable();
|
||||
|
||||
await _dayForceSyncService.SyncActiveDayForceUsers(new List<string>());
|
||||
|
||||
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<ActiveEmployeeResult>()), Times.Never);
|
||||
Mock.Get(_notificationService)
|
||||
.Verify(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Sync_Active_Basic()
|
||||
{
|
||||
var row1 = new Dictionary<string, string>();
|
||||
var row2 = new Dictionary<string, string>();
|
||||
row1["EmploymentStatus_ShortName"] = "Active";
|
||||
row1["Employee_DisplayName"] = "Test One";
|
||||
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
||||
row1["IdLibrary_LoginName"] = "[email protected]";
|
||||
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"] = "[email protected]";
|
||||
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<Dictionary<string, string>>()
|
||||
{ row1, row2 }
|
||||
});
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_notificationService)
|
||||
.Setup(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()))
|
||||
.Verifiable();
|
||||
|
||||
Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable();
|
||||
|
||||
await _dayForceSyncService.SyncActiveDayForceUsers(new List<string>());
|
||||
|
||||
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<ActiveEmployeeResult>()), Times.Exactly(2));
|
||||
Mock.Get(_notificationService)
|
||||
.Verify(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()),
|
||||
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<Dictionary<string, string>>()
|
||||
});
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.FindManager(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_payoutService)
|
||||
.Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(
|
||||
new TerminatedEmployeeReceipt(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}, new PayoutEntry(), new PayoutEntry(), new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
})
|
||||
);
|
||||
|
||||
Mock.Get(_notificationService)
|
||||
.Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()))
|
||||
.Verifiable();
|
||||
|
||||
await _dayForceSyncService.SyncTerminatedDayForceUsers(new List<string>());
|
||||
|
||||
Mock.Get(_dayForceClientService)
|
||||
.Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport),
|
||||
Times.Once);
|
||||
|
||||
Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()), Times.Never);
|
||||
Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny<AppUser>()), Times.Never);
|
||||
Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()), Times.Never);
|
||||
Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Sync_Term_Basic()
|
||||
{
|
||||
var row1 = new Dictionary<string, string>();
|
||||
var row2 = new Dictionary<string, string>();
|
||||
row1["Employee_DisplayName"] = "Test One";
|
||||
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
||||
row1["IdLibrary_LoginName"] = "[email protected]";
|
||||
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"] = "[email protected]";
|
||||
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<Dictionary<string, string>>() { row1, row2 }
|
||||
});
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.FindManager(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_payoutService)
|
||||
.Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(
|
||||
new TerminatedEmployeeReceipt(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}, new PayoutEntry(), new PayoutEntry(), new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
})
|
||||
);
|
||||
|
||||
Mock.Get(_notificationService)
|
||||
.Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()))
|
||||
.Verifiable();
|
||||
|
||||
await _dayForceSyncService.SyncTerminatedDayForceUsers(new List<string>());
|
||||
|
||||
Mock.Get(_dayForceClientService)
|
||||
.Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport),
|
||||
Times.Once);
|
||||
|
||||
Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()), Times.Exactly(2));
|
||||
Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny<AppUser>()), Times.Exactly(2));
|
||||
Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()), Times.Exactly(2));
|
||||
Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DayForceSync_ManualReportRecipients_Ok()
|
||||
{
|
||||
//setup for Active Users Email
|
||||
var row3 = new Dictionary<string, string>();
|
||||
var row4 = new Dictionary<string, string>();
|
||||
|
||||
row3["EmploymentStatus_ShortName"] = "Active";
|
||||
row3["Employee_DisplayName"] = "Test One";
|
||||
row3["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
||||
row3["IdLibrary_LoginName"] = "[email protected]";
|
||||
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"] = "[email protected]";
|
||||
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<Dictionary<string, string>>() { row3, row4 }
|
||||
});
|
||||
|
||||
Mock.Get(_userService).Setup(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Role = Role.MISSING_ROLE
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_notificationService).Setup(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>())).Verifiable();
|
||||
|
||||
//Setup for Terminated Email
|
||||
Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable();
|
||||
|
||||
var row1 = new Dictionary<string, string>();
|
||||
var row2 = new Dictionary<string, string>();
|
||||
|
||||
row1["Employee_DisplayName"] = "Test One";
|
||||
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
||||
row1["IdLibrary_LoginName"] = "[email protected]";
|
||||
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"] = "[email protected]";
|
||||
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<Dictionary<string, string>>() { row1, row2 }
|
||||
});
|
||||
|
||||
Mock.Get(_userService).Setup(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_userService).Setup(s => s.FindManager(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_payoutService).Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(
|
||||
new TerminatedEmployeeReceipt(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}, new PayoutEntry(), new PayoutEntry(), new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
})
|
||||
);
|
||||
|
||||
Mock.Get(_notificationService).Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>())).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<ActiveEmployeeResult>()), Times.Exactly(2));
|
||||
Mock.Get(_notificationService).Verify(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()), Times.Once);
|
||||
|
||||
Mock.Equals(request.MissingRoleNotification, _dayForceConfig.DayForceManualReportRecipients);
|
||||
Assert.AreNotSame(request.MissingRoleNotification, "[email protected]");
|
||||
|
||||
//Terminated User Checks
|
||||
Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()), Times.Exactly(2));
|
||||
Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny<AppUser>()), Times.Exactly(2));
|
||||
Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()), Times.Exactly(2));
|
||||
Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once);
|
||||
Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DayForceSync_RequestReportRecipients_Ok()
|
||||
{
|
||||
//setup for Active Users Email
|
||||
var row3 = new Dictionary<string, string>();
|
||||
var row4 = new Dictionary<string, string>();
|
||||
|
||||
row3["EmploymentStatus_ShortName"] = "Active";
|
||||
row3["Employee_DisplayName"] = "Test One";
|
||||
row3["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
||||
row3["IdLibrary_LoginName"] = "[email protected]";
|
||||
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"] = "[email protected]";
|
||||
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<Dictionary<string, string>>() { row3, row4 }
|
||||
});
|
||||
|
||||
Mock.Get(_userService).Setup(s => s.SyncDayForceEmployee(It.IsAny<ActiveEmployeeResult>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Role = Role.MISSING_ROLE
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_notificationService).Setup(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>())).Verifiable();
|
||||
|
||||
//Setup for Terminated Email
|
||||
Mock.Get(_unitOfWork).Setup(s => s.CompleteAsync()).Verifiable();
|
||||
|
||||
var row1 = new Dictionary<string, string>();
|
||||
var row2 = new Dictionary<string, string>();
|
||||
|
||||
row1["Employee_DisplayName"] = "Test One";
|
||||
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
||||
row1["IdLibrary_LoginName"] = "[email protected]";
|
||||
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"] = "[email protected]";
|
||||
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<Dictionary<string, string>>() { row1, row2 }
|
||||
});
|
||||
|
||||
Mock.Get(_userService).Setup(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_userService).Setup(s => s.FindManager(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
Mock.Get(_payoutService).Setup(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(
|
||||
new TerminatedEmployeeReceipt(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
}, new PayoutEntry(), new PayoutEntry(), new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]"
|
||||
})
|
||||
);
|
||||
|
||||
Mock.Get(_notificationService).Setup(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>())).Verifiable();
|
||||
|
||||
var request = new DayforceProcessRequest();
|
||||
request.MissingRoleNotification = new List<string>() { "[email protected]" };
|
||||
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<ActiveEmployeeResult>()), Times.Exactly(2));
|
||||
Mock.Get(_notificationService).Verify(s => s.SendMissingRoleNotification(It.IsAny<IEnumerable<AppUser>>(), It.IsAny<List<string>>()), Times.Once);
|
||||
|
||||
Mock.Equals(request.MissingRoleNotification, "[email protected]");
|
||||
Assert.AreNotEqual(request.MissingRoleNotification, _dayForceConfig.DayForceManualReportRecipients);
|
||||
|
||||
//Terminated User Checks
|
||||
Mock.Get(_userService).Verify(s => s.TerminateDayForceEmployee(It.IsAny<TerminatedEmployeeResult>()), Times.Exactly(2));
|
||||
Mock.Get(_userService).Verify(s => s.FindManager(It.IsAny<AppUser>()), Times.Exactly(2));
|
||||
Mock.Get(_payoutService).Verify(s => s.CreateTerminatedEmployeePayouts(It.IsAny<AppUser>(), It.IsAny<AppUser>()), Times.Exactly(2));
|
||||
Mock.Get(_dayForceClientService).Verify(s => s.GetReportData(_dayForceConfig.DayForceTerminatedUserReport), Times.Once);
|
||||
Mock.Get(_notificationService).Verify(s => s.SendTerminatedEmployeeNotification(It.IsAny<IEnumerable<TerminatedEmployeeReceipt>>(), It.IsAny<List<string>>()), 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 = "[email protected]",
|
||||
OldEmployeeId = "12345",
|
||||
OldFullName = "TESTERSON, TEST",
|
||||
NewEmail = "[email protected]",
|
||||
NewEmployeeId = "12345",
|
||||
NewFullName = "TESTERSON, TEST"
|
||||
};
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
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 = "[email protected]",
|
||||
OldEmployeeId = "12345",
|
||||
OldFullName = "TESTERSON, TEST",
|
||||
NewEmail = "[email protected]",
|
||||
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 = "[email protected]",
|
||||
OldEmployeeId = "12345",
|
||||
OldFullName = "TESTERSON, TEST",
|
||||
NewEmail = "[email protected]",
|
||||
NewEmployeeId = "12345",
|
||||
NewFullName = "TESTERSON, TEST"
|
||||
};
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
Id = Guid.NewGuid(),
|
||||
EmployeeId = "12345",
|
||||
FullName = "TESTERSON, TEST"
|
||||
}
|
||||
);
|
||||
|
||||
var row1 = new Dictionary<string, string>();
|
||||
var row2 = new Dictionary<string, string>();
|
||||
row1["EmploymentStatus_ShortName"] = "Active";
|
||||
row1["Employee_DisplayName"] = "Test One";
|
||||
row1["EmployeeEmploymentStatus_EmployeeNumber"] = "C0001";
|
||||
row1["IdLibrary_LoginName"] = "[email protected]";
|
||||
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"] = "[email protected]";
|
||||
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<Dictionary<string, string>>()
|
||||
{ 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 = "[email protected]",
|
||||
OldEmployeeId = "12345",
|
||||
OldFullName = "TESTERSON, TEST",
|
||||
NewEmail = "[email protected]",
|
||||
NewEmployeeId = "12345",
|
||||
NewFullName = "TESTERSON, TEST"
|
||||
};
|
||||
|
||||
Mock.Get(_userService)
|
||||
.Setup(s => s.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
Id = Guid.NewGuid(),
|
||||
EmployeeId = "12345",
|
||||
FullName = "TESTERSON, TEST"
|
||||
}
|
||||
);
|
||||
|
||||
var row1 = new Dictionary<string, string>();
|
||||
var row2 = new Dictionary<string, string>();
|
||||
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"] = "[email protected]";
|
||||
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<Dictionary<string, string>>()
|
||||
{ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+360
@@ -0,0 +1,360 @@
|
||||
using System;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class DeadActivityServiceTest
|
||||
{
|
||||
private IDeadActivityService _service;
|
||||
private Mock<IDeadActivityRepository> _mockDeadActivityRepository;
|
||||
private Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDeadActivityRepository = new Mock<IDeadActivityRepository>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_service = new DeadActivityService(_mockDeadActivityRepository.Object, _mockUnitOfWork.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveDeadActivity_Ok()
|
||||
{
|
||||
var deadActivity = new DeadActivity("12345", SystemType.IncentiveLog, DeadActivityReason.Other,
|
||||
"Sad Incentive Manager Noises");
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>() { deadActivity });
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>() {});
|
||||
|
||||
|
||||
var result = await _service.SaveDeadActivity(deadActivity);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(deadActivity, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveDeadActivity_DidntSave_Ok()
|
||||
{
|
||||
var deadActivity = new DeadActivity("12345", SystemType.IncentiveLog, DeadActivityReason.Other,
|
||||
"Sad Incentive Manager Noises");
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>() {});
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>() {});
|
||||
|
||||
|
||||
var result = await _service.SaveDeadActivity(deadActivity);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveDeadActivity_FilteredOut_Ok()
|
||||
{
|
||||
var deadActivity = new DeadActivity("12345", SystemType.IncentiveLog, DeadActivityReason.Other,
|
||||
"Sad Incentive Manager Noises");
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>() {deadActivity});
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>() {deadActivity});
|
||||
|
||||
|
||||
var result = await _service.SaveDeadActivity(deadActivity);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveDeadActivityRange_OK()
|
||||
{
|
||||
var deadActivities = new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1", SystemType.Action, DeadActivityReason.Other, "Oh"),
|
||||
new DeadActivity("2", SystemType.Action, DeadActivityReason.Other, "No"),
|
||||
new DeadActivity("3", SystemType.Action, DeadActivityReason.Other, "Dead"),
|
||||
new DeadActivity("4", SystemType.Action, DeadActivityReason.Other, "Activity")
|
||||
};
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(deadActivities);
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>() {});
|
||||
|
||||
var result = await _service.SaveDeadActivityRange(deadActivities);
|
||||
|
||||
_mockDeadActivityRepository.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(x => x.Count == 4)));
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(4, result.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveDeadActivityRange_FilteredOut_OK()
|
||||
{
|
||||
var deadActivities = new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1", SystemType.Action, DeadActivityReason.Other, "Oh"),
|
||||
new DeadActivity("2", SystemType.Action, DeadActivityReason.Other, "No"),
|
||||
new DeadActivity("3", SystemType.Action, DeadActivityReason.Other, "Dead"),
|
||||
new DeadActivity("4", SystemType.Action, DeadActivityReason.Other, "Activity")
|
||||
};
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(deadActivities);
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1", SystemType.Action, DeadActivityReason.Other, "Oh"),
|
||||
new DeadActivity("2", SystemType.Action, DeadActivityReason.Other, "No"),
|
||||
});
|
||||
|
||||
var result = await _service.SaveDeadActivityRange(deadActivities);
|
||||
|
||||
_mockDeadActivityRepository.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(x => x.Count == 2)));
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task SaveDeadActivityRange_FilteredOutAll_OK()
|
||||
{
|
||||
var deadActivities = new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1", SystemType.Action, DeadActivityReason.Other, "Oh"),
|
||||
new DeadActivity("2", SystemType.Action, DeadActivityReason.Other, "No"),
|
||||
new DeadActivity("3", SystemType.Action, DeadActivityReason.Other, "Dead"),
|
||||
new DeadActivity("4", SystemType.Action, DeadActivityReason.Other, "Activity")
|
||||
};
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(deadActivities);
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(deadActivities);
|
||||
|
||||
var result = await _service.SaveDeadActivityRange(deadActivities);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(0, result.Count);
|
||||
}
|
||||
|
||||
[TestCase("Product", Product.Mortgage, true)]
|
||||
[TestCase("Product", Product.Vehicle, false)]
|
||||
[TestCase("Product", null, false)]
|
||||
[TestCase("Type",ActivityType.Other, false)]
|
||||
[TestCase("Type",null, false)]
|
||||
[TestCase("SourceId", "1", false)]
|
||||
[TestCase("SourceSystem", SystemType.Redtail, false)]
|
||||
[TestCase("EmployeeId", "1234", false)]
|
||||
[TestCase("EmployeeId", null, true)]
|
||||
[TestCase("EmployeeEmail", "[email protected]", true)]
|
||||
[TestCase("EmployeeEmail", "[email protected]", true)]
|
||||
[TestCase("EmployeeEmail", "[email protected]", false)]
|
||||
[TestCase("EmployeeEmail", null, false)]
|
||||
[TestCase("DepartmentId", -1, false)]
|
||||
[TestCase("DepartmentId", null, true)]
|
||||
[TestCase("DepartmentId", 100, false)]
|
||||
public async Task FilterActivitiesByIdentifyingFields_OK(string property, object value, bool expectFilteredOut)
|
||||
{
|
||||
var deadActivities = new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1234", SystemType.Dna, DeadActivityReason.Other, "Missing Info")
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Type = ActivityType.Sale,
|
||||
SourceId = "1234",
|
||||
SourceSystem = SystemType.Dna,
|
||||
EmployeeId = null,
|
||||
EmployeeEmail = "[email protected]",
|
||||
DepartmentId = null,
|
||||
DeadDetail = new DeadActivityDetail()
|
||||
{
|
||||
AgreementNumber = "abc"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var existingActivity =
|
||||
new DeadActivity("1234", SystemType.Dna, DeadActivityReason.Other, "Missing Info")
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Type = ActivityType.Sale,
|
||||
SourceId = "1234",
|
||||
SourceSystem = SystemType.Dna,
|
||||
EmployeeId = null,
|
||||
EmployeeEmail = "[email protected]",
|
||||
DepartmentId = null,
|
||||
DeadDetail = new DeadActivityDetail()
|
||||
{
|
||||
AgreementNumber = "abc"
|
||||
}
|
||||
};
|
||||
|
||||
existingActivity.GetType().GetProperty(property)?.SetValue(existingActivity, value, null);
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(deadActivities);
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>(){existingActivity});
|
||||
|
||||
var results = await _service.SaveDeadActivityRange(deadActivities);
|
||||
Assert.AreEqual(expectFilteredOut, results.Count == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FilterActivitiesByIdentifyingFields_Details_OK()
|
||||
{
|
||||
var deadActivities = new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1234", SystemType.Dna, DeadActivityReason.Other, "Missing Info")
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Type = ActivityType.Sale,
|
||||
SourceId = "1234",
|
||||
SourceSystem = SystemType.Dna,
|
||||
EmployeeId = null,
|
||||
EmployeeEmail = "[email protected]",
|
||||
DepartmentId = null,
|
||||
DeadDetail = new DeadActivityDetail()
|
||||
{
|
||||
//We dont filter on this field
|
||||
AgreementNumber = "abc"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var existingActivity =
|
||||
new DeadActivity("1234", SystemType.Dna, DeadActivityReason.Other, "Missing Info")
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Type = ActivityType.Sale,
|
||||
SourceId = "1234",
|
||||
SourceSystem = SystemType.Dna,
|
||||
EmployeeId = null,
|
||||
EmployeeEmail = "[email protected]",
|
||||
DepartmentId = null,
|
||||
DeadDetail = new DeadActivityDetail()
|
||||
{
|
||||
//We dont filter on this field
|
||||
AgreementNumber = null
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(deadActivities);
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>(){existingActivity});
|
||||
|
||||
var results = await _service.SaveDeadActivityRange(deadActivities);
|
||||
Assert.AreEqual(true, results.Count == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FilterActivitiesByIdentifyingFields_NullDetails_OK()
|
||||
{
|
||||
var deadActivities = new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1234", SystemType.Dna, DeadActivityReason.Other, "Missing Info")
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Type = ActivityType.Sale,
|
||||
SourceId = "1234",
|
||||
SourceSystem = SystemType.Dna,
|
||||
EmployeeId = null,
|
||||
EmployeeEmail = "[email protected]",
|
||||
DepartmentId = null,
|
||||
DeadDetail = new DeadActivityDetail()
|
||||
{
|
||||
AccountNumber = "123"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var existingActivity =
|
||||
new DeadActivity("1234", SystemType.Dna, DeadActivityReason.Other, "Missing Info")
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Type = ActivityType.Sale,
|
||||
SourceId = "1234",
|
||||
SourceSystem = SystemType.Dna,
|
||||
EmployeeId = null,
|
||||
EmployeeEmail = "[email protected]",
|
||||
DepartmentId = null,
|
||||
DeadDetail = null
|
||||
};
|
||||
|
||||
|
||||
_mockDeadActivityRepository.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()))
|
||||
.ReturnsAsync(deadActivities);
|
||||
_mockDeadActivityRepository.Setup(x => x.GetDeadActivitiesBySourceIds(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(new List<DeadActivity>(){existingActivity});
|
||||
|
||||
var results = await _service.SaveDeadActivityRange(deadActivities);
|
||||
Assert.AreEqual(false, results.Count == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivity_ReturnsActivity()
|
||||
{
|
||||
var activityFromRepo = new DeadActivity(new Activity
|
||||
{
|
||||
Id = 100,
|
||||
DepartmentId = 32,
|
||||
EmployeeId = "1",
|
||||
Type = ActivityType.Sale,
|
||||
Product = Product.CheckCard,
|
||||
Accepted = DateTime.Today,
|
||||
Detail = new ActivityDetail(),
|
||||
ActivityPayouts = new List<ActivityPayoutLineItem>()
|
||||
}, DeadActivityReason.Other, "Test");
|
||||
//pretend there is more than 1 in repository
|
||||
activityFromRepo.Id = 3;
|
||||
_mockDeadActivityRepository.Setup(mock => mock.GetDeadActivityById(3))
|
||||
.ReturnsAsync(activityFromRepo);
|
||||
|
||||
var result = await _service.GetDeadActivity(3);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(3, result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivity_ThrowsWhenNull()
|
||||
{
|
||||
_mockDeadActivityRepository.Setup(mock => mock.GetDeadActivityById(3))
|
||||
.ReturnsAsync((DeadActivity) null);
|
||||
|
||||
Assert.ThrowsAsync<NotFoundException>(async () => await _service.GetDeadActivity(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Updates_DeadActivity()
|
||||
{
|
||||
var activity = new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test");
|
||||
activity.Id = 4;
|
||||
activity.LivingActivityId = null;
|
||||
|
||||
_mockDeadActivityRepository.Setup(mock => mock.GetDeadActivityById(4))
|
||||
.ReturnsAsync(activity);
|
||||
_mockUnitOfWork.Setup(x => x.CompleteAsync()).Verifiable();
|
||||
|
||||
Assert.IsNull(activity.LivingActivityId);
|
||||
var activity2 = await _service.ProcessDeadActivity(4, 1);
|
||||
Assert.AreEqual(activity.Id,activity2.Id);
|
||||
Assert.AreEqual(1, activity2.LivingActivityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+522
@@ -0,0 +1,522 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class DepartmentServiceTest
|
||||
{
|
||||
private DepartmentService _departmentService;
|
||||
private IDepartmentRepository _departmentRepository;
|
||||
private ICurrentUserService _currentUserService;
|
||||
private IUserAssignmentService _userAssignmentService;
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var mockDateTime = new DateTimeService();
|
||||
_currentUserService = Mock.Of<ICurrentUserService>();
|
||||
_userAssignmentService = Mock.Of<IUserAssignmentService>();
|
||||
|
||||
Mock.Get(_currentUserService).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, _currentUserService, mockDateTime);
|
||||
_departmentRepository = new DepartmentRepository(_context);
|
||||
|
||||
_departmentService =
|
||||
new DepartmentService(_departmentRepository, _userAssignmentService, new UnitOfWork(_context));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Basic_Flow()
|
||||
{
|
||||
//Retrieve Empty
|
||||
var departments = await _departmentService.GetAllDepartmentsAsync();
|
||||
Assert.IsNotNull(departments);
|
||||
Assert.IsEmpty(departments);
|
||||
|
||||
//Add New Department
|
||||
var department = await _departmentService.SaveDepartmentAsync(new Department()
|
||||
{
|
||||
BusinessLineCode = "1",
|
||||
DayforceDepartmentName = "TestName",
|
||||
DayForceGlCode = "1",
|
||||
DepartmentName = "TestName",
|
||||
DnaOrgNbr = "1"
|
||||
});
|
||||
Assert.NotNull(department);
|
||||
Assert.True(department.DepartmentName == "TestName");
|
||||
|
||||
//New Department Can Be Retrieved
|
||||
departments = await _departmentService.GetAllDepartmentsAsync();
|
||||
Assert.IsNotNull(departments);
|
||||
Assert.True(departments.Count == 1);
|
||||
Assert.True(departments.SingleOrDefault()?.DepartmentName == "TestName");
|
||||
|
||||
var id = departments.SingleOrDefault()?.Id;
|
||||
if (id == null)
|
||||
{
|
||||
Assert.Fail("Department ID was null, a save failed");
|
||||
return;
|
||||
}
|
||||
|
||||
//Department can be updated
|
||||
department =
|
||||
await _departmentService.UpdateDepartmentAsync(
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "NewName", State = DepartmentState.Active, BusinessLineCode = "BUS",
|
||||
RegionCode = "CENTRAL"
|
||||
}, (int)id);
|
||||
Assert.NotNull(department);
|
||||
Assert.True(department.DepartmentName == "NewName");
|
||||
Assert.True(department.BusinessLineCode == "BUS");
|
||||
Assert.True(department.RegionCode == "CENTRAL");
|
||||
Assert.True(department.State == DepartmentState.Active);
|
||||
|
||||
//Updated department can be retrieved individually
|
||||
department = await _departmentService.GetDepartmentByIdAsync((int)id);
|
||||
Assert.True(department.DepartmentName == "NewName");
|
||||
|
||||
//Updated department can be retrieved by all
|
||||
departments = await _departmentService.GetAllDepartmentsAsync();
|
||||
Assert.IsNotNull(departments);
|
||||
Assert.True(departments.Count == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Throws_Duplicate_Exception()
|
||||
{
|
||||
//Add New Department
|
||||
var testDepartment = await _departmentService.SaveDepartmentAsync(new Department()
|
||||
{
|
||||
BusinessLineCode = "1",
|
||||
DayforceDepartmentName = "TestName",
|
||||
DayForceGlCode = "1",
|
||||
DepartmentName = "TestName",
|
||||
DnaOrgNbr = "1"
|
||||
});
|
||||
Assert.NotNull(testDepartment);
|
||||
Assert.True(testDepartment.DepartmentName == "TestName");
|
||||
|
||||
//Add New Department
|
||||
var testDepartment2 = await _departmentService.SaveDepartmentAsync(new Department()
|
||||
{
|
||||
BusinessLineCode = "1",
|
||||
DayforceDepartmentName = "TestName2",
|
||||
DayForceGlCode = "1",
|
||||
DepartmentName = "TestName2",
|
||||
DnaOrgNbr = "1"
|
||||
});
|
||||
Assert.NotNull(testDepartment2);
|
||||
Assert.True(testDepartment2.DepartmentName == "TestName2");
|
||||
|
||||
//Add New Department With Same Name
|
||||
Assert.ThrowsAsync<DuplicateDataException>(async () =>
|
||||
{
|
||||
await _departmentService.SaveDepartmentAsync(new Department() { BusinessLineCode = "1",
|
||||
DayforceDepartmentName = "TestName",
|
||||
DayForceGlCode = "1",
|
||||
DepartmentName = "TestName",
|
||||
DnaOrgNbr = "1" });
|
||||
});
|
||||
|
||||
//Add New Department With Same Name Ignore Case
|
||||
Assert.ThrowsAsync<DuplicateDataException>(async () =>
|
||||
{
|
||||
await _departmentService.SaveDepartmentAsync(new Department() { BusinessLineCode = "1",
|
||||
DayforceDepartmentName = "TestName",
|
||||
DayForceGlCode = "1",
|
||||
DepartmentName = "testname",
|
||||
DnaOrgNbr = "1" });
|
||||
});
|
||||
|
||||
|
||||
//Update Department To Already Existing Name
|
||||
Assert.ThrowsAsync<DuplicateDataException>(async () =>
|
||||
{
|
||||
await _departmentService.UpdateDepartmentAsync(new Department() { DepartmentName = "TestName" },
|
||||
testDepartment2.Id ?? 1);
|
||||
});
|
||||
|
||||
//Allow Update to Update itself (Same Name), should not throw
|
||||
try
|
||||
{
|
||||
var updatedDepartment = await _departmentService.UpdateDepartmentAsync(
|
||||
new Department() { DepartmentName = "TestName2", BusinessLineCode = "2" }, testDepartment2.Id ?? 1);
|
||||
Assert.AreEqual("TestName2", updatedDepartment.DepartmentName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDepartmentDetailsAsync_Basic()
|
||||
{
|
||||
var department = new Department()
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
|
||||
var user = new AppUser
|
||||
{
|
||||
HomeDepartment = "Home",
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Abraham TestAssociate1",
|
||||
BaseRole = "UNKNOWN",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
|
||||
user.Departments.ForEach(x => x.Employee = user);
|
||||
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
|
||||
var testDepartment = await _departmentService.SaveDepartmentAsync(new Department()
|
||||
{
|
||||
BusinessLineCode = "1",
|
||||
DayforceDepartmentName = "TestName",
|
||||
DayForceGlCode = "1",
|
||||
DepartmentName = "TestName",
|
||||
DnaOrgNbr = "1",
|
||||
Assignments = new List<UserDepartment>
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Id = 11,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = yesterday,
|
||||
EndDate = null
|
||||
},
|
||||
new UserDepartment()
|
||||
{
|
||||
Id = 12,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = false,
|
||||
StartDate = yesterday,
|
||||
EndDate = null
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _departmentService.GetDepartmentDetailsAsync(testDepartment.Id.Value);
|
||||
|
||||
Assert.AreEqual("TestName", result.Department.DepartmentName);
|
||||
Assert.AreEqual(testDepartment.Assignments.Count, result.Assignments.Count);
|
||||
Assert.AreEqual(11, result.Assignments.ElementAt(0).Id);
|
||||
Assert.AreEqual(12, result.Assignments.ElementAt(1).Id);
|
||||
Assert.IsNull(result.RegionalManager);
|
||||
|
||||
Mock.Get(_userAssignmentService).Verify(
|
||||
mock => mock.GetUserAssignment(AssignmentType.RegionalManager, It.IsAny<string>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDepartmentDetailsAsync_NotFoundException()
|
||||
{
|
||||
var exception = Assert.ThrowsAsync<NotFoundException>(async () => { await _departmentService.GetDepartmentDetailsAsync(1); });
|
||||
|
||||
Assert.AreEqual("Could Not Find Department With ID 1", exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDepartmentDetailsAsync_RegionCodeLookup()
|
||||
{
|
||||
var user = new AppUser
|
||||
{
|
||||
HomeDepartment = "Home",
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "C0000",
|
||||
FullName = "Abraham TestAssociate1",
|
||||
BaseRole = "UNKNOWN",
|
||||
PersonId = 0,
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var yesterday = DateTime.Now.AddDays(-1);
|
||||
var testDepartment = await _departmentService.SaveDepartmentAsync(new Department()
|
||||
{
|
||||
BusinessLineCode = "1",
|
||||
DayforceDepartmentName = "TestName",
|
||||
DayForceGlCode = "1",
|
||||
DepartmentName = "TestName",
|
||||
DnaOrgNbr = "1",
|
||||
Assignments = new List<UserDepartment>
|
||||
{
|
||||
new UserDepartment { Id = 11, StartDate = yesterday, Employee = user, IsHome = true, Role = Role.Admin},
|
||||
new UserDepartment { Id = 12, StartDate = yesterday, Employee = user, IsHome = false, Role = Role.Admin}
|
||||
},
|
||||
RegionCode = "NORTH"
|
||||
});
|
||||
var regionalManager = new AppUser
|
||||
{ AdEmail = "[email protected]", EmployeeId = "RM000", PersonId = 1 };
|
||||
var regionalManagerAssignment = new UserAssignment
|
||||
{
|
||||
Type = AssignmentType.RegionalManager,
|
||||
Key = testDepartment.RegionCode,
|
||||
AppUser = regionalManager
|
||||
};
|
||||
Mock.Get(_userAssignmentService)
|
||||
.Setup(mock => mock.GetUserAssignment(AssignmentType.RegionalManager, It.IsAny<string>()))
|
||||
.ReturnsAsync(regionalManagerAssignment);
|
||||
|
||||
|
||||
var result = await _departmentService.GetDepartmentDetailsAsync(testDepartment.Id.Value);
|
||||
|
||||
Assert.AreEqual("[email protected]", result.RegionalManager.AdEmail);
|
||||
Assert.AreEqual("RM000", result.RegionalManager.EmployeeId);
|
||||
Assert.AreEqual(1, result.RegionalManager.PersonId);
|
||||
|
||||
Mock.Get(_userAssignmentService).Verify(
|
||||
mock => mock.GetUserAssignment(AssignmentType.RegionalManager, It.IsAny<string>()),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetHierarchicalDepartmentsForEmployeeAsync_Basic_ADMIN()
|
||||
{
|
||||
var departmentRepository = Mock.Of<IDepartmentRepository>();
|
||||
var userAssignmentService = Mock.Of<IUserAssignmentService>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var departmentService =
|
||||
new DepartmentService(departmentRepository, userAssignmentService, mockUnitOfWork.Object);
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Role = Role.Admin
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(departmentRepository).Setup(s => s.GetAllDepartmentsAsync()).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "testdep1"
|
||||
}
|
||||
});
|
||||
|
||||
Mock.Get(departmentRepository).Setup(s => s.FindDepartmentsByRegionAsync(It.IsAny<Region>())).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "testdep2"
|
||||
}
|
||||
});
|
||||
|
||||
var results = await departmentService.GetHierarchicalDepartmentsForEmployeeAsync(user, false);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsNotEmpty(results);
|
||||
Mock.Get(departmentRepository).Verify(s => s.GetAllDepartmentsAsync(), Times.Once);
|
||||
Mock.Get(departmentRepository).Verify(s => s.FindDepartmentsByRegionAsync(It.IsAny<Region>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetHierarchicalDepartmentsForEmployeeAsync_Basic_RM()
|
||||
{
|
||||
var departmentRepository = Mock.Of<IDepartmentRepository>();
|
||||
var userAssignmentService = Mock.Of<IUserAssignmentService>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var departmentService =
|
||||
new DepartmentService(departmentRepository, userAssignmentService, mockUnitOfWork.Object);
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Role = Role.RegionalManager,
|
||||
Department = new Department()
|
||||
{
|
||||
RegionCode = Region.East.Code
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(departmentRepository).Setup(s => s.GetAllDepartmentsAsync()).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "testdep1"
|
||||
}
|
||||
});
|
||||
|
||||
Mock.Get(departmentRepository).Setup(s => s.FindDepartmentsByRegionAsync(It.IsAny<Region>())).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "testdep2"
|
||||
}
|
||||
});
|
||||
|
||||
var results = await departmentService.GetHierarchicalDepartmentsForEmployeeAsync(user, false);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsNotEmpty(results);
|
||||
Mock.Get(departmentRepository).Verify(s => s.GetAllDepartmentsAsync(), Times.Never);
|
||||
Mock.Get(departmentRepository).Verify(s => s.FindDepartmentsByRegionAsync(It.IsAny<Region>()), Times.Once);
|
||||
}
|
||||
|
||||
// if you are RM but there is no region, you'll just get the branch where you are RM back...
|
||||
[Test]
|
||||
public async Task GetHierarchicalDepartmentsForEmployeeAsync_Basic_RM_null_region()
|
||||
{
|
||||
var departmentRepository = Mock.Of<IDepartmentRepository>();
|
||||
var userAssignmentService = Mock.Of<IUserAssignmentService>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var departmentService =
|
||||
new DepartmentService(departmentRepository, userAssignmentService, mockUnitOfWork.Object);
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Role = Role.RegionalManager,
|
||||
Department = new Department()
|
||||
{
|
||||
DepartmentName = "testdep3"
|
||||
// No Region.
|
||||
},
|
||||
StartDate = DateTime.Today
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(departmentRepository).Setup(s => s.GetAllDepartmentsAsync()).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "testdep1"
|
||||
}
|
||||
});
|
||||
|
||||
Mock.Get(departmentRepository).Setup(s => s.FindDepartmentsByRegionAsync(It.IsAny<Region>())).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "testdep2"
|
||||
}
|
||||
});
|
||||
|
||||
var results = await departmentService.GetHierarchicalDepartmentsForEmployeeAsync(user, false);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsNotEmpty(results);
|
||||
Mock.Get(departmentRepository).Verify(s => s.GetAllDepartmentsAsync(), Times.Never);
|
||||
Mock.Get(departmentRepository).Verify(s => s.FindDepartmentsByRegionAsync(It.IsAny<Region>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetHierarchicalDepartmentsForEmployeeAsync_Basic_ABM_MANAGER_BM()
|
||||
{
|
||||
var departmentRepository = Mock.Of<IDepartmentRepository>();
|
||||
var userAssignmentService = Mock.Of<IUserAssignmentService>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var departmentService =
|
||||
new DepartmentService(departmentRepository, userAssignmentService, mockUnitOfWork.Object);
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Role = Role.ABM,
|
||||
Department = new Department()
|
||||
{
|
||||
DepartmentName = "testdeptabm"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(departmentRepository).Setup(s => s.GetAllDepartmentsAsync()).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "testdep1"
|
||||
}
|
||||
});
|
||||
|
||||
Mock.Get(departmentRepository).Setup(s => s.FindDepartmentsByRegionAsync(It.IsAny<Region>())).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
DepartmentName = "testdep2"
|
||||
}
|
||||
});
|
||||
|
||||
var results = await departmentService.GetHierarchicalDepartmentsForEmployeeAsync(user, true);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsNotEmpty(results);
|
||||
Mock.Get(departmentRepository).Verify(s => s.GetAllDepartmentsAsync(), Times.Never);
|
||||
Mock.Get(departmentRepository).Verify(s => s.FindDepartmentsByRegionAsync(It.IsAny<Region>()), Times.Never);
|
||||
|
||||
results = await departmentService.GetHierarchicalDepartmentsForEmployeeAsync(user, false);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsEmpty(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1107
File diff suppressed because it is too large
Load Diff
+1636
File diff suppressed because it is too large
Load Diff
+146
@@ -0,0 +1,146 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.AutoDecision;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class DnaActivitySyncServiceTest
|
||||
{
|
||||
private Mock<IActivityService> _mockActivityService;
|
||||
private Mock<IActivityDecisionService> _mockActivityDecisionService;
|
||||
private Mock<IExternalActivityService> _mockExternalActivityservice;
|
||||
private Mock<IProcessorHistoryService> _mockProcessorHistoryService;
|
||||
private DnaActivitySyncService _dnaSyncService;
|
||||
private Mock<IDeadActivityService> _mockDeadActivityService;
|
||||
|
||||
// [SetUp]
|
||||
// public void Setup()
|
||||
// {
|
||||
// _mockActivityService = new Mock<IActivityService>();
|
||||
// _mockActivityDecisionService = new Mock<IActivityDecisionService>();
|
||||
// _mockProcessorHistoryService = new Mock<IProcessorHistoryService>();
|
||||
// _mockExternalActivityservice = new Mock<IExternalActivityService>();
|
||||
// _mockDeadActivityService = new Mock<IDeadActivityService>();
|
||||
|
||||
// _dnaSyncService = new DnaActivitySyncService(
|
||||
// _mockActivityService.Object,
|
||||
// _mockProcessorHistoryService.Object,
|
||||
// _mockActivityDecisionService.Object,
|
||||
// _mockDeadActivityService.Object,
|
||||
// _mockExternalActivityservice.Object);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public async Task HandleIncomingActivityDecision_SaveDeadActivity_OK()
|
||||
// {
|
||||
// _mockActivityService.Setup(x => x.SaveActivityAsync(It.IsAny<Activity>()))
|
||||
// .ThrowsAsync(new DeadActivityException("Missing Employee ID"));
|
||||
|
||||
// _mockDeadActivityService.Setup(x => x.SaveDeadActivity(It.IsAny<DeadActivity>()))
|
||||
// .ReturnsAsync(new DeadActivity("6", SystemType.Dna, DeadActivityReason.Other, "Test") { Id = 5 });
|
||||
|
||||
// var testActivity = new Activity()
|
||||
// {
|
||||
// SourceId = "10",
|
||||
// Detail = new ActivityDetail()
|
||||
// {
|
||||
// AccountNumber = "12345"
|
||||
// },
|
||||
// EmployeeId = null,
|
||||
// DepartmentId = -1,
|
||||
// EmployeeEmail = "[email protected]"
|
||||
// };
|
||||
|
||||
// await _dnaSyncService.HandleIncomingActivityDecision(testActivity, Product.NewChecking, ActivityType.Sale);
|
||||
|
||||
// _mockDeadActivityService.Verify(x => x.SaveDeadActivity(It.Is<DeadActivity>(x =>
|
||||
// x.Reason == DeadActivityReason.MissingRequiredField &&
|
||||
// x.ReasonNote == "Missing Employee ID" &&
|
||||
// x.SourceId == "10" &&
|
||||
// x.DeadDetail.AccountNumber == "12345" &&
|
||||
// x.EmployeeId == null &&
|
||||
// x.DepartmentId == null &&
|
||||
// x.EmployeeEmail == "[email protected]"
|
||||
// )), Times.Once);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public async Task HandleMapExternalActivities_OK()
|
||||
// {
|
||||
|
||||
// var activities =
|
||||
// new List<IExternalActivity>()
|
||||
// {
|
||||
// new NewLoanSaleActivity()
|
||||
// {
|
||||
// ActivityNbr = 5,
|
||||
// MinorAccountType = "DV01"
|
||||
// },
|
||||
// new NewLoanSaleActivity()
|
||||
// {
|
||||
// ActivityNbr = 6,
|
||||
// MinorAccountType = "DV01"
|
||||
// },
|
||||
// new NewLoanSaleActivity()
|
||||
// {
|
||||
// ActivityNbr = 7,
|
||||
// MinorAccountType = "DV01"
|
||||
// }
|
||||
// };
|
||||
|
||||
// var result = await _dnaSyncService.HandleMapExternalActivities(activities, Product.Vehicle, ActivityType.Sale);
|
||||
|
||||
// Assert.NotNull(result);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public async Task UpdateProcessorHistory_Ok()
|
||||
// {
|
||||
// var testProcess = new ProcessorHistoryRecord()
|
||||
// {
|
||||
// Process = Process.ImportAtmCheckCardSalesFromDna,
|
||||
// LastProcessedRecordId = 200,
|
||||
// LastProcessedRecordTimestamp = DateTime.Parse("2021-07-10"),
|
||||
// LastSuccessfulRunTime = DateTime.Parse("2021-07-10")
|
||||
// };
|
||||
|
||||
// _mockProcessorHistoryService.Setup(x => x.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(testProcess).Verifiable();
|
||||
|
||||
// await _dnaSyncService.UpdateProcessorHistory(Process.ImportAtmCheckCardSalesFromDna, 200, DateTime.Parse("2021-07-10"));
|
||||
|
||||
// _mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Once);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public async Task RunLatestDnaActivitySales_No_New_Activities()
|
||||
// {
|
||||
// _mockProcessorHistoryService.Setup(x => x.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(
|
||||
// new ProcessorHistoryRecord()
|
||||
// {
|
||||
// Process = Process.ImportAtmCheckCardSalesFromDna,
|
||||
// LastProcessedRecordId = 200,
|
||||
// LastProcessedRecordTimestamp = DateTime.Parse("2021-07-10"),
|
||||
// LastSuccessfulRunTime = DateTime.Parse("2021-07-10")
|
||||
// }).Verifiable();
|
||||
|
||||
// _mockActivityService.Setup(
|
||||
// x => x.FilterExternalActivitiesByExistingSourceId(It.IsAny<List<IExternalActivity>>())).ReturnsAsync(new List<IExternalActivity>() { });
|
||||
|
||||
// var result = await _dnaSyncService.GetLastActivityProcessedData(Process.ImportAtmCheckCardSalesFromDna);
|
||||
// Assert.NotNull(result);
|
||||
|
||||
// _mockProcessorHistoryService.Verify(x => x.GetProcessorHistory(It.Is<Process>(process => process == Process.ImportAtmCheckCardSalesFromDna)), Times.Once);
|
||||
// _mockProcessorHistoryService.Verify(x => x.GetProcessorHistory(It.IsAny<Process>()), Times.Once);
|
||||
// _mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Never);
|
||||
// }
|
||||
}
|
||||
}
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Accounts;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Activity;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Transaction;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class DnaServiceTests
|
||||
{
|
||||
private IDnaService _dnaService;
|
||||
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
|
||||
_dnaService = new DnaService(_mockCoreApiWrapperService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetNewAccountDetailsForActivities_OK()
|
||||
{
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetUpdatedAccountInformation(It.IsAny<List<long>>())).ReturnsAsync(
|
||||
new List<ActivityAccountDetails>()
|
||||
{
|
||||
new ActivityAccountDetails()
|
||||
{
|
||||
AccountNumber = 1
|
||||
},
|
||||
new ActivityAccountDetails()
|
||||
{
|
||||
AccountNumber = 2
|
||||
},
|
||||
new ActivityAccountDetails()
|
||||
{
|
||||
AccountNumber = 3
|
||||
}
|
||||
});
|
||||
|
||||
var results = await _dnaService.GetNewAccountDetailsForActivities(new List<Activity>()
|
||||
{
|
||||
new Activity()
|
||||
{
|
||||
Id = 1,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "1"
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "2"
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 3,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "3"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(3, results.Count);
|
||||
|
||||
_mockCoreApiWrapperService.Verify(x =>
|
||||
x.GetUpdatedAccountInformation(It.Is<List<long>>(x =>
|
||||
x.Contains(1) && x.Contains(2) && x.Contains(3))));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetNewAccountDetailsForActivities_OnlyKnown_OK()
|
||||
{
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetUpdatedAccountInformation(It.IsAny<List<long>>())).ReturnsAsync(
|
||||
new List<ActivityAccountDetails>()
|
||||
{
|
||||
new ActivityAccountDetails()
|
||||
{
|
||||
AccountNumber = 1
|
||||
},
|
||||
new ActivityAccountDetails()
|
||||
{
|
||||
AccountNumber = 3
|
||||
}
|
||||
});
|
||||
|
||||
var results = await _dnaService.GetNewAccountDetailsForActivities(new List<Activity>()
|
||||
{
|
||||
new Activity()
|
||||
{
|
||||
Id = 1,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "1"
|
||||
}
|
||||
},
|
||||
//Null Account Number
|
||||
new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 3,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "3"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2, results.Count);
|
||||
|
||||
_mockCoreApiWrapperService.Verify(x =>
|
||||
x.GetUpdatedAccountInformation(It.Is<List<long>>(x =>
|
||||
x.Contains(1) && x.Contains(3))));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetNewAccountDetailsForActivities_BadAccountNumber_OK()
|
||||
{
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetUpdatedAccountInformation(It.IsAny<List<long>>())).ReturnsAsync(
|
||||
new List<ActivityAccountDetails>()
|
||||
{
|
||||
new ActivityAccountDetails()
|
||||
{
|
||||
AccountNumber = 1
|
||||
},
|
||||
new ActivityAccountDetails()
|
||||
{
|
||||
AccountNumber = 3
|
||||
}
|
||||
});
|
||||
|
||||
var results = await _dnaService.GetNewAccountDetailsForActivities(new List<Activity>()
|
||||
{
|
||||
new Activity()
|
||||
{
|
||||
Id = 1,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "ADJFALKDSFJA"
|
||||
}
|
||||
},
|
||||
//Null Account Number
|
||||
new Activity()
|
||||
{
|
||||
Id = 2,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "1"
|
||||
}
|
||||
},
|
||||
new Activity()
|
||||
{
|
||||
Id = 3,
|
||||
Detail = new ActivityDetail()
|
||||
{
|
||||
AccountNumber = "12aDFKADFSF"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2, results.Count);
|
||||
|
||||
_mockCoreApiWrapperService.Verify(x =>
|
||||
x.GetUpdatedAccountInformation(It.Is<List<long>>(x =>
|
||||
x.Contains(1))));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueryActivityManagerForActivities_OK()
|
||||
{
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetActivityManagerActivities(It.IsAny<ActivityQueryRequest>())).ReturnsAsync(
|
||||
new List<NewActivityManagerReferral>()
|
||||
{
|
||||
new NewActivityManagerReferral()
|
||||
{
|
||||
ActivityId = 1
|
||||
},
|
||||
new NewActivityManagerReferral()
|
||||
{
|
||||
ActivityId = 2
|
||||
},
|
||||
new NewActivityManagerReferral()
|
||||
{
|
||||
ActivityId = 3
|
||||
}
|
||||
});
|
||||
|
||||
var results = await _dnaService.QueryActivityManagerForActivities(new List<string>()
|
||||
{
|
||||
"1","2","3"
|
||||
});
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(3, results.Count);
|
||||
|
||||
_mockCoreApiWrapperService.Verify(x =>
|
||||
x.GetActivityManagerActivities(It.Is<ActivityQueryRequest>(x =>
|
||||
x.ActivityIds.Contains(1) && x.ActivityIds.Contains(2) && x.ActivityIds.Contains(3))));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueryActivityManagerForActivities_Null_OK()
|
||||
{
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetActivityManagerActivities(It.IsAny<ActivityQueryRequest>())).ReturnsAsync(
|
||||
new List<NewActivityManagerReferral>()
|
||||
{
|
||||
new NewActivityManagerReferral()
|
||||
{
|
||||
ActivityId = 1
|
||||
},
|
||||
new NewActivityManagerReferral()
|
||||
{
|
||||
ActivityId = 3
|
||||
}
|
||||
});
|
||||
|
||||
var results = await _dnaService.QueryActivityManagerForActivities(new List<string>()
|
||||
{
|
||||
"1",null,"3"
|
||||
});
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2, results.Count);
|
||||
|
||||
_mockCoreApiWrapperService.Verify(x =>
|
||||
x.GetActivityManagerActivities(It.Is<ActivityQueryRequest>(x =>
|
||||
x.ActivityIds.Contains(1) && x.ActivityIds.Contains(3))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTransactionHistory_OK()
|
||||
{
|
||||
var accountNumber = "123456";
|
||||
var startDate = DateTime.Now.AddDays(-1);
|
||||
var endDate = DateTime.Now;
|
||||
var transactionCodes = new List<string> { "XDEP" };
|
||||
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetTransactionHistory(accountNumber, startDate, endDate, transactionCodes)).ReturnsAsync(
|
||||
new List<TransactionHistory>()
|
||||
{
|
||||
new TransactionHistory()
|
||||
{
|
||||
Id = "1"
|
||||
},
|
||||
new TransactionHistory()
|
||||
{
|
||||
Id = "2"
|
||||
}
|
||||
}.AsReadOnly).Verifiable();
|
||||
|
||||
var results = await _dnaService.GetTransactionHistory(accountNumber, startDate, endDate, transactionCodes);
|
||||
|
||||
_mockCoreApiWrapperService.Verify();
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2, results.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTransactionHistory_Null()
|
||||
{
|
||||
var accountNumber = "123456";
|
||||
var startDate = DateTime.Now.AddDays(-1);
|
||||
var endDate = DateTime.Now;
|
||||
var transactionCodes = new List<string> { "XDEP" };
|
||||
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetTransactionHistory(accountNumber, startDate, endDate, transactionCodes)).ReturnsAsync((IReadOnlyCollection<TransactionHistory>)null).Verifiable();
|
||||
|
||||
var results = await _dnaService.GetTransactionHistory(accountNumber, startDate, endDate, transactionCodes);
|
||||
|
||||
_mockCoreApiWrapperService.Verify();
|
||||
Assert.Null(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.DuplicateDetection;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services.DuplicateDetection
|
||||
{
|
||||
public class DefaultDuplicateDetectionStrategyTest
|
||||
{
|
||||
private IActivityRepository _activityRepository;
|
||||
private DefaultDuplicateDetectionStrategy _duplicateDetectionStrategy;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_activityRepository = Mock.Of<IActivityRepository>();
|
||||
_duplicateDetectionStrategy = new DefaultDuplicateDetectionStrategy(_activityRepository);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanDecide()
|
||||
{
|
||||
var activity = new Activity(); // defaults to Sale
|
||||
Assert.True(_duplicateDetectionStrategy.CanDecideActivity(activity));
|
||||
activity.Type = ActivityType.Sale;
|
||||
Assert.True(_duplicateDetectionStrategy.CanDecideActivity(activity));
|
||||
activity.Type = ActivityType.Other;
|
||||
Assert.True(_duplicateDetectionStrategy.CanDecideActivity(activity));
|
||||
}
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.DuplicateDetection;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services.DuplicateDetection
|
||||
{
|
||||
public class DuplicateDetectionServiceTest
|
||||
{
|
||||
private IDuplicateDetectionService _service;
|
||||
IActivityRepository _activityRepository;
|
||||
private IDuplicateDetectionStrategy _strategy;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_activityRepository = Mock.Of<IActivityRepository>();
|
||||
_strategy = Mock.Of<IDuplicateDetectionStrategy>();
|
||||
var strategies = new List<IDuplicateDetectionStrategy>()
|
||||
{
|
||||
_strategy
|
||||
};
|
||||
_service = new DuplicateDetectionService(strategies, _activityRepository);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AllTypesCoveredOnce()
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
Id = 1,
|
||||
Type = ActivityType.Other,
|
||||
Product = Product.Mortgage,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var duplicates = new List<Activity>() { activity };
|
||||
Mock.Get(_strategy).Setup(x => x.CanDecideActivity(It.IsAny<Activity>())).Returns(true);
|
||||
Mock.Get(_strategy).Setup(x => x.FindDuplicates(It.IsAny<Activity>())).ReturnsAsync(duplicates);
|
||||
|
||||
var results = await _service.TryFindDuplicates(activity);
|
||||
Assert.NotNull(results);
|
||||
Assert.IsNotEmpty(results);
|
||||
|
||||
Mock.Get(_strategy).Verify(x => x.CanDecideActivity(It.IsAny<Activity>()), Times.Once);
|
||||
Mock.Get(_strategy).Verify(x => x.FindDuplicates(It.IsAny<Activity>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThrowsWithoutStrategy()
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
Id = 1,
|
||||
Type = ActivityType.Other,
|
||||
Product = Product.Mortgage,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var strategies = new List<IDuplicateDetectionStrategy>();
|
||||
var service = new DuplicateDetectionService(strategies, _activityRepository);
|
||||
Assert.ThrowsAsync<NoAvailableStrategy>(async () =>
|
||||
{
|
||||
await service.TryFindDuplicates(activity);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.DuplicateDetection;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services.DuplicateDetection
|
||||
{
|
||||
public class ReferralDuplicateDetectionStrategyTest
|
||||
{
|
||||
IActivityRepository _activityRepository;
|
||||
ReferralDuplicateDetectionStrategy _duplicateDetectionStrategy;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_activityRepository = Mock.Of<IActivityRepository>();
|
||||
_duplicateDetectionStrategy = new ReferralDuplicateDetectionStrategy(_activityRepository);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanDecide()
|
||||
{
|
||||
var activity = new Activity();
|
||||
Assert.False(_duplicateDetectionStrategy.CanDecideActivity(activity));
|
||||
activity.Type = ActivityType.Sale;
|
||||
Assert.False(_duplicateDetectionStrategy.CanDecideActivity(activity));
|
||||
activity.Type = ActivityType.Other;
|
||||
Assert.False(_duplicateDetectionStrategy.CanDecideActivity(activity));
|
||||
activity.Type = ActivityType.Referral;
|
||||
Assert.True(_duplicateDetectionStrategy.CanDecideActivity(activity));
|
||||
}
|
||||
}
|
||||
}
|
||||
+600
@@ -0,0 +1,600 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class EStatementServiceTest
|
||||
{
|
||||
private EStatementService _referralService;
|
||||
private IActivityRepository _activityRepository;
|
||||
private IUnitOfWork _unitOfWork;
|
||||
private Mock<IProcessorHistoryService> _mockProcessorHistoryService;
|
||||
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
|
||||
private Mock<IActivityService> _mockActivityService;
|
||||
|
||||
[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;
|
||||
var context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
||||
|
||||
_activityRepository = new ActivityRepository(context);
|
||||
_unitOfWork = new UnitOfWork(context);
|
||||
|
||||
_mockProcessorHistoryService = new Mock<IProcessorHistoryService>();
|
||||
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
|
||||
_mockActivityService = new Mock<IActivityService>();
|
||||
|
||||
_referralService =
|
||||
new EStatementService(_mockProcessorHistoryService.Object, _mockCoreApiWrapperService.Object,
|
||||
_mockActivityService.Object, _activityRepository);
|
||||
}
|
||||
|
||||
[TestCase("1111", null)]
|
||||
[TestCase(null, "1111")]
|
||||
[Test]
|
||||
public async Task MatchOrExpireEstatementReferral_MatchOnPersonOrOrgNumber_MatchNoExpire(string supjectPersonNbr, string subjectOrgNbr)
|
||||
{
|
||||
// Delivery methods activity dates must precede referral source created date
|
||||
var deliveryMethodDaysInPast = -2;
|
||||
var referralDaysInPast = -5;
|
||||
|
||||
var matchedEStatementReferral = new Activity()
|
||||
{
|
||||
Product = Product.eStatement,
|
||||
EmployeeId = "1",
|
||||
SourceId = "2",
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
SourceCreated = DateTime.Now.AddDays(referralDaysInPast),
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = null,
|
||||
SubjectPersonNbr = supjectPersonNbr,
|
||||
SubjectOrgNbr = subjectOrgNbr
|
||||
},
|
||||
MetaData = new List<ActivityMetaData> { }
|
||||
};
|
||||
|
||||
matchedEStatementReferral.Id = await _activityRepository.SaveActivityAsync(matchedEStatementReferral);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var lastRun = new ProcessorHistoryRecord() { };
|
||||
_mockProcessorHistoryService.Setup(mock => mock.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(lastRun);
|
||||
|
||||
var matchedDeliveryMethod = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 1,
|
||||
AccountNumber = 11111,
|
||||
PersonNumber = supjectPersonNbr,
|
||||
OrganizationNumber = subjectOrgNbr ?? "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = "0987654321",
|
||||
EmailAddresses = "[email protected]"
|
||||
};
|
||||
|
||||
var methodWithNonMatchingNumbers = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 2,
|
||||
AccountNumber = 22222,
|
||||
PersonNumber = "1234",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = null,
|
||||
EmailAddresses = null
|
||||
};
|
||||
|
||||
var methodWithMetadata = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 3,
|
||||
AccountNumber = 33333,
|
||||
PersonNumber = "5678",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = "2629999999,2622344555,2626788888,2624324444",
|
||||
EmailAddresses = "[email protected],[email protected]"
|
||||
};
|
||||
|
||||
var eStatmentActivities = new List<EStatementDeliveryMethod>() { matchedDeliveryMethod, methodWithNonMatchingNumbers, methodWithMetadata };
|
||||
_mockCoreApiWrapperService.Setup(mock => mock.GetEStatmentDeliveryMethods(It.IsAny<DateTime>())).ReturnsAsync(eStatmentActivities);
|
||||
var results = await _referralService.UpdateOrExpireEStatementReferral();
|
||||
|
||||
_mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Once);
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsTrue(results.Count == 1);
|
||||
Assert.IsTrue(results.First().Note.Contains(matchedDeliveryMethod.AccountNumber.ToString()));
|
||||
Assert.AreEqual(matchedDeliveryMethod.AccountNumber.ToString(), matchedEStatementReferral.Detail.AccountNumber);
|
||||
Assert.AreEqual(matchedEStatementReferral.Id, results.First().ActivityId);
|
||||
Assert.AreEqual(ActivityState.Accepted, results.First().State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task MatchOrExpireEstatementReferral_MatchOnPhoneMetaData_MatchNoExpire()
|
||||
{
|
||||
// Delivery methods activity dates must precede referral source created date
|
||||
var deliveryMethodDaysInPast = -2;
|
||||
var referralDaysInPast = -5;
|
||||
|
||||
var matchedEStatementReferral = new Activity()
|
||||
{
|
||||
Product = Product.eStatement,
|
||||
EmployeeId = "1",
|
||||
SourceId = "2",
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
SourceCreated = DateTime.Now.AddDays(referralDaysInPast),
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = null,
|
||||
SubjectPersonNbr = null,
|
||||
SubjectOrgNbr = null
|
||||
},
|
||||
MetaData = new List<ActivityMetaData> {
|
||||
new ActivityMetaData {
|
||||
MetaData = "1234567890",
|
||||
MetaDataType = MetaDataType.Phone
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
matchedEStatementReferral.Id = await _activityRepository.SaveActivityAsync(matchedEStatementReferral);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var lastRun = new ProcessorHistoryRecord() { };
|
||||
_mockProcessorHistoryService.Setup(mock => mock.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(lastRun);
|
||||
|
||||
var matchedDeliveryMethod = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 1,
|
||||
AccountNumber = 11111,
|
||||
PersonNumber = "1234",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = "1234567890,0987654321", // Additional phone number should be added to referral activity
|
||||
EmailAddresses = "[email protected]" // This email address should be added to the referral activity
|
||||
};
|
||||
|
||||
var methodWithNonMatchingMetadata = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 2,
|
||||
AccountNumber = 22222,
|
||||
PersonNumber = "5678",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = "0987654321",
|
||||
EmailAddresses = "[email protected], [email protected]"
|
||||
};
|
||||
|
||||
var methodWithoutMetadata = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 3,
|
||||
AccountNumber = 33333,
|
||||
PersonNumber = "9134",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = null,
|
||||
EmailAddresses = null
|
||||
};
|
||||
|
||||
var eStatmentActivities = new List<EStatementDeliveryMethod>() { matchedDeliveryMethod, methodWithNonMatchingMetadata, methodWithoutMetadata };
|
||||
_mockCoreApiWrapperService.Setup(mock => mock.GetEStatmentDeliveryMethods(It.IsAny<DateTime>())).ReturnsAsync(eStatmentActivities);
|
||||
var results = await _referralService.UpdateOrExpireEStatementReferral();
|
||||
|
||||
_mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Once);
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsTrue(results.Count == 1);
|
||||
Assert.IsTrue(results.First().Note.Contains(matchedDeliveryMethod.AccountNumber.ToString()));
|
||||
Assert.AreEqual(matchedEStatementReferral.Id, results.First().ActivityId);
|
||||
Assert.AreEqual(ActivityState.Accepted, results.First().State);
|
||||
Assert.AreEqual(2, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Phone).Count()); // Added one new phone number
|
||||
Assert.AreEqual(1, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Email).Count()); // Added one new email address
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task MatchOrExpireReferralsWithoutSales_MatchOnEmailMetaData_MatchNoExpire()
|
||||
{
|
||||
// Delivery methods activity dates must precede referral source created date
|
||||
var deliveryMethodDaysInPast = -2;
|
||||
var referralDaysInPast = -5;
|
||||
|
||||
var matchedEStatementReferral = new Activity()
|
||||
{
|
||||
Product = Product.eStatement,
|
||||
EmployeeId = "1",
|
||||
SourceId = "2",
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
SourceCreated = DateTime.Now.AddDays(referralDaysInPast),
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = null,
|
||||
SubjectPersonNbr = null,
|
||||
SubjectOrgNbr = null
|
||||
},
|
||||
MetaData = new List<ActivityMetaData> {
|
||||
new ActivityMetaData {
|
||||
MetaData = "[email protected]",
|
||||
MetaDataType = MetaDataType.Email
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
matchedEStatementReferral.Id = await _activityRepository.SaveActivityAsync(matchedEStatementReferral);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var lastRun = new ProcessorHistoryRecord() { };
|
||||
_mockProcessorHistoryService.Setup(mock => mock.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(lastRun);
|
||||
|
||||
var matchedDeliveryMethod = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 1,
|
||||
AccountNumber = 11111,
|
||||
PersonNumber = "1234",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = "1234567890", // This phone number should be added to referral activity
|
||||
EmailAddresses = "[email protected], [email protected]" // Additional email address should be added to the referral activity
|
||||
};
|
||||
|
||||
var methodWithNonMatchingMetadata = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 2,
|
||||
AccountNumber = 22222,
|
||||
PersonNumber = "5678",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = "0987654321",
|
||||
EmailAddresses = "[email protected], [email protected]"
|
||||
};
|
||||
|
||||
var methodWithoutMetadata = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 3,
|
||||
AccountNumber = 33333,
|
||||
PersonNumber = "9123",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = null,
|
||||
EmailAddresses = null
|
||||
};
|
||||
|
||||
var eStatmentActivities = new List<EStatementDeliveryMethod>() { matchedDeliveryMethod, methodWithNonMatchingMetadata, methodWithoutMetadata };
|
||||
_mockCoreApiWrapperService.Setup(mock => mock.GetEStatmentDeliveryMethods(It.IsAny<DateTime>())).ReturnsAsync(eStatmentActivities);
|
||||
var results = await _referralService.UpdateOrExpireEStatementReferral();
|
||||
|
||||
_mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Once);
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsTrue(results.Count == 1);
|
||||
Assert.IsTrue(results.First().Note.Contains(matchedDeliveryMethod.AccountNumber.ToString()));
|
||||
Assert.AreEqual(matchedEStatementReferral.Id, results.First().ActivityId);
|
||||
Assert.AreEqual(ActivityState.Accepted, results.First().State);
|
||||
Assert.AreEqual(1, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Phone).Count()); // Added one new phone number
|
||||
Assert.AreEqual(2, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Email).Count()); // Added one new email address
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task MatchOrExpireEstatementReferral_MultipleDeliveryMethodsMatch_OneMatchNoExpire()
|
||||
{
|
||||
// Delivery methods activity dates must precede referral source created date
|
||||
var deliveryMethodDaysInPast = -2;
|
||||
var latestDeliveryMethodDaysInPast = -1;
|
||||
var referralDaysInPast = -5;
|
||||
var referralMatchingPhoneNumber = "1234567890";
|
||||
|
||||
var matchedEStatementReferral = new Activity()
|
||||
{
|
||||
Product = Product.eStatement,
|
||||
EmployeeId = "1",
|
||||
SourceId = "2",
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
SourceCreated = DateTime.Now.AddDays(referralDaysInPast),
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = null,
|
||||
SubjectPersonNbr = null,
|
||||
SubjectOrgNbr = null
|
||||
},
|
||||
MetaData = new List<ActivityMetaData> {
|
||||
new ActivityMetaData {
|
||||
MetaData = referralMatchingPhoneNumber,
|
||||
MetaDataType = MetaDataType.Phone
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
matchedEStatementReferral.Id = await _activityRepository.SaveActivityAsync(matchedEStatementReferral);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var lastRun = new ProcessorHistoryRecord() { };
|
||||
_mockProcessorHistoryService.Setup(mock => mock.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(lastRun);
|
||||
|
||||
var matchedDeliveryMethod = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 1,
|
||||
AccountNumber = 11111,
|
||||
PersonNumber = "1234",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(latestDeliveryMethodDaysInPast),
|
||||
PhoneNumbers = referralMatchingPhoneNumber,
|
||||
EmailAddresses = "[email protected]" // This email address should be added to the referral activity
|
||||
};
|
||||
|
||||
var methodWithNonMatchingMetadata = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 2,
|
||||
AccountNumber = 22222,
|
||||
PersonNumber = "5678",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = referralMatchingPhoneNumber,
|
||||
EmailAddresses = "[email protected], [email protected]"
|
||||
};
|
||||
|
||||
var methodWithoutMetadata = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 3,
|
||||
AccountNumber = 33333,
|
||||
PersonNumber = "9123",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = referralMatchingPhoneNumber,
|
||||
EmailAddresses = null
|
||||
};
|
||||
|
||||
var eStatmentActivities = new List<EStatementDeliveryMethod>() { matchedDeliveryMethod, methodWithNonMatchingMetadata, methodWithoutMetadata };
|
||||
_mockCoreApiWrapperService.Setup(mock => mock.GetEStatmentDeliveryMethods(It.IsAny<DateTime>())).ReturnsAsync(eStatmentActivities);
|
||||
var results = await _referralService.UpdateOrExpireEStatementReferral();
|
||||
|
||||
_mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Once);
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsTrue(results.Count == 1);
|
||||
Assert.IsTrue(results.First().Note.Contains(matchedDeliveryMethod.AccountNumber.ToString()));
|
||||
Assert.AreEqual(matchedEStatementReferral.Id, results.First().ActivityId);
|
||||
Assert.AreEqual(ActivityState.Accepted, results.First().State);
|
||||
Assert.AreEqual(1, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Phone).Count()); // Did not add any phone numbers
|
||||
Assert.AreEqual(1, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Email).Count()); // Added one new email address
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task MatchOrExpireEstatementReferral_MatchMultipleOnPersNumberAndMetaData_OneMatchNoExpire()
|
||||
{
|
||||
// Delivery methods activity dates must precede referral source created date
|
||||
var deliveryMethodDaysInPast = -2;
|
||||
var firstMatchedDeliveryMethodDaysInPast = -2;
|
||||
var latestDeliveryMethodDaysInPast = -1; // Method with this date will match because it is newest
|
||||
var referralDaysInPast = -5;
|
||||
|
||||
var referralMatchingPersNumber = "1111";
|
||||
var referralMatchingPhoneNumber = "1234567890";
|
||||
var referralMatchingEmail = "[email protected]";
|
||||
|
||||
var matchedEStatementReferral = new Activity()
|
||||
{
|
||||
Product = Product.eStatement,
|
||||
EmployeeId = "1",
|
||||
SourceId = "2",
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
SourceCreated = DateTime.Now.AddDays(referralDaysInPast),
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = null,
|
||||
SubjectPersonNbr = referralMatchingPersNumber,
|
||||
SubjectOrgNbr = null
|
||||
},
|
||||
MetaData = new List<ActivityMetaData> {
|
||||
new ActivityMetaData {
|
||||
MetaData = referralMatchingEmail,
|
||||
MetaDataType = MetaDataType.Email
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
matchedEStatementReferral.Id = await _activityRepository.SaveActivityAsync(matchedEStatementReferral);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var lastRun = new ProcessorHistoryRecord() { };
|
||||
_mockProcessorHistoryService.Setup(mock => mock.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(lastRun);
|
||||
|
||||
// Will match on email MetaData
|
||||
var matchedOnEmailDeliveryMethod = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 1,
|
||||
AccountNumber = 11111,
|
||||
PersonNumber = "1234",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(latestDeliveryMethodDaysInPast),
|
||||
PhoneNumbers = referralMatchingPhoneNumber,
|
||||
EmailAddresses = referralMatchingEmail
|
||||
};
|
||||
|
||||
// Will match on PersonNumber
|
||||
var matchedOnPersonNumberButNotLatest = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 2,
|
||||
AccountNumber = 22222,
|
||||
PersonNumber = referralMatchingPersNumber,
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(firstMatchedDeliveryMethodDaysInPast),
|
||||
PhoneNumbers = referralMatchingPhoneNumber,
|
||||
EmailAddresses = referralMatchingEmail
|
||||
};
|
||||
|
||||
var nonMatchingMethod = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 3,
|
||||
AccountNumber = 33333,
|
||||
PersonNumber = "5678",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = null,
|
||||
EmailAddresses = null
|
||||
};
|
||||
|
||||
var eStatmentActivities = new List<EStatementDeliveryMethod>() { matchedOnEmailDeliveryMethod, matchedOnPersonNumberButNotLatest, nonMatchingMethod };
|
||||
_mockCoreApiWrapperService.Setup(mock => mock.GetEStatmentDeliveryMethods(It.IsAny<DateTime>())).ReturnsAsync(eStatmentActivities);
|
||||
var results = await _referralService.UpdateOrExpireEStatementReferral();
|
||||
|
||||
_mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Once);
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsTrue(results.Count == 1);
|
||||
Assert.IsTrue(results.First().Note.Contains(matchedOnEmailDeliveryMethod.AccountNumber.ToString()));
|
||||
Assert.AreEqual(matchedEStatementReferral.Id, results.First().ActivityId);
|
||||
Assert.AreEqual(ActivityState.Accepted, results.First().State);
|
||||
Assert.AreEqual(1, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Phone).Count()); // Did not add any phone numbers
|
||||
Assert.AreEqual(1, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Email).Count()); // Added one new email address
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task MatchOrExpireEstatementReferral_MultipleReferralMatches_MatchOneReferralNoExpire()
|
||||
{
|
||||
// Delivery methods activity dates must precede referral source created date
|
||||
var deliveryMethodDaysInPast = -2;
|
||||
var referralDaysInPast = -5;
|
||||
var latestReferral = -4;
|
||||
|
||||
var duplicateReferral = new Activity()
|
||||
{
|
||||
Product = Product.eStatement,
|
||||
EmployeeId = "1",
|
||||
SourceId = "1",
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
SourceCreated = DateTime.Now.AddDays(latestReferral),
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = null,
|
||||
SubjectPersonNbr = "1234",
|
||||
SubjectOrgNbr = null
|
||||
}
|
||||
};
|
||||
|
||||
duplicateReferral.Id = await _activityRepository.SaveActivityAsync(duplicateReferral);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var matchingReferral = new Activity()
|
||||
{
|
||||
Product = Product.eStatement,
|
||||
EmployeeId = "2",
|
||||
SourceId = "2",
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
SourceCreated = DateTime.Now.AddDays(referralDaysInPast),
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = null,
|
||||
SubjectPersonNbr = "1234",
|
||||
SubjectOrgNbr = null
|
||||
}
|
||||
};
|
||||
// Saving this referral second makes it the "latest" (last updated) and match
|
||||
matchingReferral.Id = await _activityRepository.SaveActivityAsync(matchingReferral);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var lastRun = new ProcessorHistoryRecord() { };
|
||||
_mockProcessorHistoryService.Setup(mock => mock.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(lastRun);
|
||||
|
||||
var matchedDeliveryMethod = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 1,
|
||||
AccountNumber = 11111,
|
||||
PersonNumber = "1234",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = null,
|
||||
EmailAddresses = null
|
||||
};
|
||||
|
||||
var nonMatchedDeliveryMethod = new EStatementDeliveryMethod()
|
||||
{
|
||||
ActivityNumber = 2,
|
||||
AccountNumber = 22222,
|
||||
PersonNumber = "4321",
|
||||
OrganizationNumber = "0",
|
||||
ActivityDateTime = DateTime.Now.AddDays(deliveryMethodDaysInPast),
|
||||
PhoneNumbers = null,
|
||||
EmailAddresses = null
|
||||
};
|
||||
|
||||
var eStatmentActivities = new List<EStatementDeliveryMethod>() { matchedDeliveryMethod };
|
||||
_mockCoreApiWrapperService.Setup(mock => mock.GetEStatmentDeliveryMethods(It.IsAny<DateTime>())).ReturnsAsync(eStatmentActivities);
|
||||
var results = await _referralService.UpdateOrExpireEStatementReferral();
|
||||
|
||||
_mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Once);
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsTrue(results.Count == 1);
|
||||
Assert.IsTrue(results.First().Note.Contains(matchedDeliveryMethod.AccountNumber.ToString()));
|
||||
Assert.AreEqual(matchingReferral.Id, results.First().ActivityId);
|
||||
Assert.AreEqual(ActivityState.Accepted, results.First().State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task MatchOrExpireEstatementReferral_NoMatch_Expire()
|
||||
{
|
||||
var referralDaysInPast = -61; // Expires after 60 days
|
||||
|
||||
var matchedEStatementReferral = new Activity()
|
||||
{
|
||||
Product = Product.eStatement,
|
||||
EmployeeId = "1",
|
||||
SourceId = "2",
|
||||
Type = ActivityType.Referral,
|
||||
State = ActivityState.PendingReferral,
|
||||
SourceCreated = DateTime.Now.AddDays(referralDaysInPast),
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = null,
|
||||
SubjectPersonNbr = null,
|
||||
SubjectOrgNbr = null
|
||||
}
|
||||
};
|
||||
|
||||
matchedEStatementReferral.Id = await _activityRepository.SaveActivityAsync(matchedEStatementReferral);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var lastRun = new ProcessorHistoryRecord() { };
|
||||
_mockProcessorHistoryService.Setup(mock => mock.GetProcessorHistory(It.IsAny<Process>())).ReturnsAsync(lastRun);
|
||||
|
||||
var eStatmentActivities = new List<EStatementDeliveryMethod>() { }; // Matching fails because there are no estatements to match with
|
||||
_mockCoreApiWrapperService.Setup(mock => mock.GetEStatmentDeliveryMethods(It.IsAny<DateTime>())).ReturnsAsync(eStatmentActivities);
|
||||
var results = await _referralService.UpdateOrExpireEStatementReferral();
|
||||
|
||||
_mockProcessorHistoryService.Verify(mock => mock.SaveProcessorHistory(It.IsAny<ProcessorHistoryRecord>()), Times.Never);
|
||||
|
||||
Assert.IsNotNull(results);
|
||||
Assert.IsTrue(results.Count == 1);
|
||||
Assert.IsTrue(results.First().Note.Contains("expired"));
|
||||
Assert.AreEqual(0, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Phone).Count());
|
||||
Assert.AreEqual(0, matchedEStatementReferral.MetaData.Where(x => x.MetaDataType == MetaDataType.Email).Count());
|
||||
}
|
||||
}
|
||||
}
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Extensions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
|
||||
namespace Application.UnitTests.Services.ExternalActivity
|
||||
{
|
||||
public class ExternalActivityServiceTest
|
||||
{
|
||||
private IExternalActivityService _externalActivityService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDepartmentRepository> _mockDepartmentRepository;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockDepartmentRepository = new Mock<IDepartmentRepository>();
|
||||
var strategies = new List<IExternalActivityStrategy>()
|
||||
{
|
||||
new NewCheckingAccountActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object),
|
||||
new NewIncentiveManagerActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object),
|
||||
new NewAtmCheckCardActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object),
|
||||
new NewMortgageActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object)
|
||||
};
|
||||
_externalActivityService = new ExternalActivityService(strategies);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewAtmCheckCardActivityStrategy_ATM_OK()
|
||||
{
|
||||
var externalActivity = new NewAtmCheckCardActivity()
|
||||
{
|
||||
CardType = "ATM",
|
||||
AccountNbr = 1,
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
ResponsiblePersonNbr = 1234,
|
||||
AgreementNbr = 10111,
|
||||
OwnerPersonNbr = "5678",
|
||||
AcctStateAtActivity = "ACT",
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.TryMapExternalActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Other);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewCheckingAccountActivityStrategy_Ok()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.TryMapExternalActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")),
|
||||
Times.Once);
|
||||
_mockUserService.Verify(x => x.GetAllUsersAsync(It.IsAny<UserSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[TestCase("Atm Card", Product.ATMCard)]
|
||||
[TestCase("Check Card Referral", Product.CheckCard)]
|
||||
[TestCase("Checking Referral", Product.NewChecking)]
|
||||
[TestCase("Mortgage Referral", Product.Mortgage)]
|
||||
[TestCase("Direct Deposit", Product.DirectDeposit)]
|
||||
[TestCase("CC Balance Transfer", Product.CreditCardBalanceTransfer)]
|
||||
public async Task NewIncentiveManagerActivityStrategy_Ok(string campaign, Product product)
|
||||
{
|
||||
var externalActivity = new NewActivityManagerReferral()
|
||||
{
|
||||
OriginatingBranchName = "MEQUON",
|
||||
OriginatorPersNbr = 5,
|
||||
OriginatorUserId = "JSMITHB",
|
||||
ReferredPersonNbr = "1234",
|
||||
ReferredPersOrgNbr = null,
|
||||
ReferralStation= "Submitted",
|
||||
StationDateTime = DateTime.Today.StartOfMonth(),
|
||||
Campaign = campaign,
|
||||
OriginationDateTime = DateTime.Parse("2021-03-10"),
|
||||
OriginatorFirstName = "John",
|
||||
OriginatorLastName = "Smith",
|
||||
OriginatorMiddleInitial = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindDepartmentByBranchName(It.IsAny<string>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.TryMapExternalActivity(externalActivity);
|
||||
Assert.True(activity.Product == product);
|
||||
Assert.True(activity.Type == ActivityType.Referral);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindDepartmentByBranchName(It.Is<string>(x => x == "MEQUON")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewMortgageActivityStrategy_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]",
|
||||
MinorAccountType = "FE01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.TryMapExternalActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Mortgage);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.GetAllUsersAsync(It.IsAny<UserSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Extensions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
|
||||
namespace Application.UnitTests.Services.ExternalActivity
|
||||
{
|
||||
public class NewActivityManagerActivityStrategyTest
|
||||
{
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDepartmentRepository> _mockDepartmentRepository;
|
||||
private NewIncentiveManagerActivityStrategy _externalActivityService;
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockDepartmentRepository = new Mock<IDepartmentRepository>();
|
||||
_externalActivityService = new NewIncentiveManagerActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object);
|
||||
}
|
||||
|
||||
[TestCase("Atm Card", Product.ATMCard)]
|
||||
[TestCase("Check Card Referral", Product.CheckCard)]
|
||||
[TestCase("Checking Referral", Product.NewChecking)]
|
||||
[TestCase("Mortgage Referral", Product.Mortgage)]
|
||||
[TestCase("Direct Deposit", Product.DirectDeposit)]
|
||||
[TestCase("CC Balance Transfer", Product.CreditCardBalanceTransfer)]
|
||||
[TestCase("LIC Referral", Product.LIC)]
|
||||
public async Task NewIncentiveManagerActivityStrategy_Ok(string campaign, Product product)
|
||||
{
|
||||
var externalActivity = new NewActivityManagerReferral()
|
||||
{
|
||||
OriginatingBranchName = "MEQUON",
|
||||
OriginatorPersNbr = 5,
|
||||
OriginatorUserId = "JSMITHB",
|
||||
ReferredPersonNbr = "1234",
|
||||
ReferredPersOrgNbr = null,
|
||||
ReferralStation= "Submitted",
|
||||
StationDateTime = DateTime.Today.StartOfMonth(),
|
||||
Campaign = campaign,
|
||||
OriginationDateTime = DateTime.Parse("2021-03-10"),
|
||||
OriginatorFirstName = "John",
|
||||
OriginatorLastName = "Smith",
|
||||
OriginatorMiddleInitial = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindDepartmentByBranchName(It.IsAny<string>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == product);
|
||||
Assert.True(activity.Type == ActivityType.Referral);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindDepartmentByBranchName(It.Is<string>(x => x == "MEQUON")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewIncentiveManagerActivityStrategy_NoEmail_Ok()
|
||||
{
|
||||
var externalActivity = new NewActivityManagerReferral()
|
||||
{
|
||||
OriginatingBranchName = "WEST BEND MAIN",
|
||||
OriginatorPersNbr = 5,
|
||||
OriginatorUserId = "JSMITHB",
|
||||
ReferredPersonNbr = "1234",
|
||||
ReferredPersOrgNbr = null,
|
||||
ReferralStation= "Submitted",
|
||||
StationDateTime = DateTime.Today.StartOfMonth(),
|
||||
Campaign = "ATM Card",
|
||||
OriginationDateTime = DateTime.Parse("2021-03-10"),
|
||||
OriginatorFirstName = "John",
|
||||
OriginatorLastName = "Smith",
|
||||
OriginatorMiddleInitial = "B",
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
_mockDepartmentRepository.Setup(x => x.FindDepartmentByBranchName(It.IsAny<string>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Referral);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindDepartmentByBranchName(It.Is<string>(x => x == "WEST BEND MAIN")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Throws_WhenUnknownProduct_OK()
|
||||
{
|
||||
var externalActivity = new NewActivityManagerReferral()
|
||||
{
|
||||
OriginatingBranchName = "WEST BEND MAIN",
|
||||
OriginatorPersNbr = 5,
|
||||
OriginatorUserId = "JSMITHB",
|
||||
ReferredPersonNbr = "1234",
|
||||
ReferredPersOrgNbr = null,
|
||||
ReferralStation= "Submitted",
|
||||
StationDateTime = DateTime.Today.StartOfMonth(),
|
||||
Campaign = "THIS PRODUCT DOES NOT EXIST",
|
||||
OriginationDateTime = DateTime.Parse("2021-03-10"),
|
||||
OriginatorFirstName = "John",
|
||||
OriginatorLastName = "Smith",
|
||||
OriginatorMiddleInitial = "B",
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
Assert.ThrowsAsync<Exception>(async () => await _externalActivityService.MapToActivityManagerActivity(externalActivity));
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(0));
|
||||
_mockDepartmentRepository.Verify(x => x.FindDepartmentByBranchName(It.Is<string>(x => x == "WEST BEND MAIN")), Times.Once);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewIncentiveManagerActivityStrategy_NoDepartment_Ok()
|
||||
{
|
||||
var externalActivity = new NewActivityManagerReferral()
|
||||
{
|
||||
OriginatingBranchName = "WEST BEND MAIN",
|
||||
OriginatorPersNbr = 5,
|
||||
OriginatorUserId = "JSMITHB",
|
||||
ReferredPersonNbr = "1234",
|
||||
ReferredPersOrgNbr = null,
|
||||
ReferralStation= "Submitted",
|
||||
StationDateTime = DateTime.Today.StartOfMonth(),
|
||||
Campaign = "ATM Card",
|
||||
OriginationDateTime = DateTime.Parse("2021-03-10"),
|
||||
OriginatorFirstName = "John",
|
||||
OriginatorLastName = "Smith",
|
||||
OriginatorMiddleInitial = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindDepartmentByBranchName(It.IsAny<string>())).ReturnsAsync((Department) null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Referral);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindDepartmentByBranchName(It.Is<string>(x => x == "WEST BEND MAIN")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewIncentiveManagerActivityStrategy_ExceptionReturnsBasic()
|
||||
{
|
||||
var externalActivity = new NewActivityManagerReferral()
|
||||
{
|
||||
OriginatingBranchName = "WEST BEND MAIN",
|
||||
OriginatorPersNbr = 5,
|
||||
OriginatorUserId = "JSMITHB",
|
||||
ReferredPersonNbr = "1234",
|
||||
ReferredPersOrgNbr = null,
|
||||
ReferralStation= "Submitted",
|
||||
StationDateTime = DateTime.Today.StartOfMonth(),
|
||||
Campaign = "ATM Card",
|
||||
OriginationDateTime = DateTime.Parse("2021-03-10"),
|
||||
OriginatorFirstName = "John",
|
||||
OriginatorLastName = "Smith",
|
||||
OriginatorMiddleInitial = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindDepartmentByBranchName(It.IsAny<string>()))
|
||||
.ThrowsAsync(new Exception("OOPS"));
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Referral);
|
||||
//we search for user before department, if department fails, we can still save user
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindDepartmentByBranchName(It.Is<string>(x => x == "WEST BEND MAIN")), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
+260
@@ -0,0 +1,260 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
|
||||
namespace Application.UnitTests.Services.ExternalActivity
|
||||
{
|
||||
public class NewAtmCheckCardActivityStrategyTest
|
||||
{
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDepartmentRepository> _mockDepartmentRepository;
|
||||
private NewAtmCheckCardActivityStrategy _externalActivityService;
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockDepartmentRepository = new Mock<IDepartmentRepository>();
|
||||
_externalActivityService = new NewAtmCheckCardActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewAtmCheckCardActivityStrategy_ATM_OK()
|
||||
{
|
||||
var externalActivity = new NewAtmCheckCardActivity()
|
||||
{
|
||||
CardType = "ATM",
|
||||
AccountNbr = 1,
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
ResponsiblePersonNbr = 1234,
|
||||
AgreementNbr = 10111,
|
||||
OwnerPersonNbr = "5678",
|
||||
AcctStateAtActivity = "ACT",
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Other);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewAtmCheckCardActivityStrategy_CheckCard_OK()
|
||||
{
|
||||
var externalActivity = new NewAtmCheckCardActivity()
|
||||
{
|
||||
CardType = "Check Card",
|
||||
AccountNbr = 1,
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
ResponsiblePersonNbr = 1234,
|
||||
AgreementNbr = 10111,
|
||||
OwnerPersonNbr = "5678",
|
||||
AcctStateAtActivity = "ACT",
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.CheckCard);
|
||||
Assert.True(activity.Type == ActivityType.Other);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewAtmCheckCardActivityStrategy_NoEmail_OK()
|
||||
{
|
||||
var externalActivity = new NewAtmCheckCardActivity()
|
||||
{
|
||||
CardType = "ATM",
|
||||
AccountNbr = 1,
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
ResponsiblePersonNbr = 1234,
|
||||
AgreementNbr = 10111,
|
||||
OwnerPersonNbr = "5678",
|
||||
AcctStateAtActivity = "ACT",
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Other);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewAtmCheckCardActivityStrategy_ATM_NoDepartment_OK()
|
||||
{
|
||||
var externalActivity = new NewAtmCheckCardActivity()
|
||||
{
|
||||
CardType = "ATM",
|
||||
AccountNbr = 1,
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
ResponsiblePersonNbr = 1234,
|
||||
AgreementNbr = 10111,
|
||||
OwnerPersonNbr = "5678",
|
||||
AcctStateAtActivity = "ACT",
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync((Department) null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Other);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Once);
|
||||
}
|
||||
|
||||
//NewAtmCheckCard uses Users Home Department to assign branch.
|
||||
[Test]
|
||||
public async Task NewAtmCheckCardActivityStrategy_ATM_NoUser_OK()
|
||||
{
|
||||
var externalActivity = new NewAtmCheckCardActivity()
|
||||
{
|
||||
CardType = "ATM",
|
||||
AccountNbr = 1,
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
ResponsiblePersonNbr = 1234,
|
||||
AgreementNbr = 10111,
|
||||
OwnerPersonNbr = "5678",
|
||||
AcctStateAtActivity = "ACT",
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(new Department()
|
||||
{
|
||||
Id = 10
|
||||
});
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Other);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewAtmCheckCardActivityStrategy_ExceptionReturnsBasic()
|
||||
{
|
||||
var externalActivity = new NewAtmCheckCardActivity()
|
||||
{
|
||||
CardType = "ATM",
|
||||
AccountNbr = 1,
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
ResponsiblePersonNbr = 1234,
|
||||
AgreementNbr = 10111,
|
||||
OwnerPersonNbr = "5678",
|
||||
AcctStateAtActivity = "ACT",
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ThrowsAsync(new Exception("Oops"));
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(new Department()
|
||||
{
|
||||
Id = 10
|
||||
});
|
||||
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.ATMCard);
|
||||
Assert.True(activity.Type == ActivityType.Other);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+433
@@ -0,0 +1,433 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
|
||||
namespace Application.UnitTests.Services.ExternalActivity
|
||||
{
|
||||
public class NewCheckingAccountActivityStrategyTest
|
||||
{
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDepartmentRepository> _mockDepartmentRepository;
|
||||
private NewCheckingAccountActivityStrategy _externalActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockDepartmentRepository = new Mock<IDepartmentRepository>();
|
||||
_externalActivityService = new NewCheckingAccountActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewCheckingAccountActivityStrategy_Ok()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewCheckingAccountActivityStrategy_NoEmail_Ok()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser) null);
|
||||
_mockUserService.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>())).ReturnsAsync(
|
||||
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewCheckingAccountActivityStrategy_NoUser()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser) null);
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
});
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewCheckingAccountActivityStrategy_NoDepartment_Ok()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewCheckingAccountActivityStrategy_ExceptionReturnsBasic()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ThrowsAsync(new Exception("OOPS"));
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ThrowsAsync(new Exception("OOPS"));
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewDigitalBankingCheckingAccountActivityStrategy_Ok()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "Digital Banking",
|
||||
BranchOrgNbr = 1210,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2022-12-10"),
|
||||
AssociateFirst = "Digital",
|
||||
AssociateLast = "Banking",
|
||||
AssociateMiddleInit = "",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "DigitalBankingAppUserEmployeeId"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 43
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(43, activity.DepartmentId);
|
||||
Assert.AreEqual("DigitalBankingAppUserEmployeeId", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "DigitalBankingAppUserEmployeeId")), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task NewDigitalBankingCheckingAccountActivityStrategy_NoEmail_Ok()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "Digital Banking",
|
||||
BranchOrgNbr = 1210,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "Digital",
|
||||
AssociateLast = "Banking",
|
||||
AssociateMiddleInit = ""
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
_mockUserService.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>())).ReturnsAsync(
|
||||
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "DigitalBankingAppUserEmployeeId"
|
||||
});
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 43
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(43, activity.DepartmentId);
|
||||
Assert.AreEqual("DigitalBankingAppUserEmployeeId", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "DigitalBankingAppUserEmployeeId")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewDigitalBankingCheckingAccountActivityStrategy_NoUser()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "Digital Banking",
|
||||
BranchOrgNbr = 1210,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "Digital",
|
||||
AssociateLast = "Banking",
|
||||
AssociateMiddleInit = ""
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 43
|
||||
});
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewDigitalBankingCheckingAccountActivityStrategy_NoDepartment_Ok()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "Digital Banking",
|
||||
BranchOrgNbr = 1210,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "Digital",
|
||||
AssociateLast = "Banking",
|
||||
AssociateMiddleInit = "",
|
||||
EmployeeEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "DigitalBankingAppUserEmployeeId"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual("DigitalBankingAppUserEmployeeId", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "DigitalBankingAppUserEmployeeId")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewDigitalBankingCheckingAccountActivityStrategy_ExceptionReturnsBasic()
|
||||
{
|
||||
var externalActivity = new NewCheckingAccountActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
ResponsiblePersonNbr = 1234,
|
||||
BranchOrgName = "Digital Banking",
|
||||
BranchOrgNbr = 1210,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "Digital",
|
||||
AssociateLast = "Banking",
|
||||
AssociateMiddleInit = ""
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ThrowsAsync(new Exception("OOPS"));
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ThrowsAsync(new Exception("OOPS"));
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.NewChecking);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
|
||||
namespace Application.UnitTests.Services.ExternalActivity
|
||||
{
|
||||
public class NewDebtProtectionEligibleLoanStrategyTest
|
||||
{
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDepartmentRepository> _mockDepartmentRepository;
|
||||
private NewDebtProtectionEligibleLoanStrategy _externalActivityService;
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockDepartmentRepository = new Mock<IDepartmentRepository>();
|
||||
_externalActivityService = new NewDebtProtectionEligibleLoanStrategy(_mockUserService.Object, _mockDepartmentRepository.Object);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task NewDebtProtectionEligibleLoan_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]",
|
||||
MinorAccountType = "SG01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
});
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.DebtProtectionEligibleLoan);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewDebtProtectionEligibleLoan_NoEmail_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "SG01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser) null);
|
||||
_mockUserService.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>())).ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
}
|
||||
);
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
});
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.DebtProtectionEligibleLoan);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewDebtProtectionEligibleLoan_NoUser_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "SG01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser) null);
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
});
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.DebtProtectionEligibleLoan);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Exactly(1));
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewDebtProtectionEligibleLoan_NoDepartment_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]",
|
||||
MinorAccountType = "SG01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.DebtProtectionEligibleLoan);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewDebtProtectionEligibleLoan_ExceptionReturnsBasic()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "SG01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ThrowsAsync(new Exception("OOPS"));
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ThrowsAsync(new Exception("OOPS"));
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.AreEqual(activity.Product, Product.DebtProtectionEligibleLoan);
|
||||
Assert.AreEqual(activity.Type, ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Constants;
|
||||
|
||||
namespace Application.UnitTests.Services.ExternalActivity
|
||||
{
|
||||
public class NewMortgageActivityStrategyTest
|
||||
{
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDepartmentRepository> _mockDepartmentRepository;
|
||||
private NewMortgageActivityStrategy _externalActivityService;
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockDepartmentRepository = new Mock<IDepartmentRepository>();
|
||||
_externalActivityService = new NewMortgageActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task NewMortgageActivityStrategy_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]",
|
||||
MinorAccountType = "FE01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Mortgage);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewMortgageActivityStrategy_NoEmail_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "FE01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser) null);
|
||||
_mockUserService.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>())).ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Mortgage);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewMortgageActivityStrategy_NoUser_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "FE01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser) null);
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
});
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Mortgage);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Exactly(1));
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewMortgageActivityStrategy_NoDepartment_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]",
|
||||
MinorAccountType = "FE01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Mortgage);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewMortgageActivityStrategy_ExceptionReturnsBasic()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "FE01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ThrowsAsync(new Exception("OOPS"));
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ThrowsAsync(new Exception("OOPS"));
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Mortgage);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewMortgageActivityStrategy_FirstMortgageSale_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = null,
|
||||
AssociateLast = null,
|
||||
AssociateMiddleInit = null,
|
||||
EmployeeEmail = null,
|
||||
MinorAccountType = "MA01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = SystemAppUserConstants.FirstMortgageEmail,
|
||||
EmployeeId = "1234"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 39
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.FirstMortgageReferral);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(39, activity.DepartmentId);
|
||||
Assert.AreEqual("1234", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == SystemAppUserConstants.FirstMortgageEmail)), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "1234")), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
|
||||
namespace Application.UnitTests.Services.ExternalActivity
|
||||
{
|
||||
public class NewVehicleActivityStrategyTest
|
||||
{
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDepartmentRepository> _mockDepartmentRepository;
|
||||
private NewVehicleActivityStrategy _externalActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockDepartmentRepository = new Mock<IDepartmentRepository>();
|
||||
_externalActivityService = new NewVehicleActivityStrategy(_mockUserService.Object, _mockDepartmentRepository.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewVehicleActivityStrategy_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]",
|
||||
MinorAccountType = "DV01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Vehicle);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewVehicleActivityStrategy_NoEmail_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "DV01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser) null);
|
||||
_mockUserService.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>())).ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
}
|
||||
);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Vehicle);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(10, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewVehicleActivityStrategy_NoUser_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "DV01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser) null);
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>())).ReturnsAsync(
|
||||
new Department()
|
||||
{
|
||||
Id = 10
|
||||
});
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Vehicle);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Exactly(1));
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewVehicleActivityStrategy_NoDepartment_Ok()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
EmployeeEmail = "[email protected]",
|
||||
MinorAccountType = "DVO1"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "7624"
|
||||
});
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Vehicle);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual("7624", activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Once);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Never);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.Is<AppUser>(x => x.EmployeeId == "7624")), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NewVehicleActivityStrategy_ExceptionReturnsBasic()
|
||||
{
|
||||
var externalActivity = new NewLoanSaleActivity()
|
||||
{
|
||||
SubjectAccountNbr = 1,
|
||||
OriginatingPersonNbr = 1234,
|
||||
BranchOrgName = "West Bend-Main Branch",
|
||||
BranchOrgNbr = 400,
|
||||
TaxOrgNbr = "300",
|
||||
TaxPersonNbr = "200",
|
||||
CurrentAccountStatus = "Active",
|
||||
ActivityDateTime = DateTime.Parse("2021-09-10"),
|
||||
AssociateFirst = "John",
|
||||
AssociateLast = "Smith",
|
||||
AssociateMiddleInit = "B",
|
||||
MinorAccountType = "DV01"
|
||||
};
|
||||
|
||||
_mockUserService.Setup(x => x.GetUserByAdEmailAsync(It.IsAny<string>())).ThrowsAsync(new Exception("OOPS"));
|
||||
_mockUserService
|
||||
.Setup(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()))
|
||||
.ThrowsAsync(new Exception("OOPS"));
|
||||
_mockDepartmentRepository.Setup(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((Department)null);
|
||||
|
||||
var activity = await _externalActivityService.MapToActivityManagerActivity(externalActivity);
|
||||
Assert.True(activity.Product == Product.Vehicle);
|
||||
Assert.True(activity.Type == ActivityType.Sale);
|
||||
Assert.AreEqual(-1, activity.DepartmentId);
|
||||
Assert.AreEqual(null, activity.EmployeeId);
|
||||
|
||||
_mockUserService.Verify(x => x.GetUserByAdEmailAsync(It.Is<string>(x => x == "[email protected]")), Times.Never);
|
||||
_mockUserService.Verify(x => x.TryFindSingleUserByName(It.IsAny<UserNameSearchRequest>()), Times.Once);
|
||||
_mockDepartmentRepository.Verify(x => x.FindUserHomeDepartment(It.IsAny<AppUser>()), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class GapInsuranceActivityServiceTest
|
||||
{
|
||||
private GapInsuranceActivityService _gapInsuranceActivityService;
|
||||
private IActivityRepository _activityRepository;
|
||||
private IActivityDetailService _activityDetailService;
|
||||
private IActivityService _activityService;
|
||||
private IUnitOfWork _unitOfWork;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
|
||||
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
||||
|
||||
Mock.Get(mockCurrentUserService)
|
||||
.Setup(service => service.GetCurrentUser())
|
||||
.Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
});
|
||||
|
||||
var context = new ApplicationDbContext(options, mockCurrentUserService, new DateTimeService());
|
||||
_activityRepository = new ActivityRepository(context);
|
||||
_activityService = Mock.Of<IActivityService>();
|
||||
_activityDetailService = Mock.Of<IActivityDetailService>();
|
||||
Mock.Get(_activityDetailService).Setup(x => x.SaveActivityDetailUpdate(It.IsAny<ActivityDetailUpdate>())).ReturnsAsync(new ActivityDetailUpdate());
|
||||
Mock.Get(_activityService).Setup(x => x.ApplyStateChange(It.IsAny<ActivityStateChange>(), false)).ReturnsAsync(new Activity());
|
||||
_unitOfWork = new UnitOfWork(context);
|
||||
_gapInsuranceActivityService = new GapInsuranceActivityService(_activityDetailService, _activityRepository, _activityService, _unitOfWork);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ExpectedRegularMatch()
|
||||
{
|
||||
var accepted = DateTime.UtcNow.AddDays(-1);
|
||||
|
||||
var activities = new List<Activity>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Accepted = accepted,
|
||||
EmployeeId = CreateId(),
|
||||
Product = Product.Vehicle,
|
||||
SourceId = "12345",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
IsGapInsuranceEligible = true
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
Accepted = accepted,
|
||||
EmployeeId = CreateId(),
|
||||
Product = Product.GAPInsurance,
|
||||
SourceId = "8675309",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
IsGapInsuranceEligible = false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var parentActivityId = await _activityRepository.SaveActivityAsync(activities[0]);
|
||||
var accessoryActivityId = await _activityRepository.SaveActivityAsync(activities[1]);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var updated = await _gapInsuranceActivityService.MatchOrRemoveGapAccessories();
|
||||
Assert.AreEqual(2, updated);
|
||||
var updateAccessoryActivity = await _activityRepository.GetActivityById(accessoryActivityId);
|
||||
var updateParentActivity = await _activityRepository.GetActivityById(parentActivityId);
|
||||
|
||||
Assert.AreEqual(2, updated);
|
||||
Assert.AreEqual(updateAccessoryActivity.MatchingGapInsuranceActivityId, updateParentActivity.Id);
|
||||
Assert.AreEqual(updateParentActivity.MatchingGapInsuranceActivityId, updateAccessoryActivity.Id);
|
||||
Assert.IsNotNull(updateAccessoryActivity.Detail.GapInsuranceAddDate);
|
||||
Assert.IsNotNull(updateParentActivity.Detail.GapInsuranceAddDate);
|
||||
Assert.IsNull(updateAccessoryActivity.Detail.GapInsuranceRemoveDate);
|
||||
Assert.IsNull(updateParentActivity.Detail.GapInsuranceRemoveDate);
|
||||
}
|
||||
|
||||
[TestCase(ActivityState.ManualReview, ActivityState.Accepted)]
|
||||
[TestCase(ActivityState.Rejected, ActivityState.Accepted)]
|
||||
[TestCase(ActivityState.Transferred, ActivityState.Accepted)]
|
||||
[TestCase(ActivityState.Accepted, ActivityState.ManualReview)]
|
||||
[TestCase(ActivityState.Accepted, ActivityState.Rejected)]
|
||||
[TestCase(ActivityState.Accepted, ActivityState.Transferred)]
|
||||
public async Task RegularMatchRemovedWhenEitherActivityStateBecomesNotAccepted(ActivityState accessoryActivityState, ActivityState parentActivityState)
|
||||
{
|
||||
var accepted = DateTime.UtcNow.AddDays(-1);
|
||||
|
||||
var activities = new List<Activity>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Accepted = accepted,
|
||||
EmployeeId = CreateId(),
|
||||
MatchingGapInsuranceActivityId = 2,
|
||||
Product = Product.Vehicle,
|
||||
SourceId = "Parent",
|
||||
State = parentActivityState,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
IsGapInsuranceEligible = true,
|
||||
GapInsuranceAddDate = accepted
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
Accepted = accepted,
|
||||
EmployeeId = CreateId(),
|
||||
MatchingGapInsuranceActivityId = 1,
|
||||
Product = Product.GAPInsurance,
|
||||
SourceId = "Accessory",
|
||||
State = accessoryActivityState,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
IsGapInsuranceEligible = false,
|
||||
GapInsuranceAddDate = accepted
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var parentActivityId = await _activityRepository.SaveActivityAsync(activities[0]);
|
||||
var accessoryActivityId = await _activityRepository.SaveActivityAsync(activities[1]);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var updated = await _gapInsuranceActivityService.MatchOrRemoveGapAccessories();
|
||||
|
||||
var removedAccessoryActivity = await _activityRepository.GetActivityById(accessoryActivityId);
|
||||
var removedParentActivity = await _activityRepository.GetActivityById(parentActivityId);
|
||||
|
||||
Assert.IsNotNull(removedAccessoryActivity.Detail.GapInsuranceRemoveDate);
|
||||
Assert.IsNotNull(removedParentActivity.Detail.GapInsuranceRemoveDate);
|
||||
|
||||
Assert.AreEqual(removedAccessoryActivity.MatchingGapInsuranceActivityId, 0);
|
||||
Assert.AreEqual(removedParentActivity.MatchingGapInsuranceActivityId, 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RegularMatchRemovedWhenMatchedActivityCantBeFound()
|
||||
{
|
||||
var accepted = DateTime.UtcNow.AddDays(-1);
|
||||
|
||||
var activities = new List<Activity>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Accepted = accepted,
|
||||
EmployeeId = CreateId(),
|
||||
MatchingGapInsuranceActivityId = 2,
|
||||
Product = Product.Vehicle,
|
||||
SourceId = "Parent",
|
||||
State = ActivityState.Accepted,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
AccountNumber = "12345",
|
||||
IsGapInsuranceEligible = true,
|
||||
GapInsuranceAddDate = accepted
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var parentActivityId = await _activityRepository.SaveActivityAsync(activities[0]);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
var updated = await _gapInsuranceActivityService.MatchOrRemoveGapAccessories();
|
||||
|
||||
var removedParentActivity = await _activityRepository.GetActivityById(parentActivityId);
|
||||
|
||||
Assert.IsNotNull(removedParentActivity.Detail.GapInsuranceRemoveDate);
|
||||
Assert.AreEqual(removedParentActivity.MatchingGapInsuranceActivityId, 0);
|
||||
}
|
||||
|
||||
private static string CreateId() => Guid.NewGuid().ToString("D");
|
||||
}
|
||||
}
|
||||
+730
@@ -0,0 +1,730 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.DispersalStrategy;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.GoalDispersal;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Extensions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class GoalDispersalServiceTest
|
||||
{
|
||||
private Mock<IGoalService> _mockGoalService;
|
||||
private Mock<IDepartmentRepository> _mockDepartmentRepository;
|
||||
private Mock<INotificationApiService> _mockNotificationService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IGoalChangeRepository> _mockGoalChangeRepository;
|
||||
private Mock<IDispersalStrategyService> _mockDispersalStrategyService;
|
||||
private IGoalDispersalService _goalDispersalService;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockGoalService = new Mock<IGoalService>();
|
||||
_mockGoalChangeRepository = new Mock<IGoalChangeRepository>();
|
||||
_mockDepartmentRepository = new Mock<IDepartmentRepository>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockDispersalStrategyService = new Mock<IDispersalStrategyService>();
|
||||
_mockNotificationService = new Mock<INotificationApiService>();
|
||||
_goalDispersalService = new GoalDispersalService(_mockUserService.Object, _mockGoalService.Object,
|
||||
_mockDepartmentRepository.Object, _mockNotificationService.Object,
|
||||
_mockDispersalStrategyService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DisperseGoalsByExtrapolatingLastMonth_OK()
|
||||
{
|
||||
var goalList = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.Mortgage,
|
||||
Value = 200,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.Vehicle,
|
||||
Value = 0,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.CheckCard,
|
||||
Value = 0,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.DirectDeposit,
|
||||
Value = 35,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
}
|
||||
};
|
||||
|
||||
var departmentGoal = new DepartmentGoals(10, 2021);
|
||||
departmentGoal.ApplyAll(goalList);
|
||||
|
||||
var personnelGoals = new PersonnelGoals(10, 2021, 1, new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
PersonId = 5,
|
||||
EmployeeId = "5E",
|
||||
AdditionalPermissions = new List<UserPermission>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10
|
||||
}
|
||||
},
|
||||
Role = Role.BM
|
||||
}
|
||||
});
|
||||
personnelGoals.ApplyAll(goalList.Select(x =>
|
||||
{
|
||||
x.EmployeeId = "5E";
|
||||
return x;
|
||||
}).ToList());
|
||||
|
||||
|
||||
_mockGoalService.Setup(x => x.GetAnnualDepartmentGoalsAsync(It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(departmentGoal);
|
||||
_mockGoalService.Setup(x => x.GetMonthlyPersonnelGoalsAsync(It.IsAny<DepartmentPersonnelSearchRequest>()))
|
||||
.ReturnsAsync(personnelGoals);
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateFromExistingGoals(It.IsAny<ExtrapolationGoalDispersalData>()))
|
||||
.Returns(new GoalDispersalReceipt(10, GoalDispersalStrategy.ExtrapolateFromExistingGoals));
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.DefaultWeightedDispersal(It.IsAny<DefaultWeightedGoalDispersalData>()))
|
||||
.Returns(new GoalDispersalReceipt(10, GoalDispersalStrategy.DefaultDisperseWithWeights));
|
||||
|
||||
var results = await _goalDispersalService.DisperseGoalsByExtrapolatingLastMonth(10, 1, 2020);
|
||||
Assert.AreEqual(GoalDispersalStrategy.ExtrapolateFromExistingGoals, results.Strategy);
|
||||
_mockDispersalStrategyService.Verify(x => x.ExtrapolateFromExistingGoals(It.IsAny<ExtrapolationGoalDispersalData>()), Times.Once);
|
||||
_mockGoalService.Verify(x => x.SaveGoalRangeAsync(It.IsAny<List<GoalChange>>()), Times.Once);
|
||||
|
||||
}
|
||||
|
||||
[TestCase(1, 2021, 12, 2020)]
|
||||
[TestCase(2, 2021, 1, 2021)]
|
||||
[TestCase(3, 2021, 2, 2021)]
|
||||
[TestCase(4, 2021, 3, 2021)]
|
||||
[TestCase(5, 2021, 4, 2021)]
|
||||
[TestCase(6, 2021, 5, 2021)]
|
||||
[TestCase(7, 2021, 6, 2021)]
|
||||
[TestCase(8, 2021, 7, 2021)]
|
||||
[TestCase(9, 2021, 8, 2021)]
|
||||
[TestCase(10, 2021, 9, 2021)]
|
||||
[TestCase(11, 2021, 10, 2021)]
|
||||
[TestCase(12, 2021, 11, 2021)]
|
||||
public async Task DisperseGoalsByExtrapolatingLastMonth_Calculates_Year_Month_OK(int month, int year, int lastMonth, int lastMonthYear)
|
||||
{
|
||||
var goalList = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.Mortgage,
|
||||
Value = 200,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
}
|
||||
};
|
||||
|
||||
var departmentGoal = new DepartmentGoals(10, 2021);
|
||||
departmentGoal.ApplyAll(goalList);
|
||||
|
||||
var personnelGoals = new PersonnelGoals(10, 2021, 1, new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
PersonId = 5,
|
||||
EmployeeId = "5E",
|
||||
AdditionalPermissions = new List<UserPermission>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10
|
||||
}
|
||||
},
|
||||
Role = Role.BM
|
||||
}
|
||||
});
|
||||
personnelGoals.ApplyAll(goalList.Select(x =>
|
||||
{
|
||||
x.EmployeeId = "5E";
|
||||
return x;
|
||||
}).ToList());
|
||||
|
||||
// The goals and personnel don't really matter for testing we just need some values
|
||||
_mockGoalService.Setup(x => x.GetAnnualDepartmentGoalsAsync(It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(departmentGoal);
|
||||
_mockGoalService.Setup(x => x.GetMonthlyPersonnelGoalsAsync(It.IsAny<DepartmentPersonnelSearchRequest>()))
|
||||
.ReturnsAsync(personnelGoals);
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateFromExistingGoals(It.IsAny<ExtrapolationGoalDispersalData>()))
|
||||
.Returns(new GoalDispersalReceipt(10, GoalDispersalStrategy.ExtrapolateFromExistingGoals));
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.DefaultWeightedDispersal(It.IsAny<DefaultWeightedGoalDispersalData>()))
|
||||
.Returns(new GoalDispersalReceipt(10, GoalDispersalStrategy.DefaultDisperseWithWeights));
|
||||
|
||||
var results = await _goalDispersalService.DisperseGoalsByExtrapolatingLastMonth(10, month, year);
|
||||
Assert.NotNull(results);
|
||||
_mockGoalService.Verify(
|
||||
x => x.GetMonthlyPersonnelGoalsAsync(
|
||||
It.Is<DepartmentPersonnelSearchRequest>(x => x.Month == month && x.Year == year)), Times.Once());
|
||||
_mockGoalService.Verify(
|
||||
x => x.GetMonthlyPersonnelGoalsAsync(
|
||||
It.Is<DepartmentPersonnelSearchRequest>(x => x.Month == lastMonth && x.Year == lastMonthYear)),
|
||||
Times.Once());
|
||||
_mockGoalService.Verify(
|
||||
X => X.GetAnnualDepartmentGoalsAsync(It.Is<int>(x => x == 10), It.Is<int>(x => x == year)), Times.AtLeastOnce);
|
||||
_mockGoalService.Verify(
|
||||
X => X.GetAnnualDepartmentGoalsAsync(It.Is<int>(x => x == 10), It.Is<int>(x => x == lastMonthYear)),
|
||||
Times.AtLeastOnce);
|
||||
_mockGoalService.Verify(x => x.SaveGoalRangeAsync(It.IsAny<List<GoalChange>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DisperseGoalsByExtrapolatingLastMonth_Defaults_OK()
|
||||
{
|
||||
var goalList = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.Mortgage,
|
||||
Value = 0,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.Vehicle,
|
||||
Value = 0,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.CheckCard,
|
||||
Value = 0,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.DirectDeposit,
|
||||
Value = 0,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
}
|
||||
};
|
||||
|
||||
var departmentGoal = new DepartmentGoals(10, 2021);
|
||||
departmentGoal.ApplyAll(goalList);
|
||||
|
||||
var personnelGoals = new PersonnelGoals(10, 2021, 1, new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
PersonId = 5,
|
||||
EmployeeId = "5E",
|
||||
AdditionalPermissions = new List<UserPermission>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10
|
||||
}
|
||||
},
|
||||
Role = Role.BM
|
||||
}
|
||||
});
|
||||
personnelGoals.ApplyAll(goalList.Select(x =>
|
||||
{
|
||||
x.EmployeeId = "5E";
|
||||
return x;
|
||||
}).ToList());
|
||||
|
||||
// The goals and personnel don't really matter for testing we just need some values
|
||||
_mockGoalService.Setup(x => x.GetAnnualDepartmentGoalsAsync(It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(departmentGoal);
|
||||
_mockGoalService.Setup(x => x.GetMonthlyPersonnelGoalsAsync(It.IsAny<DepartmentPersonnelSearchRequest>()))
|
||||
.ReturnsAsync(personnelGoals);
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateFromExistingGoals(It.IsAny<ExtrapolationGoalDispersalData>()))
|
||||
.Returns(new GoalDispersalReceipt(10, GoalDispersalStrategy.ExtrapolateFromExistingGoals));
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.DefaultWeightedDispersal(It.IsAny<DefaultWeightedGoalDispersalData>()))
|
||||
.Returns(new GoalDispersalReceipt(10, GoalDispersalStrategy.DefaultDisperseWithWeights));
|
||||
|
||||
var results = await _goalDispersalService.DisperseGoalsByExtrapolatingLastMonth(10, 1, 2020);
|
||||
Assert.AreEqual(GoalDispersalStrategy.DefaultDisperseWithWeights, results.Strategy);
|
||||
_mockDispersalStrategyService.Verify(x => x.DefaultWeightedDispersal(It.IsAny<DefaultWeightedGoalDispersalData>()), Times.Once);
|
||||
_mockGoalService.Verify(x => x.SaveGoalRangeAsync(It.IsAny<List<GoalChange>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DisperseAllDepartmentGoalsForMonth_OK()
|
||||
{
|
||||
var goalList = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Product = Product.Mortgage,
|
||||
Value = 200,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
}
|
||||
};
|
||||
|
||||
var departmentGoal = new DepartmentGoals(10, 2021);
|
||||
departmentGoal.ApplyAll(goalList);
|
||||
|
||||
var personnelGoals = new PersonnelGoals(10, 2021, 1, new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
PersonId = 5,
|
||||
EmployeeId = "5E",
|
||||
AdditionalPermissions = new List<UserPermission>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10
|
||||
}
|
||||
},
|
||||
Role = Role.BM
|
||||
}
|
||||
});
|
||||
personnelGoals.ApplyAll(goalList.Select(x =>
|
||||
{
|
||||
x.EmployeeId = "5E";
|
||||
return x;
|
||||
}).ToList());
|
||||
|
||||
|
||||
// The goals and personnel don't really matter for testing we just need some values
|
||||
_mockGoalService.Setup(x => x.GetAnnualDepartmentGoalsAsync(It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(departmentGoal);
|
||||
_mockGoalService.Setup(x => x.GetMonthlyPersonnelGoalsAsync(It.IsAny<DepartmentPersonnelSearchRequest>()))
|
||||
.ReturnsAsync(personnelGoals);
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateFromExistingGoals(It.Is<ExtrapolationGoalDispersalData>(x => x.DepartmentId == 0)))
|
||||
.Returns(new GoalDispersalReceipt(0, GoalDispersalStrategy.ExtrapolateFromExistingGoals));
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateFromExistingGoals(It.Is<ExtrapolationGoalDispersalData>(x => x.DepartmentId == 1)))
|
||||
.Returns(new GoalDispersalReceipt(1, GoalDispersalStrategy.DefaultDisperseWithWeights));
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateFromExistingGoals(It.Is<ExtrapolationGoalDispersalData>(x => x.DepartmentId == 2)))
|
||||
.Returns(new GoalDispersalReceipt(2, GoalDispersalStrategy.ExtrapolateFromExistingGoals));
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateFromExistingGoals(
|
||||
It.Is<ExtrapolationGoalDispersalData>(x => x.DepartmentId == 3)))
|
||||
.Throws(new Exception("Ooops"));
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.GetAllDepartmentsAsync()).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
Id = 0,
|
||||
DepartmentName = "Name0"
|
||||
},
|
||||
new Department()
|
||||
{
|
||||
Id = 1,
|
||||
DepartmentName = "Name1"
|
||||
},
|
||||
new Department()
|
||||
{
|
||||
Id = 2,
|
||||
},
|
||||
new Department()
|
||||
{
|
||||
Id = 3,
|
||||
DepartmentName = "Name3"
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
var results = await _goalDispersalService.DisperseAllDepartmentGoalsForMonth(1, 2020);
|
||||
Assert.Contains("0 - Name0",results.Keys);
|
||||
Assert.Contains("1 - Name1", results.Keys);
|
||||
Assert.Contains("2 - ", results.Keys);
|
||||
Assert.Contains("3 - Name3", results.Keys);
|
||||
|
||||
Assert.NotNull(results["0 - Name0"]);
|
||||
Assert.NotNull(results["1 - Name1"]);
|
||||
Assert.NotNull(results["2 - "]);
|
||||
Assert.Null(results["3 - Name3"]);
|
||||
|
||||
Assert.AreEqual(GoalDispersalStrategy.ExtrapolateFromExistingGoals, results["0 - Name0"].Strategy);
|
||||
Assert.AreEqual(GoalDispersalStrategy.DefaultDisperseWithWeights,results["1 - Name1"].Strategy);
|
||||
Assert.AreEqual(GoalDispersalStrategy.ExtrapolateFromExistingGoals,results["2 - "].Strategy);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CustomWeightedDispersal_OK()
|
||||
{
|
||||
var customWeightedDispersalRequest = new CustomWeightedDispersalRequest()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
month = 01,
|
||||
year = 2021,
|
||||
DispersalProduct = Product.Mortgage,
|
||||
DispersalWeightByRole = new Dictionary<string, double>(){ { "BM", .10 }, {"PFO", .25} }
|
||||
};
|
||||
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "ABM1",
|
||||
PersonId = 1,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Role = Role.ABM
|
||||
}
|
||||
}
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "BM1",
|
||||
PersonId = 2,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Role = Role.BM
|
||||
}
|
||||
}
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "BM2",
|
||||
PersonId = 3,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Role = Role.BM
|
||||
}
|
||||
}
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "PFO1",
|
||||
PersonId = 4,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Role = Role.PFO
|
||||
}
|
||||
}
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "PFO2",
|
||||
PersonId = 5,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Role = Role.PFO
|
||||
}
|
||||
}
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "PFO3",
|
||||
PersonId = 6,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10,
|
||||
Role = Role.PFO
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var deptGoals = new DepartmentGoals(10, 2021);
|
||||
deptGoals.ApplyAll(new List<Goal>()
|
||||
{
|
||||
new Goal(){
|
||||
DepartmentId = 10,
|
||||
Product = Product.Mortgage,
|
||||
Value = 200,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-1").EndOfMonth()
|
||||
}
|
||||
});
|
||||
|
||||
_mockGoalService.Setup(x => x.GetAnnualDepartmentGoalsAsync(It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(deptGoals);
|
||||
|
||||
_mockUserService.Setup(x => x.FindDepartmentAssignments(It.IsAny<DepartmentPersonnelSearchRequest>()))
|
||||
.ReturnsAsync(users);
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.CustomWeightedDispersal(It.IsAny<CustomWeightedDispersalRequest>(),
|
||||
It.IsAny<List<AppUser>>(), It.IsAny<int>()))
|
||||
.Returns(new GoalDispersalReceipt(10, GoalDispersalStrategy.CustomWeightedDispersal));
|
||||
|
||||
var receipt = await _goalDispersalService.CustomWeightedDispersal(customWeightedDispersalRequest);
|
||||
Assert.AreEqual(10, receipt.DepartmentId);
|
||||
Assert.AreEqual(GoalDispersalStrategy.CustomWeightedDispersal, receipt.Strategy);
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Verify(x => x.CustomWeightedDispersal(
|
||||
It.Is<CustomWeightedDispersalRequest>(x => x.Equals(customWeightedDispersalRequest)),
|
||||
It.Is<List<AppUser>>(x => x.Count == 6), It.Is<int>(x => x == 200)));
|
||||
|
||||
_mockGoalService.Verify(x =>
|
||||
x.GetAnnualDepartmentGoalsAsync(It.Is<int>(x => x == 10), It.Is<int>(x => x == 2021)));
|
||||
|
||||
_mockUserService.Verify(x => x.FindDepartmentAssignments(It.Is<DepartmentPersonnelSearchRequest>(x =>
|
||||
x.Month == 1 && x.Year == 2021 && x.IncludeAllPersonnel == true && x.DepartmentId == 10)));
|
||||
|
||||
_mockGoalService.Verify(x => x.SaveGoalRangeAsync(It.IsAny<List<GoalChange>>()), Times.Once);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ExecuteMonthStartDispersal_OK()
|
||||
{
|
||||
var request = new GoalDispersalRequest()
|
||||
{
|
||||
MonthsBack = 0,
|
||||
GoalDispersalNotification = new List<string> { "[email protected]", "[email protected]" }
|
||||
};
|
||||
|
||||
_mockDepartmentRepository.Setup(x => x.GetAllDepartmentsAsync()).ReturnsAsync(new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
Id = 0,
|
||||
DepartmentName = "Department0"
|
||||
},
|
||||
new Department()
|
||||
{
|
||||
Id = 10,
|
||||
Assignments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Id = 100,
|
||||
AppUserId = new Guid("00000000-1111-1111-0000-000000000000"),
|
||||
DepartmentId = 10
|
||||
}
|
||||
},
|
||||
DepartmentName = "Department10"
|
||||
},
|
||||
new Department()
|
||||
{
|
||||
Id = 2,
|
||||
Assignments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Id = 22,
|
||||
AppUserId = new Guid("00000000-2222-0000-0000-000000000000"),
|
||||
DepartmentId = 2
|
||||
}
|
||||
},
|
||||
DepartmentName = "Department2"
|
||||
},
|
||||
new Department()
|
||||
{
|
||||
Id = 3,
|
||||
Assignments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Id = 33,
|
||||
AppUserId = new Guid("00000000-3333-0000-0000-000000000000"),
|
||||
DepartmentId = 3
|
||||
}
|
||||
},
|
||||
DepartmentName = "Department3"
|
||||
},
|
||||
});
|
||||
|
||||
var goalUpdate = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 10,
|
||||
Value = 300,
|
||||
StartDate = DateTime.Parse("2021-01-01T20:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-01-31T23:59:00.000")
|
||||
};
|
||||
|
||||
var goal2Update = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 10,
|
||||
Value = 301,
|
||||
StartDate = DateTime.Parse("2021-01-01T10:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-01-31T21:59:00.000")
|
||||
};
|
||||
|
||||
var goal3Update = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 10,
|
||||
Value = 302,
|
||||
StartDate = DateTime.Parse("2021-01-01T11:30:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-01-31T03:59:00.000")
|
||||
};
|
||||
|
||||
var goalChangeList = new List<GoalChange>() { goalUpdate, goal2Update, goal3Update };
|
||||
|
||||
var goal1 = new Goal()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 10,
|
||||
Value = 303,
|
||||
StartDate = DateTime.Parse("2021-01-01T11:30:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-01-31T03:59:00.000")
|
||||
};
|
||||
|
||||
var goalDeptList = new List<Goal>() { goal1 };
|
||||
|
||||
_mockGoalService.Setup(x => x.SaveGoalRangeAsync(goalChangeList)).ReturnsAsync(goalDeptList);
|
||||
|
||||
var deptGoals = new DepartmentGoals(10, 2021);
|
||||
|
||||
deptGoals.ApplyAll(new List<Goal>()
|
||||
{
|
||||
new Goal(){
|
||||
DepartmentId = 10,
|
||||
Product = Product.Mortgage,
|
||||
Value = 299,
|
||||
StartDate = DateTime.Parse("2021-1-1"),
|
||||
EndDate = DateTime.Parse("2021-1-31").EndOfMonth()
|
||||
},
|
||||
new Goal(){
|
||||
DepartmentId = 10,
|
||||
Product = Product.Mortgage,
|
||||
Value = 500,
|
||||
StartDate = DateTime.Parse("2021-2-1"),
|
||||
EndDate = DateTime.Parse("2021-2-28").EndOfMonth()
|
||||
}
|
||||
});
|
||||
|
||||
_mockGoalService.Setup(x => x.GetAnnualDepartmentGoalsAsync(It.IsAny<int>(), It.IsAny<int>())).ReturnsAsync(deptGoals);
|
||||
|
||||
var personnelGoals = new PersonnelGoals(10, 2021, 1, new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
PersonId = 5,
|
||||
Id = new Guid("00000000-1111-1111-0000-000000000000"),
|
||||
EmployeeId = "11111",
|
||||
AdditionalPermissions = new List<UserPermission>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10
|
||||
}
|
||||
},
|
||||
Role = Role.BM
|
||||
},
|
||||
|
||||
new AppUser()
|
||||
{
|
||||
PersonId = 7,
|
||||
Id = new Guid("00000000-7777-7777-0000-000000000000"),
|
||||
EmployeeId = "77777",
|
||||
AdditionalPermissions = new List<UserPermission>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 10
|
||||
}
|
||||
},
|
||||
Role = Role.Teller
|
||||
}
|
||||
});
|
||||
|
||||
personnelGoals.ApplyAll(goalDeptList.Select(x =>
|
||||
{
|
||||
x.EmployeeId = "11111";
|
||||
return x;
|
||||
|
||||
}).ToList());
|
||||
|
||||
_mockGoalService.Setup(x => x.GetMonthlyPersonnelGoalsAsync(It.IsAny<DepartmentPersonnelSearchRequest>())).ReturnsAsync(personnelGoals);
|
||||
|
||||
var receipt = new GoalDispersalReceipt(10, GoalDispersalStrategy.ExtrapolateFromExistingGoals)
|
||||
{
|
||||
GoalChanges = goalChangeList,
|
||||
Strategy = GoalDispersalStrategy.ExtrapolateFromExistingGoals,
|
||||
DepartmentId = 10,
|
||||
GoalDispersalErrors = new List<GoalDispersalReceiptItem>()
|
||||
{
|
||||
new GoalDispersalReceiptItem(GoalDispersalError.NewUserRequiresManualEntry, "77777", "New user required manual entry.")
|
||||
{
|
||||
EmployeeId = "77777",
|
||||
ErrorType = GoalDispersalError.NewUserRequiresManualEntry
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
_mockDispersalStrategyService.Setup(x => x.ExtrapolateFromExistingGoals(It.IsAny<ExtrapolationGoalDispersalData>())).Returns(receipt);
|
||||
|
||||
var results = await _goalDispersalService.DisperseAllDepartmentGoalsForMonth(2, 2021);
|
||||
await _goalDispersalService.ExecuteMonthStartDispersal(request);
|
||||
|
||||
_mockNotificationService.Verify(mock => mock.SendMonthStartGoalDispersalReceipt(results, request.GoalDispersalNotification), Times.Once);
|
||||
|
||||
Assert.NotNull(results["0 - Department0"]);
|
||||
Assert.NotNull(results["10 - Department10"]);
|
||||
Assert.AreEqual(3, results["10 - Department10"].GoalChanges.Count());
|
||||
Assert.AreEqual(1, results["10 - Department10"].GoalDispersalErrors.Count());
|
||||
Assert.NotNull(results["2 - Department2"]);
|
||||
Assert.NotNull(results["3 - Department3"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+736
@@ -0,0 +1,736 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Extensions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.DispersalStrategy;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.GoalDispersal;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class GoalServiceRepositoryTest
|
||||
{
|
||||
private GoalService _goalService;
|
||||
private IGoalRepository _goalRepository;
|
||||
private IGoalChangeRepository _goalChangeRepository;
|
||||
private ICurrentUserService _currentUserService;
|
||||
private Mock<IDispersalStrategyService> _mockDispersalStrategyService;
|
||||
private IUserService _userService;
|
||||
private IDepartmentRepository _departmentRepository;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var mockDateTime = new DateTimeService();
|
||||
_currentUserService = Mock.Of<ICurrentUserService>();
|
||||
_userService = Mock.Of<IUserService>();
|
||||
|
||||
Mock.Get(_currentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]"
|
||||
});
|
||||
Mock.Get(_userService).Setup(x => x.GetUserByEmployeeIdAsync(It.IsAny<string>())).ReturnsAsync(new AppUser { Id = Guid.NewGuid() });
|
||||
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging(true)
|
||||
.Options;
|
||||
var context = new ApplicationDbContext(options, _currentUserService, mockDateTime);
|
||||
_goalRepository = new GoalRepository(context);
|
||||
_goalChangeRepository = new GoalChangeRepository(context);
|
||||
_mockDispersalStrategyService = new Mock<IDispersalStrategyService>();
|
||||
_departmentRepository = Mock.Of<IDepartmentRepository>();
|
||||
|
||||
_goalService = new GoalService(_goalRepository, _goalChangeRepository, _currentUserService, _mockDispersalStrategyService.Object,
|
||||
new UnitOfWork(context), _userService, _departmentRepository);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Save_And_Get_Goal()
|
||||
{
|
||||
var saved = await _goalService.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var goal = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00002",
|
||||
Value = 99,
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
var result = await _goalService.SaveGoalAsync(goal);
|
||||
Assert.NotNull(result);
|
||||
|
||||
saved = await _goalService.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Save_And_Get_Goal_Strips_Timestamp_Preserves_Kind()
|
||||
{
|
||||
var saved = await _goalService.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var goal = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00002",
|
||||
Value = 99,
|
||||
StartDate = DateTime.SpecifyKind(DateTime.Parse("2021-07-01T10:37:00.000"), DateTimeKind.Local),
|
||||
EndDate = DateTime.SpecifyKind(DateTime.Parse("2021-07-31T22:04:30.000"), DateTimeKind.Utc)
|
||||
};
|
||||
var result = await _goalService.SaveGoalAsync(goal);
|
||||
Assert.NotNull(result);
|
||||
|
||||
saved = await _goalService.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsNotEmpty(saved);
|
||||
Assert.AreEqual(DateTime.Parse("2021-07-01T00:00:00.000"), saved.First().StartDate);
|
||||
Assert.AreEqual(DateTime.Parse("2021-07-31T23:59:59.000"), saved.First().EndDate);
|
||||
Assert.AreEqual(goal.StartDate.Kind, saved.First().StartDate.Kind);
|
||||
Assert.AreEqual(goal.EndDate.Kind, saved.First().EndDate.Kind);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDeptGoalsForRange()
|
||||
{
|
||||
var goal = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 55,
|
||||
Value = 98,
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
|
||||
await _goalService.SaveGoalAsync(goal);
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 11771,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 55,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var range = new MonthRange(2021, 7, 2021, 8);
|
||||
var found = await _goalService.GetEmployeeDepartmentsGoalsForMonthRangeAsync(user, range);
|
||||
Assert.NotNull(found);
|
||||
Assert.IsNotEmpty(found.First().Goals.ProductGoals);
|
||||
Assert.IsNotEmpty(found.First().GoalAudit);
|
||||
Assert.AreEqual(1, found.First().GoalAudit.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDeptGoalsForRange_NoAssignmentInMonthRange_ReturnsEmpty()
|
||||
{
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.Admin,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 11771,
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 55,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
},
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-08-01T00:00:00.000")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var range = new MonthRange(2021, 5, 2021, 6);
|
||||
var found = await _goalService.GetEmployeeDepartmentsGoalsForMonthRangeAsync(user, range);
|
||||
Assert.IsEmpty(found);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveGoalRange_FirstDepartmentChanges_OK()
|
||||
{
|
||||
//Stub this so there is no exception, extrapolate generates no new Goals
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(It.IsAny<DepartmentGoalExtrapolationRequest>(), It.IsAny<PersonnelGoals>()))
|
||||
.Returns(new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct));
|
||||
|
||||
Mock.Get(_userService).Setup(x => x.FindDepartmentAssignments(It.IsAny<DepartmentPersonnelSearchRequest>()))
|
||||
.ReturnsAsync(new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "C4000"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "C5000"
|
||||
}
|
||||
});
|
||||
|
||||
var saved = await _goalService.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var goal = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
Value = 98,
|
||||
StartDate = DateTime.Parse("2021-07-01T20:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
var goal2 = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
Value = 99,
|
||||
StartDate = DateTime.Parse("2021-08-01T10:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-08-31T21:59:00.000")
|
||||
};
|
||||
var goal3 = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
Value = 100,
|
||||
StartDate = DateTime.Parse("2020-09-01T11:30:00.000"),
|
||||
EndDate = DateTime.Parse("2020-09-30T03:59:00.000")
|
||||
};
|
||||
var goalDiffDept = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 2,
|
||||
Value = 101,
|
||||
StartDate = DateTime.Parse("2021-09-01T12:30:00.000"),
|
||||
EndDate = DateTime.Parse("2021-09-30T20:59:00.000")
|
||||
};
|
||||
var goalPersonnel = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00002",
|
||||
Value = 102,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000"),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
};
|
||||
var result = await _goalService.SaveGoalRangeAsync(new List<GoalChange>()
|
||||
{
|
||||
goal, goal2, goal3, goalDiffDept, goalPersonnel
|
||||
});
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(5, result.Count);
|
||||
|
||||
//Only Re-disperse if goal was updated not added for the first time
|
||||
_mockDispersalStrategyService
|
||||
.Verify(x => x.ExtrapolateSingleDepartmentProduct(It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 1), It.IsAny<PersonnelGoals>()), Times.Exactly(0));
|
||||
|
||||
|
||||
Assert.True(result.TrueForAll(x => x.StartDate.TimeOfDay.ToString().Equals("00:00:00")));
|
||||
Assert.True(result.TrueForAll(x => x.EndDate.TimeOfDay.ToString().Equals("23:59:59")));
|
||||
|
||||
var startDate = goal.StartDate;
|
||||
|
||||
var goals = await _goalService.GetAnnualDepartmentGoalsAsync(goal.DepartmentId, startDate.Year);
|
||||
Assert.NotNull(goals);
|
||||
var checkCardGoals = goals.MonthlyGoals[goal.StartDate.Month - 1].ProductGoals[Product.CheckCard];
|
||||
Assert.AreEqual(goal.Value, checkCardGoals);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveGoalRange_ReDisperseDepartmentGoals_OK()
|
||||
{
|
||||
var julyGoalDispersalReceipt =
|
||||
new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct);
|
||||
|
||||
Mock.Get(_userService).Setup(x => x.FindDepartmentAssignments(It.IsAny<DepartmentPersonnelSearchRequest>())).ReturnsAsync(
|
||||
new List<AppUser>(){
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "C00002"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "C00003"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "C00004"
|
||||
}
|
||||
});
|
||||
julyGoalDispersalReceipt.GoalChanges = new List<GoalChange>()
|
||||
{
|
||||
new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00002",
|
||||
Value = 110,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
},
|
||||
new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00003",
|
||||
Value = 111,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
},
|
||||
new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00004",
|
||||
Value = 112,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
}
|
||||
};
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(It.Is<DepartmentGoalExtrapolationRequest>(request => request.DepartmentId == 1 && request.DepartmentGoalStartDate.Month == 7), It.IsAny<PersonnelGoals>()))
|
||||
.Returns(julyGoalDispersalReceipt);
|
||||
|
||||
//For August
|
||||
var augGoalDispersalReceipt =
|
||||
new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct);
|
||||
augGoalDispersalReceipt.GoalChanges = julyGoalDispersalReceipt.GoalChanges.Select(x => new GoalChange()
|
||||
{
|
||||
Product = x.Product,
|
||||
DepartmentId = x.DepartmentId,
|
||||
PersonId = x.PersonId,
|
||||
Value = x.Value * 2,
|
||||
StartDate = DateTime.Parse("2021-08-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-08-31T20:59:00.000")
|
||||
}).ToList();
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 1 && x.DepartmentGoalStartDate.Month == 8), It.IsAny<PersonnelGoals>()))
|
||||
.Returns(augGoalDispersalReceipt);
|
||||
|
||||
//For September
|
||||
var sepGoalDispersalReceipt =
|
||||
new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct);
|
||||
sepGoalDispersalReceipt.GoalChanges = julyGoalDispersalReceipt.GoalChanges.Select(x => new GoalChange()
|
||||
{
|
||||
Product = x.Product,
|
||||
DepartmentId = x.DepartmentId,
|
||||
PersonId = x.PersonId,
|
||||
Value = x.Value * 3,
|
||||
StartDate = DateTime.Parse("2021-09-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-09-30T20:59:00.000")
|
||||
}).ToList();
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 1 && x.DepartmentGoalStartDate.Month == 9), It.IsAny<PersonnelGoals>()))
|
||||
.Returns(sepGoalDispersalReceipt);
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 2), It.IsAny<PersonnelGoals>()))
|
||||
.Returns(new GoalDispersalReceipt(2, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct));
|
||||
|
||||
var saved = await _goalService.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var goal = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 98,
|
||||
StartDate = DateTime.Parse("2021-07-01T20:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
var goal2 = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 99,
|
||||
StartDate = DateTime.Parse("2021-08-01T10:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-08-31T21:59:00.000")
|
||||
};
|
||||
var goal3 = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 100,
|
||||
StartDate = DateTime.Parse("2021-09-01T11:30:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-09-30T03:59:00.000")
|
||||
};
|
||||
var goalDiffDept = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 2,
|
||||
Value = 101,
|
||||
StartDate = DateTime.Parse("2021-09-01T12:30:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-09-30T20:59:00.000")
|
||||
};
|
||||
var goalPersonnel = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00002",
|
||||
Value = 102,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
};
|
||||
var result = await _goalService.SaveGoalRangeAsync(new List<GoalChange>()
|
||||
{
|
||||
goal, goal2, goal3, goalDiffDept, goalPersonnel
|
||||
});
|
||||
|
||||
var goalUpdate = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 300,
|
||||
StartDate = DateTime.Parse("2021-07-01T20:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
var goal2Update = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 301,
|
||||
StartDate = DateTime.Parse("2021-08-01T10:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-08-31T21:59:00.000")
|
||||
};
|
||||
var goal3Update = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 302,
|
||||
StartDate = DateTime.Parse("2021-09-01T11:30:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-09-30T03:59:00.000")
|
||||
};
|
||||
|
||||
var resultRedispersal = await _goalService.SaveGoalRangeAsync(new List<GoalChange>()
|
||||
{
|
||||
goalUpdate, goal2Update, goal3Update
|
||||
});
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(5, result.Count);
|
||||
|
||||
Assert.NotNull(resultRedispersal);
|
||||
Assert.AreEqual(12, resultRedispersal.Count);
|
||||
|
||||
var goalChanges = await _goalChangeRepository.GetGoalChangesAsync();
|
||||
Assert.AreEqual(17, goalChanges.Count());
|
||||
Assert.True(result.TrueForAll(x => x.StartDate.TimeOfDay.ToString().Equals("00:00:00")));
|
||||
Assert.True(result.TrueForAll(x => x.EndDate.TimeOfDay.ToString().Equals("23:59:59")));
|
||||
|
||||
var startDate = goal.StartDate;
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Verify(x => x.ExtrapolateSingleDepartmentProduct(It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 1), It.IsAny<PersonnelGoals>()), Times.Exactly(3));
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Verify(x => x.ExtrapolateSingleDepartmentProduct(It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 2), It.IsAny<PersonnelGoals>()), Times.Exactly(0));
|
||||
|
||||
var goals = await _goalService.GetAnnualDepartmentGoalsAsync(1, 2021);
|
||||
Assert.NotNull(goals);
|
||||
|
||||
var mortgageGoals = goals.MonthlyGoals[6].ProductGoals[Product.Mortgage];
|
||||
Assert.AreEqual(300, mortgageGoals);
|
||||
|
||||
mortgageGoals = goals.MonthlyGoals[7].ProductGoals[Product.Mortgage];
|
||||
Assert.AreEqual(301, mortgageGoals);
|
||||
|
||||
mortgageGoals = goals.MonthlyGoals[8].ProductGoals[Product.Mortgage];
|
||||
Assert.AreEqual(302, mortgageGoals);
|
||||
|
||||
|
||||
var test = await _goalRepository.GetGoalsAsync(null);
|
||||
/*These were not calculated as we mocked the dispersal service. Just verifying that the receipt goal
|
||||
change were applied. */
|
||||
var julyPersonnelGoals = await _goalService.GetMonthlyPersonnelGoalsAsync(
|
||||
new DepartmentPersonnelSearchRequest()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
Month = 7,
|
||||
Year = 2021
|
||||
});
|
||||
Assert.AreEqual(110, julyPersonnelGoals.Goals["C00002"].ProductGoals[Product.Mortgage]);
|
||||
Assert.AreEqual(111, julyPersonnelGoals.Goals["C00003"].ProductGoals[Product.Mortgage]);
|
||||
Assert.AreEqual(112, julyPersonnelGoals.Goals["C00004"].ProductGoals[Product.Mortgage]);
|
||||
|
||||
var augPersonnelGoals = await _goalService.GetMonthlyPersonnelGoalsAsync(
|
||||
new DepartmentPersonnelSearchRequest()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
Month = 8,
|
||||
Year = 2021
|
||||
});
|
||||
Assert.AreEqual(220, augPersonnelGoals.Goals["C00002"].ProductGoals[Product.Mortgage]);
|
||||
Assert.AreEqual(222, augPersonnelGoals.Goals["C00003"].ProductGoals[Product.Mortgage]);
|
||||
Assert.AreEqual(224, augPersonnelGoals.Goals["C00004"].ProductGoals[Product.Mortgage]);
|
||||
|
||||
var sepPersonnelGoals = await _goalService.GetMonthlyPersonnelGoalsAsync(
|
||||
new DepartmentPersonnelSearchRequest()
|
||||
{
|
||||
DepartmentId = 1,
|
||||
Month = 9,
|
||||
Year = 2021
|
||||
});
|
||||
Assert.AreEqual(330, sepPersonnelGoals.Goals["C00002"].ProductGoals[Product.Mortgage]);
|
||||
Assert.AreEqual(333, sepPersonnelGoals.Goals["C00003"].ProductGoals[Product.Mortgage]);
|
||||
Assert.AreEqual(336, sepPersonnelGoals.Goals["C00004"].ProductGoals[Product.Mortgage]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveGoalRange_ReDisperseDepartmentGoals_OnlyIfDeptGoalChanges_OK()
|
||||
{
|
||||
var julygoalDispersalReceipt =
|
||||
new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct);
|
||||
|
||||
Mock.Get(_userService).Setup(x => x.FindDepartmentAssignments(It.IsAny<DepartmentPersonnelSearchRequest>()))
|
||||
.ReturnsAsync(
|
||||
new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "C00002"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "C00003"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "C00004"
|
||||
}
|
||||
});
|
||||
julygoalDispersalReceipt.GoalChanges = new List<GoalChange>()
|
||||
{
|
||||
new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00002",
|
||||
Value = 110,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
},
|
||||
new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00003",
|
||||
Value = 111,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
},
|
||||
new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00004",
|
||||
Value = 112,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
}
|
||||
};
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(
|
||||
It.Is<DepartmentGoalExtrapolationRequest>(request =>
|
||||
request.DepartmentId == 1 && request.DepartmentGoalStartDate.Month == 7),
|
||||
It.IsAny<PersonnelGoals>()))
|
||||
.Returns(julygoalDispersalReceipt);
|
||||
|
||||
//For August
|
||||
var augGoalDispersalReceipt =
|
||||
new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct);
|
||||
augGoalDispersalReceipt.GoalChanges = julygoalDispersalReceipt.GoalChanges.Select(x => new GoalChange()
|
||||
{
|
||||
Product = x.Product,
|
||||
DepartmentId = x.DepartmentId,
|
||||
PersonId = x.PersonId,
|
||||
Value = x.Value * 2,
|
||||
StartDate = DateTime.Parse("2021-08-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-08-31T20:59:00.000")
|
||||
}).ToList();
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(
|
||||
It.Is<DepartmentGoalExtrapolationRequest>(x =>
|
||||
x.DepartmentId == 1 && x.DepartmentGoalStartDate.Month == 8), It.IsAny<PersonnelGoals>()))
|
||||
.Returns(augGoalDispersalReceipt);
|
||||
|
||||
//For September
|
||||
var sepGoalDispersalReceipt =
|
||||
new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct);
|
||||
sepGoalDispersalReceipt.GoalChanges = julygoalDispersalReceipt.GoalChanges.Select(x => new GoalChange()
|
||||
{
|
||||
Product = x.Product,
|
||||
DepartmentId = x.DepartmentId,
|
||||
PersonId = x.PersonId,
|
||||
Value = x.Value * 3,
|
||||
StartDate = DateTime.Parse("2021-09-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-09-30T20:59:00.000")
|
||||
}).ToList();
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(
|
||||
It.Is<DepartmentGoalExtrapolationRequest>(x =>
|
||||
x.DepartmentId == 1 && x.DepartmentGoalStartDate.Month == 9), It.IsAny<PersonnelGoals>()))
|
||||
.Returns(sepGoalDispersalReceipt);
|
||||
|
||||
_mockDispersalStrategyService
|
||||
.Setup(x => x.ExtrapolateSingleDepartmentProduct(
|
||||
It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 2),
|
||||
It.IsAny<PersonnelGoals>()))
|
||||
.Returns(new GoalDispersalReceipt(2, GoalDispersalStrategy.ExtrapolateSingleDepartmentProduct));
|
||||
|
||||
var saved = await _goalService.GetGoalsAsync(new GoalSearchRequest());
|
||||
Assert.NotNull(saved);
|
||||
Assert.IsEmpty(saved);
|
||||
|
||||
var goal = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 98,
|
||||
StartDate = DateTime.Parse("2021-07-01T20:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
var goal2 = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 99,
|
||||
StartDate = DateTime.Parse("2021-08-01T10:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-08-31T21:59:00.000")
|
||||
};
|
||||
var goal3 = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 100,
|
||||
StartDate = DateTime.Parse("2021-09-01T11:30:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-09-30T03:59:00.000")
|
||||
};
|
||||
var goalDiffDept = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 2,
|
||||
Value = 101,
|
||||
StartDate = DateTime.Parse("2021-09-01T12:30:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-09-30T20:59:00.000")
|
||||
};
|
||||
var goalPersonnel = new GoalChange()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
PersonId = "C00002",
|
||||
Value = 102,
|
||||
StartDate = DateTime.Parse("2021-07-01T13:00:13.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T20:59:00.000")
|
||||
};
|
||||
var result = await _goalService.SaveGoalRangeAsync(new List<GoalChange>()
|
||||
{
|
||||
goal, goal2, goal3, goalDiffDept, goalPersonnel
|
||||
});
|
||||
|
||||
var goalUpdate = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 98,
|
||||
StartDate = DateTime.Parse("2021-07-01T20:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
var goal2Update = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 99,
|
||||
StartDate = DateTime.Parse("2021-08-01T10:00:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-08-31T21:59:00.000")
|
||||
};
|
||||
var goal3Update = new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
DepartmentId = 1,
|
||||
Value = 100,
|
||||
StartDate = DateTime.Parse("2021-09-01T11:30:00.000").StartOfMonth(),
|
||||
EndDate = DateTime.Parse("2021-09-30T03:59:00.000")
|
||||
};
|
||||
|
||||
var resultRedispersal = await _goalService.SaveGoalRangeAsync(new List<GoalChange>()
|
||||
{
|
||||
goalUpdate, goal2Update, goal3Update
|
||||
});
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(5, result.Count);
|
||||
|
||||
//Only duplicate goal changes are saved, and issue no new personnel changes
|
||||
Assert.NotNull(resultRedispersal);
|
||||
Assert.AreEqual(3, resultRedispersal.Count);
|
||||
|
||||
var goalChanges = await _goalChangeRepository.GetGoalChangesAsync();
|
||||
Assert.AreEqual(8, goalChanges.Count());
|
||||
|
||||
var startDate = goal.StartDate;
|
||||
|
||||
//Verify that we did not Redisperse
|
||||
_mockDispersalStrategyService.Verify(
|
||||
x => x.ExtrapolateSingleDepartmentProduct(
|
||||
It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 1),
|
||||
It.IsAny<PersonnelGoals>()), Times.Exactly(0));
|
||||
|
||||
_mockDispersalStrategyService.Verify(
|
||||
x => x.ExtrapolateSingleDepartmentProduct(
|
||||
It.Is<DepartmentGoalExtrapolationRequest>(x => x.DepartmentId == 2),
|
||||
It.IsAny<PersonnelGoals>()), Times.Exactly(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
+361
@@ -0,0 +1,361 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.DispersalStrategy;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class GoalServiceTest
|
||||
{
|
||||
private GoalService _goalService;
|
||||
private IGoalRepository _goalRepository;
|
||||
private IGoalChangeRepository _goalChangeRepository;
|
||||
private ICurrentUserService _currentUserService;
|
||||
private IDepartmentRepository _departmentRepository;
|
||||
private Mock<IDispersalStrategyService> _mockDispersalStrategyService;
|
||||
private IUserService _userService;
|
||||
private IUnitOfWork _unitOfWork;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_currentUserService = Mock.Of<ICurrentUserService>();
|
||||
_userService = Mock.Of<IUserService>();
|
||||
|
||||
Mock.Get(_currentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]"
|
||||
});
|
||||
|
||||
_goalRepository = Mock.Of<IGoalRepository>();
|
||||
_goalChangeRepository = Mock.Of<IGoalChangeRepository>();
|
||||
_unitOfWork = Mock.Of<IUnitOfWork>();
|
||||
_mockDispersalStrategyService = new Mock<IDispersalStrategyService>();
|
||||
_departmentRepository = Mock.Of<IDepartmentRepository>();
|
||||
|
||||
_goalService = new GoalService(_goalRepository, _goalChangeRepository, _currentUserService, _mockDispersalStrategyService.Object,
|
||||
_unitOfWork, _userService, _departmentRepository);
|
||||
}
|
||||
[Test]
|
||||
public async Task GetMonthlyPersonnelGoals_Basic()
|
||||
{
|
||||
var searchRequest = new DepartmentPersonnelSearchRequest()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Year = 2020,
|
||||
Month = 3
|
||||
};
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
FullName = "Tester Doe",
|
||||
EmployeeId = "11771"
|
||||
}
|
||||
};
|
||||
var goals = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Value = 4,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Vehicle,
|
||||
Value = 4,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_userService).Setup(s => s.FindDepartmentAssignments(searchRequest))
|
||||
.ReturnsAsync(users);
|
||||
|
||||
Mock.Get(_goalRepository).Setup(s => s.FindMonthlyPersonnelGoals(searchRequest.DepartmentId, users,
|
||||
searchRequest.Year, searchRequest.Month))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _goalService.GetMonthlyPersonnelGoalsAsync(searchRequest);
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(result.GoalAudit);
|
||||
Assert.IsNotEmpty(result.GoalAudit);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetEmployeeDepartmentsGoalsForMonth_Basic()
|
||||
{
|
||||
var range = new MonthRange(2021, 1);
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
FullName = "Tester Doe",
|
||||
EmployeeId = "11771",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var userDept = new UserDepartment()
|
||||
{
|
||||
Role = Role.Teller,
|
||||
DepartmentId = 55,
|
||||
Employee = user,
|
||||
IsHome = true,
|
||||
SlidingPayout = 100,
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 55,
|
||||
DepartmentName = "Dept1",
|
||||
State = DepartmentState.Active
|
||||
}
|
||||
};
|
||||
user.Departments.Add(userDept);
|
||||
|
||||
var goals = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Value = 4,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Vehicle,
|
||||
Value = 4,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_goalRepository).Setup(s =>
|
||||
s.FindDepartmentGoalsByMonthRange(userDept.DepartmentId, It.IsAny<MonthRange>()))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _goalService.GetEmployeeDepartmentsGoalsForMonthRangeAsync(user, range);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetEmployeeGoalsForMonth_Basic()
|
||||
{
|
||||
var searchRequest = new DepartmentPersonnelSearchRequest()
|
||||
{
|
||||
DepartmentId = 55,
|
||||
Year = 2020,
|
||||
Month = 3
|
||||
};
|
||||
var range = new MonthRange(2021, 1);
|
||||
|
||||
var user = new AppUser()
|
||||
{
|
||||
FullName = "Tester Doe",
|
||||
EmployeeId = "11771",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var userDept = new UserDepartment()
|
||||
{
|
||||
Role = Role.Teller,
|
||||
DepartmentId = 55,
|
||||
Employee = user,
|
||||
IsHome = true,
|
||||
SlidingPayout = 100,
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 55,
|
||||
DepartmentName = "Dept1",
|
||||
State = DepartmentState.Active
|
||||
}
|
||||
};
|
||||
user.Departments.Add(userDept);
|
||||
|
||||
var goals = new List<Goal>()
|
||||
{
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Value = 4,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55
|
||||
},
|
||||
new Goal()
|
||||
{
|
||||
Product = Product.Vehicle,
|
||||
Value = 4,
|
||||
EmployeeId = "11771",
|
||||
DepartmentId = 55
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_goalRepository).Setup(s =>
|
||||
s.FindPersonnelGoalsByMonthRange(userDept.DepartmentId, It.IsAny<List<AppUser>>(), range))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _goalService.GetEmployeeGoalsForMonthRangeAsync(user, range);
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(result.GoalAudit);
|
||||
Assert.IsNotEmpty(result.GoalAudit);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDeptGoals()
|
||||
{
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
Value = 98,
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
Value = 99,
|
||||
StartDate = DateTime.Parse("2021-08-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-08-31T23:59:00.000")
|
||||
};
|
||||
var goal3 = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
Value = 100,
|
||||
StartDate = DateTime.Parse("2020-09-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2020-09-30T23:59:00.000")
|
||||
};
|
||||
var goalDiffDept = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 2,
|
||||
Value = 101,
|
||||
StartDate = DateTime.Parse("2021-09-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-09-30T23:59:00.000")
|
||||
};
|
||||
var inputGoals = new List<Goal>()
|
||||
{
|
||||
goal, goal2, goal3, goalDiffDept
|
||||
};
|
||||
|
||||
var startDate = goal.StartDate;
|
||||
Mock.Get(_goalRepository).Setup(mock => mock.FindAnnualDepartmentGoals(It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(inputGoals);
|
||||
|
||||
var goals = await _goalService.GetAnnualDepartmentGoalsAsync(goal.DepartmentId, startDate.Year);
|
||||
Assert.NotNull(goals);
|
||||
var checkCardGoals = goals.MonthlyGoals[goal.StartDate.Month - 1].ProductGoals[Product.CheckCard];
|
||||
Assert.AreEqual(goal.Value, checkCardGoals);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAllDeptGoals()
|
||||
{
|
||||
var goal = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
Value = 98,
|
||||
StartDate = DateTime.Parse("2021-07-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-07-31T23:59:00.000")
|
||||
};
|
||||
var goal2 = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 1,
|
||||
Value = 99,
|
||||
StartDate = DateTime.Parse("2021-08-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-08-31T23:59:00.000")
|
||||
};
|
||||
var goalDiffDept = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 2,
|
||||
Value = 100,
|
||||
StartDate = DateTime.Parse("2020-09-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2020-09-30T23:59:00.000")
|
||||
};
|
||||
var goalDiffDept2 = new Goal()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
DepartmentId = 2,
|
||||
Value = 101,
|
||||
StartDate = DateTime.Parse("2021-09-01T00:00:00.000"),
|
||||
EndDate = DateTime.Parse("2021-09-30T23:59:00.000")
|
||||
};
|
||||
var inputGoals = new List<Goal>()
|
||||
{
|
||||
goal, goal2
|
||||
};
|
||||
var inputGoals2 = new List<Goal>()
|
||||
{
|
||||
goalDiffDept, goalDiffDept2
|
||||
};
|
||||
var departments = new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
Id = 1,
|
||||
DepartmentName = "dept1"
|
||||
},
|
||||
new Department()
|
||||
{
|
||||
Id = 2,
|
||||
DepartmentName = "dept2"
|
||||
}
|
||||
};
|
||||
|
||||
var startDate = goal.StartDate;
|
||||
Mock.Get(_goalRepository).Setup(mock => mock.FindAnnualDepartmentGoals(1, It.IsAny<int>()))
|
||||
.ReturnsAsync(inputGoals);
|
||||
Mock.Get(_goalRepository).Setup(mock => mock.FindAnnualDepartmentGoals(2, It.IsAny<int>()))
|
||||
.ReturnsAsync(inputGoals2);
|
||||
Mock.Get(_departmentRepository).Setup(mock => mock.GetAllDepartmentsAsync()).ReturnsAsync(departments);
|
||||
|
||||
var goals = await _goalService.GetAllAnnualDepartmentGoalsAsync(startDate.Year);
|
||||
Assert.NotNull(goals);
|
||||
var checkCardGoals = goals.First().MonthlyGoals[goal.StartDate.Month - 1].ProductGoals[Product.CheckCard];
|
||||
Assert.AreEqual(goal.Value, checkCardGoals);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetGoalChanges_Basic()
|
||||
{
|
||||
var goals = new List<GoalChange>()
|
||||
{
|
||||
new GoalChange()
|
||||
{
|
||||
Product = Product.Mortgage,
|
||||
Value = 4,
|
||||
DepartmentId = 55
|
||||
},
|
||||
new GoalChange()
|
||||
{
|
||||
Product = Product.Vehicle,
|
||||
Value = 4,
|
||||
DepartmentId = 55
|
||||
}
|
||||
};
|
||||
|
||||
Mock.Get(_goalChangeRepository).Setup(s => s.GetGoalChangesAsync())
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _goalService.GetGoalChangesAsync();
|
||||
Assert.NotNull(result);
|
||||
Assert.IsNotEmpty(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.DataAccess;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services.MicroApiServices
|
||||
{
|
||||
public class FileOperationsApiServiceTest
|
||||
{
|
||||
private FileOperationsApiService _fileOperationsApiService;
|
||||
private Mock<IFileOperationsApiDao> _mockFileOperationsDao;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockFileOperationsDao = new Mock<IFileOperationsApiDao>();
|
||||
_fileOperationsApiService = new FileOperationsApiService(_mockFileOperationsDao.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetFileContent_ValidRequest_Success()
|
||||
{
|
||||
_mockFileOperationsDao.Setup(s => s.GetFileContent("filePath")).ReturnsAsync("fileContent");
|
||||
|
||||
var fileContent = await _fileOperationsApiService.GetFileContent("filePath");
|
||||
|
||||
_mockFileOperationsDao.Verify(s => s.GetFileContent("filePath"), Times.Once());
|
||||
Assert.AreEqual("fileContent", fileContent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetFileContent_DaoFails_ExceptionThrown()
|
||||
{
|
||||
_mockFileOperationsDao.Setup(s => s.GetFileContent("filePath")).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.GetFileContent("filePath"));
|
||||
|
||||
_mockFileOperationsDao.Verify(s => s.GetFileContent("filePath"), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.NotificationsApiLib.Models;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.DataAccess;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Dayforce;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.GoalDispersal;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class NotificationServiceTest
|
||||
{
|
||||
private INotificationApiService _notificationService;
|
||||
private Mock<INotificationApiDao> _mockNotificationsDao;
|
||||
private EmailRecipientsConfiguration _emailConfig;
|
||||
private Mock<ApiConfiguration> _incentiveApiConfig;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockNotificationsDao = new Mock<INotificationApiDao>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_incentiveApiConfig = new Mock<ApiConfiguration>();
|
||||
_emailConfig = new EmailRecipientsConfiguration()
|
||||
{
|
||||
TransferRequestInitiatedNotification = new List<string> { "[email protected]" }
|
||||
};
|
||||
_notificationService = new NotificationApiService(_emailConfig, _incentiveApiConfig.Object, _mockNotificationsDao.Object,
|
||||
_mockUserService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendMonthStartGoalDispersalReceipt_Ok()
|
||||
{
|
||||
var noErrorsReceipt = new GoalDispersalReceipt(1, GoalDispersalStrategy.ExtrapolateFromExistingGoals);
|
||||
var withErrorsReceipt = new GoalDispersalReceipt(2, GoalDispersalStrategy.ExtrapolateFromExistingGoals);
|
||||
withErrorsReceipt.AddNewDispersalError(GoalDispersalError.ErrorsDuringDisperse, "1234", "Error1", "Batmam");
|
||||
withErrorsReceipt.AddNewDispersalError(GoalDispersalError.DispersedToUserWithoutPermission, "4567",
|
||||
"Error2", "Ironman");
|
||||
var defaultReceipt = new GoalDispersalReceipt(3, GoalDispersalStrategy.DefaultDisperseWithWeights);
|
||||
var defaultReceiptWithErrors =
|
||||
new GoalDispersalReceipt(4, GoalDispersalStrategy.DefaultDisperseWithWeights);
|
||||
defaultReceiptWithErrors.AddNewDispersalError(GoalDispersalError.ErrorsDuringDisperse, "8910", "Error3",
|
||||
"Superman");
|
||||
|
||||
var reportData = new Dictionary<string, GoalDispersalReceipt>()
|
||||
{
|
||||
{ "DeptA - 1", noErrorsReceipt },
|
||||
{ "DeptB - 2", withErrorsReceipt },
|
||||
{ "DeptC - 3", defaultReceipt },
|
||||
{ "DeptD - 4", defaultReceiptWithErrors },
|
||||
{ "DeptE - 6", null }
|
||||
};
|
||||
|
||||
_mockNotificationsDao.Setup(x =>
|
||||
x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
||||
await _notificationService.SendMonthStartGoalDispersalReceipt(reportData, new List<string>());
|
||||
|
||||
_mockNotificationsDao.Verify(x => x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendMonthStartGoalDispersalReceipt_Does_Not_Except()
|
||||
{
|
||||
_mockNotificationsDao.Setup(x => x.SendMessageAsync(It.IsAny<EmailRequest>()))
|
||||
.ThrowsAsync(new Exception("Ahhh"));
|
||||
|
||||
var result = _notificationService.SendMonthStartGoalDispersalReceipt(new Dictionary<string, GoalDispersalReceipt>()
|
||||
{
|
||||
{ "Test", new GoalDispersalReceipt(10, GoalDispersalStrategy.DefaultDisperseWithWeights) }
|
||||
}, new List<string>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendMissingRoleNotification_Ok()
|
||||
{
|
||||
var users = new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
FullName = "Test One",
|
||||
EmployeeId = "11771",
|
||||
BaseRole = "Base Role",
|
||||
HomeDepartment = "Home"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
FullName = "Test Two",
|
||||
EmployeeId = "C00002",
|
||||
BaseRole = "Base Role",
|
||||
HomeDepartment = "Home"
|
||||
}
|
||||
};
|
||||
|
||||
_mockNotificationsDao.Setup(x =>
|
||||
x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
||||
await _notificationService.SendMissingRoleNotification(users, new List<string>());
|
||||
|
||||
_mockNotificationsDao.Verify(x => x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendTerminatedEmployeeNotification_Ok()
|
||||
{
|
||||
var employee = new AppUser()
|
||||
{
|
||||
FullName = "Test One",
|
||||
EmployeeId = "11771",
|
||||
BaseRole = "Base Role",
|
||||
HomeDepartment = "Home",
|
||||
Terminated = new DateTime(2020, 3, 1)
|
||||
};
|
||||
var manager = new AppUser()
|
||||
{
|
||||
FullName = "Test Two",
|
||||
EmployeeId = "C00002",
|
||||
BaseRole = "Base Role",
|
||||
HomeDepartment = "Home"
|
||||
};
|
||||
var lastMonth = new PayoutEntry()
|
||||
{
|
||||
Code = "ABC",
|
||||
EmployeeId = "11771",
|
||||
EmployeeName = "Test One",
|
||||
PayoutTotal = 500
|
||||
};
|
||||
var thisMonth = new PayoutEntry()
|
||||
{
|
||||
Code = "ABC",
|
||||
EmployeeId = "11771",
|
||||
EmployeeName = "Test One",
|
||||
PayoutTotal = 200
|
||||
};
|
||||
|
||||
var receipts = new List<TerminatedEmployeeReceipt>()
|
||||
{
|
||||
new TerminatedEmployeeReceipt(employee,lastMonth,thisMonth,manager)
|
||||
};
|
||||
|
||||
_mockNotificationsDao.Setup(x =>
|
||||
x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
||||
await _notificationService.SendTerminatedEmployeeNotification(receipts, new List<string>());
|
||||
|
||||
_mockNotificationsDao.Verify(x => x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendTransferRequestInitiatedNotification_Ok()
|
||||
{
|
||||
var transferAction = new ActivityTransferAction
|
||||
{
|
||||
RequestedActivityId = 1,
|
||||
RequestedActivity = new Activity
|
||||
{
|
||||
DepartmentId = 1,
|
||||
Product = Product.CheckCard,
|
||||
Type = ActivityType.Referral
|
||||
},
|
||||
CreatedBy = "Employee One",
|
||||
NewActivityEmployeeId = "123",
|
||||
NewActivityDepartmentId = 2
|
||||
};
|
||||
var recipients = new List<string> { "[email protected]", "[email protected]" };
|
||||
|
||||
_mockNotificationsDao.Setup(x =>
|
||||
x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
||||
|
||||
await _notificationService.SendTransferRequestInitiatedNotification(transferAction, recipients);
|
||||
|
||||
_mockNotificationsDao.Verify(x => x.SendMessageAsync(It.IsAny<EmailRequest>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendTransferRequestInitiatedNotification_OverrideRecipients()
|
||||
{
|
||||
var transferAction = new ActivityTransferAction
|
||||
{
|
||||
RequestedActivityId = 1,
|
||||
RequestedActivity = new Activity
|
||||
{
|
||||
DepartmentId = 1,
|
||||
Product = Product.CheckCard,
|
||||
Type = ActivityType.Referral
|
||||
},
|
||||
CreatedBy = "Employee One",
|
||||
NewActivityEmployeeId = "123",
|
||||
NewActivityDepartmentId = 2
|
||||
};
|
||||
var originalRecipients = new List<string> { "[email protected]", "[email protected]" };
|
||||
var actualRecipients = new List<string> { "[email protected]" };
|
||||
|
||||
_emailConfig.OverrideRecipients = true;
|
||||
_emailConfig.TransferRequestInitiatedNotification = actualRecipients;
|
||||
|
||||
var emailRequest = new EmailRequest
|
||||
{
|
||||
Recipient = originalRecipients,
|
||||
Body = "test",
|
||||
Subject = "Test"
|
||||
};
|
||||
|
||||
_mockNotificationsDao.Setup(x => x.SendMessageAsync(emailRequest));
|
||||
|
||||
await _notificationService.SendTransferRequestInitiatedNotification(transferAction, actualRecipients);
|
||||
|
||||
emailRequest = new EmailRequest
|
||||
{
|
||||
Recipient = actualRecipients,
|
||||
Body = "test",
|
||||
Subject = "Test"
|
||||
};
|
||||
|
||||
_mockNotificationsDao.Verify(notification => notification.SendMessageAsync(It.IsAny<EmailRequest>()), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1440
File diff suppressed because it is too large
Load Diff
+1105
File diff suppressed because it is too large
Load Diff
+71
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class ProcessorHistoryServiceTest
|
||||
{
|
||||
private ProcessorHistoryService _processorHistoryService;
|
||||
private Mock<IProcessorHistoryRepository> _mockRepository;
|
||||
|
||||
public ProcessorHistoryServiceTest()
|
||||
{
|
||||
_mockRepository = new Mock<IProcessorHistoryRepository>();
|
||||
_processorHistoryService = new ProcessorHistoryService(_mockRepository.Object, new Mock<IUnitOfWork>().Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetProcessorHistory_OK()
|
||||
{
|
||||
_mockRepository.Setup(repo => repo.GetProcessorRunHistory(It.IsAny<Process>())).ReturnsAsync(new ProcessorHistoryRecord()
|
||||
{
|
||||
Process = Process.ImportCheckingAccountSalesFromDna,
|
||||
LastProcessedRecordId = 5
|
||||
}).Verifiable();
|
||||
|
||||
var res = await _processorHistoryService.GetProcessorHistory(Process.ImportCheckingAccountSalesFromDna);
|
||||
Assert.AreEqual(Process.ImportCheckingAccountSalesFromDna, res.Process);
|
||||
Assert.AreEqual(5, res.LastProcessedRecordId);
|
||||
|
||||
_mockRepository.Verify( x => x.GetProcessorRunHistory(It.Is<Process>(x => x == Process.ImportCheckingAccountSalesFromDna)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProcessorHistory_Exception()
|
||||
{
|
||||
_mockRepository.Setup(repo => repo.GetProcessorRunHistory(It.IsAny<Process>()))
|
||||
.ThrowsAsync(new Exception("oops"));
|
||||
Assert.ThrowsAsync<Exception>( async () => await _processorHistoryService.GetProcessorHistory(Process.ImportCheckingAccountSalesFromDna));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SaveProcessorHistory_Exception()
|
||||
{
|
||||
_mockRepository.Setup(repo => repo.SaveProcessorRunHistory(It.IsAny<ProcessorHistoryRecord>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
Assert.ThrowsAsync<Exception>( async () => await _processorHistoryService.SaveProcessorHistory(new ProcessorHistoryRecord()
|
||||
{
|
||||
LastProcessedRecordId = 100
|
||||
}));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveProcessorHistory_OK()
|
||||
{
|
||||
_mockRepository.Setup(repo => repo.SaveProcessorRunHistory(It.IsAny<ProcessorHistoryRecord>())).ReturnsAsync(Process.ImportCheckingAccountSalesFromDna).Verifiable();
|
||||
|
||||
var res = await _processorHistoryService.SaveProcessorHistory(new ProcessorHistoryRecord()
|
||||
{
|
||||
LastProcessedRecordId = 100
|
||||
});
|
||||
Assert.AreEqual(Process.ImportCheckingAccountSalesFromDna, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
+323
@@ -0,0 +1,323 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Temenos;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Temenos;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Constants;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
|
||||
namespace Application.UnitTests.Services.Temenos
|
||||
{
|
||||
public class ImportCreditCardSalesServiceTest
|
||||
{
|
||||
private ImportCreditCardSalesService _importCreditCardSalesService;
|
||||
private Mock<IUserRepository> _mockUserRepository;
|
||||
private Mock<IActivityService> _mockActivityService;
|
||||
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
|
||||
private Mock<IDeadActivityService> _mockDeadActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserRepository = new Mock<IUserRepository>();
|
||||
_mockActivityService = new Mock<IActivityService>();
|
||||
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
|
||||
_mockDeadActivityService = new Mock<IDeadActivityService>();
|
||||
_importCreditCardSalesService = new ImportCreditCardSalesService(_mockActivityService.Object,
|
||||
_mockUserRepository.Object,
|
||||
_mockFileOperationsApiService.Object,
|
||||
_mockDeadActivityService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportCreditCardSales_BusinessPersonalAndDeadActivities_OK()
|
||||
{
|
||||
string fileContents = GetFileContent();
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContents);
|
||||
|
||||
AppUser user = GetAppUser();
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
_mockActivityService.Setup(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()));
|
||||
_mockDeadActivityService.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()));
|
||||
|
||||
var request = new ImportCreditCardSalesRequest()
|
||||
{
|
||||
FilePath = "path",
|
||||
DynamicFileName = "filename"
|
||||
|
||||
};
|
||||
|
||||
await _importCreditCardSalesService.HandleImportCreditCardSales(request);
|
||||
|
||||
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(3));
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Once);
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportCreditCardSales_UserRepositoryFails_ActivitesSavedAsDead()
|
||||
{
|
||||
string fileContents = GetFileContent();
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContents);
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ThrowsAsync(new Exception("Failure"));
|
||||
_mockDeadActivityService.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()));
|
||||
|
||||
var request = new ImportCreditCardSalesRequest()
|
||||
{
|
||||
FilePath = "path",
|
||||
DynamicFileName = "filename"
|
||||
|
||||
};
|
||||
|
||||
await _importCreditCardSalesService.HandleImportCreditCardSales(request);
|
||||
|
||||
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(3));
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Once);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportCreditCardSales_UserHomeDeptIsNull_ActivitesSavedAsDead()
|
||||
{
|
||||
string fileContents = GetFileContent();
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContents);
|
||||
|
||||
AppUser user = GetAppUser(false);
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
_mockDeadActivityService.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()));
|
||||
|
||||
var request = new ImportCreditCardSalesRequest()
|
||||
{
|
||||
FilePath = "path",
|
||||
DynamicFileName = "filename"
|
||||
|
||||
};
|
||||
|
||||
await _importCreditCardSalesService.HandleImportCreditCardSales(request);
|
||||
|
||||
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(3));
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportCreditCardSales_DeadActivityServiceFails_OtherActivitiesSave()
|
||||
{
|
||||
string fileContents = GetFileContent();
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContents);
|
||||
|
||||
AppUser user = GetAppUser();
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
_mockActivityService.Setup(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()));
|
||||
_mockDeadActivityService.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>())).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var request = new ImportCreditCardSalesRequest()
|
||||
{
|
||||
FilePath = "path",
|
||||
DynamicFileName = "filename"
|
||||
|
||||
};
|
||||
|
||||
await _importCreditCardSalesService.HandleImportCreditCardSales(request);
|
||||
|
||||
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(3));
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Once);
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HandleImportCreditCardSales_FileOperationsFindFilesFails_ExceptionThrown()
|
||||
{
|
||||
string fileContents = GetFileContent();
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var request = new ImportCreditCardSalesRequest()
|
||||
{
|
||||
FilePath = "path",
|
||||
DynamicFileName = "filename"
|
||||
|
||||
};
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(() => _importCreditCardSalesService.HandleImportCreditCardSales(request));
|
||||
|
||||
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HandleImportCreditCardSales_FileOperationsGetFileContentFails_ExceptionThrown()
|
||||
{
|
||||
string fileContents = GetFileContent();
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
_mockFileOperationsApiService.Setup(x => x.GetFileContent("path\\filename")).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var request = new ImportCreditCardSalesRequest()
|
||||
{
|
||||
FilePath = "path",
|
||||
DynamicFileName = "filename"
|
||||
|
||||
};
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(() => _importCreditCardSalesService.HandleImportCreditCardSales(request));
|
||||
|
||||
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
}
|
||||
|
||||
private static AppUser GetAppUser(bool assignHomeDepartment = true)
|
||||
{
|
||||
var department = new Department
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
if (assignHomeDepartment)
|
||||
{
|
||||
user.Departments.Add(assignment);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
private static string GetFileContent()
|
||||
{
|
||||
var fileContent = new List<TemenosCreditCardSale>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
ApplicationID = "123",
|
||||
SubProduct = TemenosImportConstants.PersonalCardSubProduct,
|
||||
FinalLoanAmount = "$1000.00",
|
||||
DisbursedDate = DateTime.Now.AddDays(-1).ToString("MM/dd/yyyy"),
|
||||
ApplicantFirstName = "FName",
|
||||
ApplicantLastName = "LName",
|
||||
OrganizationName = string.Empty,
|
||||
LOResponsibleEmployeeEmail = string.Empty,
|
||||
LODirectLoanOfficer = string.Empty,
|
||||
ReferringEmployeeEmail = "[email protected]",
|
||||
},
|
||||
new()
|
||||
{
|
||||
ApplicationID = "456",
|
||||
SubProduct = TemenosImportConstants.PersonalCardSubProduct,
|
||||
FinalLoanAmount = "$1000.00",
|
||||
DisbursedDate = DateTime.Now.AddDays(-1).ToString("MM/dd/yyyy"),
|
||||
ApplicantFirstName = "FName",
|
||||
ApplicantLastName = "LName",
|
||||
OrganizationName = string.Empty,
|
||||
LOResponsibleEmployeeEmail = string.Empty,
|
||||
LODirectLoanOfficer = "LastName, FirstName",
|
||||
ReferringEmployeeEmail = string.Empty,
|
||||
},
|
||||
new()
|
||||
{
|
||||
ApplicationID = "789",
|
||||
SubProduct = "BusinessCard",
|
||||
FinalLoanAmount = "$1000.00",
|
||||
DisbursedDate = DateTime.Now.AddDays(-1).ToString("MM/dd/yyyy"),
|
||||
ApplicantFirstName = string.Empty,
|
||||
ApplicantLastName = string.Empty,
|
||||
OrganizationName = "Business Name",
|
||||
LOResponsibleEmployeeEmail = "[email protected]",
|
||||
LODirectLoanOfficer = string.Empty,
|
||||
ReferringEmployeeEmail = string.Empty,
|
||||
},
|
||||
new()
|
||||
{
|
||||
ApplicationID = "987",
|
||||
SubProduct = "BusinessCard",
|
||||
FinalLoanAmount = "$1000.00",
|
||||
DisbursedDate = DateTime.Now.AddDays(-1).ToString("MM/dd/yyyy"),
|
||||
ApplicantFirstName = "Dead",
|
||||
ApplicantLastName = "Activity",
|
||||
OrganizationName = string.Empty,
|
||||
LOResponsibleEmployeeEmail = string.Empty,
|
||||
LODirectLoanOfficer = string.Empty,
|
||||
ReferringEmployeeEmail = string.Empty,
|
||||
},
|
||||
new()
|
||||
{
|
||||
ApplicationID = "654",
|
||||
SubProduct = string.Empty,
|
||||
FinalLoanAmount = "$1000.00",
|
||||
DisbursedDate = DateTime.Now.AddDays(-1).ToString("MM/dd/yyyy"),
|
||||
ApplicantFirstName = "Record",
|
||||
ApplicantLastName = "Ignored",
|
||||
OrganizationName = string.Empty,
|
||||
LOResponsibleEmployeeEmail = string.Empty,
|
||||
LODirectLoanOfficer = string.Empty,
|
||||
ReferringEmployeeEmail = string.Empty,
|
||||
}
|
||||
};
|
||||
|
||||
var writer = new StringWriter();
|
||||
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = "|", HasHeaderRecord = false };
|
||||
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
csv.WriteRecords(fileContent);
|
||||
}
|
||||
|
||||
return writer.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
+673
@@ -0,0 +1,673 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CsvHelper.Configuration;
|
||||
using CsvHelper;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.Temenos;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.Temenos;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
|
||||
namespace Application.UnitTests.Services.Temenos
|
||||
{
|
||||
public class ImportIndirectVehicleSalesServiceTest
|
||||
{
|
||||
private ImportIndirectVehicleSalesService _importIndirectVehicleSalesService;
|
||||
private Mock<IUserRepository> _mockUserRepository;
|
||||
private Mock<IActivityService> _mockActivityService;
|
||||
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
|
||||
private Mock<IDeadActivityService> _mockDeadActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockUserRepository = new Mock<IUserRepository>();
|
||||
_mockActivityService = new Mock<IActivityService>();
|
||||
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
|
||||
_mockDeadActivityService = new Mock<IDeadActivityService>();
|
||||
_importIndirectVehicleSalesService = new ImportIndirectVehicleSalesService(_mockActivityService.Object,
|
||||
_mockUserRepository.Object,
|
||||
_mockFileOperationsApiService.Object,
|
||||
_mockDeadActivityService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportIndirectVehicleSales_DeadAndAcceptedActivities_Ok()
|
||||
{
|
||||
var directFileContent = new List<DirectVehicleSaleRecord>()
|
||||
{
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-6789",
|
||||
ApplicationID = "123",
|
||||
CreatedDate = DateTime.Now.AddDays(-50).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
},
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
ApplicationID = "321",
|
||||
CreatedDate = DateTime.Now.AddDays(-30).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
}
|
||||
};
|
||||
var directWriter = GetWriter(directFileContent);
|
||||
|
||||
var indirectFileContent = new List<IndirectVehicleSaleRecord>()
|
||||
{
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-6789",
|
||||
CreatedDate = DateTime.Now.AddDays(-40).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
},
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
CreatedDate = DateTime.Now.AddDays(-10).ToString(),
|
||||
ApplicationID = "321",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
}
|
||||
};
|
||||
var indirectWriter = GetWriter(indirectFileContent);
|
||||
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.SetupSequence(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ReturnsAsync(directWriter.ToString())
|
||||
.ReturnsAsync(indirectWriter.ToString());
|
||||
|
||||
var user = GetAppUser("[email protected]");
|
||||
_mockUserRepository.SetupSequence(x => x.FindUserByAdEmailAsync(It.IsAny<string>()))
|
||||
.ReturnsAsync(user)
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "directFileName",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
await _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request);
|
||||
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Once);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Once);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Exactly(2));
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportIndirectVehicleSales_NoMatches_NoActivitiesSaved()
|
||||
{
|
||||
|
||||
var directFileContent = new List<DirectVehicleSaleRecord>()
|
||||
{
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-6789",
|
||||
ApplicationID = "123",
|
||||
CreatedDate = DateTime.Now.AddDays(-10).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
},
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
ApplicationID = "321",
|
||||
CreatedDate = DateTime.Now.AddDays(-10).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
}
|
||||
};
|
||||
var directWriter = GetWriter(directFileContent);
|
||||
|
||||
var indirectFileContent = new List<IndirectVehicleSaleRecord>()
|
||||
{
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "987-65-4321",
|
||||
CreatedDate = DateTime.Now.AddDays(-40).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
},
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
CreatedDate = DateTime.Now.AddDays(-20).ToString(),
|
||||
ApplicationID = "321",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
}
|
||||
};
|
||||
var indirectWriter = GetWriter(indirectFileContent);
|
||||
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.SetupSequence(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ReturnsAsync(directWriter.ToString())
|
||||
.ReturnsAsync(indirectWriter.ToString());
|
||||
|
||||
var user = GetAppUser("[email protected]");
|
||||
_mockUserRepository.SetupSequence(x => x.FindUserByAdEmailAsync(It.IsAny<string>()))
|
||||
.ReturnsAsync(user)
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "directFileName",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
await _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request);
|
||||
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Never);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportIndirectVehicleSales_OneIndirectMatch_CorrectActivitySaved()
|
||||
{
|
||||
|
||||
var referringEmail = "[email protected]";
|
||||
var matchedSsn = "123-45-6789";
|
||||
var directCreatedDate = DateTime.Now.AddDays(-50).ToString();
|
||||
var indirectCreatedDate = DateTime.Now.AddDays(-10).ToString();
|
||||
var disbursedDate = DateTime.Now.ToString();
|
||||
|
||||
var directFileContent = new List<DirectVehicleSaleRecord>()
|
||||
{
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = matchedSsn,
|
||||
ApplicationID = "123",
|
||||
CreatedDate = directCreatedDate,
|
||||
ReferringEmployeeEmail = referringEmail
|
||||
},
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-9876",
|
||||
ApplicationID = "123",
|
||||
CreatedDate = DateTime.Now.AddDays(-30).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
}
|
||||
};
|
||||
var directWriter = GetWriter(directFileContent);
|
||||
|
||||
var indirectFileContent = new List<IndirectVehicleSaleRecord>()
|
||||
{
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = matchedSsn,
|
||||
CreatedDate = DateTime.Now.AddDays(-40).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = disbursedDate
|
||||
},
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
CreatedDate = DateTime.Now.AddDays(-60).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = DateTime.Now.AddDays(-70).ToString()
|
||||
},
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "999-99-9999",
|
||||
CreatedDate = DateTime.Now.AddDays(-60).ToString(),
|
||||
ApplicationID = "999",
|
||||
DisbursedDate = DateTime.Now.AddDays(-65).ToString()
|
||||
}
|
||||
};
|
||||
var indirectWriter = GetWriter(indirectFileContent);
|
||||
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.SetupSequence(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ReturnsAsync(directWriter.ToString())
|
||||
.ReturnsAsync(indirectWriter.ToString());
|
||||
|
||||
var user = GetAppUser(referringEmail);
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
_mockActivityService.Setup(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()));
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "filename",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
await _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request);
|
||||
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.Is<List<Activity>>(x => x.Count == 1
|
||||
&& x[0].EmployeeEmail == referringEmail
|
||||
&& x[0].SourceCreated == DateTime.Parse(disbursedDate)
|
||||
&& x[0].Accepted == DateTime.Parse(disbursedDate).Date.AddHours(12))));
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportIndirectVehicleSales_MultipleIndirectApplicants_FirstRecordMatches()
|
||||
{
|
||||
var referringEmail = "[email protected]";
|
||||
var matchedSsn = "123-45-6789";
|
||||
var directCreatedDate = DateTime.Now.AddDays(-50).ToString();
|
||||
var indirectCreatedDate = DateTime.Now.AddDays(-10).ToString();
|
||||
var disbursedDate = DateTime.Now.ToString();
|
||||
var matchedApplicantName = "matchedName";
|
||||
|
||||
var directFileContent = new List<DirectVehicleSaleRecord>()
|
||||
{
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = matchedSsn,
|
||||
ApplicationID = "123",
|
||||
CreatedDate = directCreatedDate,
|
||||
ReferringEmployeeEmail = referringEmail
|
||||
},
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = matchedSsn,
|
||||
ApplicationID = "123",
|
||||
CreatedDate = directCreatedDate,
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
}
|
||||
};
|
||||
var directWriter = GetWriter(directFileContent);
|
||||
|
||||
var indirectFileContent = new List<IndirectVehicleSaleRecord>()
|
||||
{
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = matchedSsn,
|
||||
CreatedDate = DateTime.Now.AddDays(-40).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = disbursedDate,
|
||||
ApplicantName = matchedApplicantName
|
||||
},
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = matchedSsn,
|
||||
CreatedDate = DateTime.Now.AddDays(-40).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = disbursedDate
|
||||
}
|
||||
};
|
||||
var indirectWriter = GetWriter(indirectFileContent);
|
||||
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.SetupSequence(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ReturnsAsync(directWriter.ToString())
|
||||
.ReturnsAsync(indirectWriter.ToString());
|
||||
|
||||
var user = GetAppUser(referringEmail);
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
_mockActivityService.Setup(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()));
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "filename",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
await _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request);
|
||||
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.Is<List<Activity>>(x => x.Count == 1
|
||||
&& x[0].Detail.MemberName == matchedApplicantName
|
||||
&& x[0].EmployeeEmail == referringEmail
|
||||
&& x[0].SourceCreated == DateTime.Parse(disbursedDate)
|
||||
&& x[0].Accepted == DateTime.Parse(disbursedDate).Date.AddHours(12))));
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HandleImportIndirectVehicleSales_DeadActivityServiceFails_ExceptionThrown()
|
||||
{
|
||||
var directFileContent = new List<DirectVehicleSaleRecord>()
|
||||
{
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
ApplicationID = "321",
|
||||
CreatedDate = DateTime.Now.AddDays(-30).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
}
|
||||
};
|
||||
var directWriter = GetWriter(directFileContent);
|
||||
|
||||
var indirectFileContent = new List<IndirectVehicleSaleRecord>()
|
||||
{
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-6789",
|
||||
CreatedDate = DateTime.Now.AddDays(-40).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
},
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
CreatedDate = DateTime.Now.AddDays(-10).ToString(),
|
||||
ApplicationID = "321",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
}
|
||||
};
|
||||
var indirectWriter = GetWriter(indirectFileContent);
|
||||
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.SetupSequence(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ReturnsAsync(directWriter.ToString())
|
||||
.ReturnsAsync(indirectWriter.ToString());
|
||||
|
||||
var user = GetAppUser("[email protected]");
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync((AppUser)null);
|
||||
|
||||
_mockDeadActivityService.Setup(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>())).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "directFileName",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(() => _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request));
|
||||
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Once);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HandleImportIndirectVehicleSales_ActivityServiceFails_ExceptionThrown()
|
||||
{
|
||||
var directFileContent = new List<DirectVehicleSaleRecord>()
|
||||
{
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
ApplicationID = "321",
|
||||
CreatedDate = DateTime.Now.AddDays(-30).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
}
|
||||
};
|
||||
var directWriter = GetWriter(directFileContent);
|
||||
|
||||
var indirectFileContent = new List<IndirectVehicleSaleRecord>()
|
||||
{
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
CreatedDate = DateTime.Now.AddDays(-10).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
}
|
||||
};
|
||||
var indirectWriter = GetWriter(indirectFileContent);
|
||||
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()))
|
||||
.ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.SetupSequence(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ReturnsAsync(directWriter.ToString())
|
||||
.ReturnsAsync(indirectWriter.ToString());
|
||||
|
||||
var user = GetAppUser("[email protected]");
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
_mockActivityService.Setup(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>())).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "directFileName",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(() => _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request));
|
||||
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Never);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Once);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportIndirectVehicleSales_UserRepositoryFails_DeadActivitySaved()
|
||||
{
|
||||
var directFileContent = new List<DirectVehicleSaleRecord>()
|
||||
{
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-6789",
|
||||
ApplicationID = "123",
|
||||
CreatedDate = DateTime.Now.AddDays(-50).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
}
|
||||
};
|
||||
var directWriter = GetWriter(directFileContent);
|
||||
|
||||
var indirectFileContent = new List<IndirectVehicleSaleRecord>()
|
||||
{
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-6789",
|
||||
CreatedDate = DateTime.Now.AddDays(-40).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
},
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
CreatedDate = DateTime.Now.AddDays(-10).ToString(),
|
||||
ApplicationID = "321",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
}
|
||||
};
|
||||
var indirectWriter = GetWriter(indirectFileContent);
|
||||
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.SetupSequence(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ReturnsAsync(directWriter.ToString())
|
||||
.ReturnsAsync(indirectWriter.ToString());
|
||||
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "directFileName",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
await _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request);
|
||||
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(x => x.Count == 1)), Times.Once);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandleImportIndirectVehicleSales_NullEmployeeHomedepartment_DeadActivitySaved()
|
||||
{
|
||||
var directFileContent = new List<DirectVehicleSaleRecord>()
|
||||
{
|
||||
new DirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-6789",
|
||||
ApplicationID = "123",
|
||||
CreatedDate = DateTime.Now.AddDays(-50).ToString(),
|
||||
ReferringEmployeeEmail = "[email protected]"
|
||||
}
|
||||
};
|
||||
var directWriter = GetWriter(directFileContent);
|
||||
|
||||
var indirectFileContent = new List<IndirectVehicleSaleRecord>()
|
||||
{
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "123-45-6789",
|
||||
CreatedDate = DateTime.Now.AddDays(-40).ToString(),
|
||||
ApplicationID = "123",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
},
|
||||
new IndirectVehicleSaleRecord()
|
||||
{
|
||||
ApplicantSSN = "555-55-5555",
|
||||
CreatedDate = DateTime.Now.AddDays(-10).ToString(),
|
||||
ApplicationID = "321",
|
||||
DisbursedDate = DateTime.Now.ToString()
|
||||
}
|
||||
};
|
||||
var indirectWriter = GetWriter(indirectFileContent);
|
||||
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.SetupSequence(x => x.GetFileContent(It.IsAny<string>()))
|
||||
.ReturnsAsync(directWriter.ToString())
|
||||
.ReturnsAsync(indirectWriter.ToString());
|
||||
|
||||
var user = GetAppUser("[email protected]", false);
|
||||
_mockUserRepository.Setup(x => x.FindUserByAdEmailAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "directFileName",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
await _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request);
|
||||
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.Is<List<DeadActivity>>(x => x.Count == 1)), Times.Once);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Once);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public Task HandleImportIndirectVehicleSales_FileOperationsGetContentServiceFails_ExceptionThrown()
|
||||
{
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(fileResponse);
|
||||
|
||||
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "directFileName",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(() => _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request));
|
||||
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Never);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public Task HandleImportIndirectVehicleSales_FileOperationsBuildListServiceFails_ExceptionThrown()
|
||||
{
|
||||
var fileResponse = new string[] { "filename" };
|
||||
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var request = new ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
FilePath = "path\\",
|
||||
DirectDynamicFileName = "directFileName",
|
||||
IndirectDynamicFileName = "indirectFileName"
|
||||
};
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(() => _importIndirectVehicleSalesService.HandleImportIndirectVehicleSales(request));
|
||||
|
||||
_mockDeadActivityService.Verify(x => x.SaveDeadActivityRange(It.IsAny<List<DeadActivity>>()), Times.Never);
|
||||
_mockActivityService.Verify(x => x.SaveActivityRangeAsync(It.IsAny<List<Activity>>()), Times.Never);
|
||||
_mockUserRepository.Verify(x => x.FindUserByAdEmailAsync(It.IsAny<string>()), Times.Never);
|
||||
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private StringWriter GetWriter<T>(List<T> fileContent)
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = "|", HasHeaderRecord = false };
|
||||
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
csv.WriteRecords(fileContent);
|
||||
}
|
||||
|
||||
return writer;
|
||||
}
|
||||
|
||||
private AppUser GetAppUser(string emailAddress, bool assignHomeDepartment = true)
|
||||
{
|
||||
var department = new Department
|
||||
{
|
||||
DepartmentName = "Dept1",
|
||||
Id = 55,
|
||||
State = DepartmentState.Active
|
||||
};
|
||||
var user = new AppUser
|
||||
{
|
||||
AdEmail = emailAddress,
|
||||
EmployeeId = "11771",
|
||||
FullName = "John Doe",
|
||||
Departments = new List<UserDepartment>()
|
||||
};
|
||||
var assignment = new UserDepartment
|
||||
{
|
||||
Id = 99,
|
||||
Department = department,
|
||||
Employee = user,
|
||||
Role = Role.BM,
|
||||
IsHome = true,
|
||||
StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
|
||||
EndDate = null
|
||||
};
|
||||
|
||||
if (assignHomeDepartment)
|
||||
{
|
||||
user.Departments.Add(assignment);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
|
||||
namespace Application.UnitTests.Services
|
||||
{
|
||||
public class UserAssignmentServiceTest
|
||||
{
|
||||
private UserAssignmentService _service;
|
||||
private Mock<IUserAssignmentRepository> _mockUserAssignmentRepository;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUserAssignmentRepository = new Mock<IUserAssignmentRepository>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_service = new UserAssignmentService(_mockUserAssignmentRepository.Object, _mockUserService.Object,
|
||||
_mockUnitOfWork.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAllUserAssignmentsAsync_OK()
|
||||
{
|
||||
var assignmentsFromRepo = new List<UserAssignment>
|
||||
{
|
||||
new UserAssignment { Id = 1 },
|
||||
new UserAssignment { Id = 2 }
|
||||
};
|
||||
_mockUserAssignmentRepository.Setup(repo => repo.GetAllUserAssignmentsAsync())
|
||||
.ReturnsAsync(assignmentsFromRepo);
|
||||
|
||||
var result = await _service.GetAllUserAssignmentsAsync();
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.Any(x => x.Id == 1));
|
||||
Assert.True(result.Any(x => x.Id == 2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetRegionalManager_OK()
|
||||
{
|
||||
var assignment = new UserAssignmentRequest
|
||||
{
|
||||
EmployeeId = "123",
|
||||
Key = "NORTH",
|
||||
Type = AssignmentType.RegionalManager
|
||||
};
|
||||
var validUser = new AppUser
|
||||
{
|
||||
Assignments = new List<UserAssignment>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Role = Role.RegionalManager
|
||||
}
|
||||
}
|
||||
};
|
||||
_mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(assignment.EmployeeId))
|
||||
.ReturnsAsync(validUser);
|
||||
|
||||
var result = await _service.SetRegionalManager(assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
_mockUnitOfWork.Verify(mock => mock.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetRegionalManager_ThrowsNotFoundException()
|
||||
{
|
||||
var assignment = new UserAssignmentRequest
|
||||
{
|
||||
EmployeeId = "123"
|
||||
};
|
||||
_mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(assignment.EmployeeId))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
var exception = Assert.ThrowsAsync<NotFoundException>(async() =>
|
||||
{
|
||||
await _service.SetRegionalManager(assignment);
|
||||
});
|
||||
|
||||
Assert.AreEqual("Employee Not Found", exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetRegionalManager_ThrowsBadUserAssignmentException()
|
||||
{
|
||||
var assignment = new UserAssignmentRequest
|
||||
{
|
||||
EmployeeId = "123"
|
||||
};
|
||||
var nonRegionalManager = new AppUser { Role = Role.Teller };
|
||||
_mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(assignment.EmployeeId))
|
||||
.ReturnsAsync(nonRegionalManager);
|
||||
var exception = Assert.ThrowsAsync<BadUserAssignmentException>(async () =>
|
||||
{
|
||||
await _service.SetRegionalManager(assignment);
|
||||
});
|
||||
|
||||
Assert.AreEqual("Employee must have the Regional Manager role", exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetRegionalManager_SetsUserToAssignment()
|
||||
{
|
||||
var assignment = new UserAssignmentRequest
|
||||
{
|
||||
EmployeeId = "123",
|
||||
Key = "NORTH",
|
||||
Type = AssignmentType.RegionalManager
|
||||
};
|
||||
var userFromRepo = new AppUser
|
||||
{
|
||||
EmployeeId = "123",
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 456,
|
||||
Assignments = new List<UserAssignment>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Role = Role.RegionalManager
|
||||
}
|
||||
}
|
||||
};
|
||||
var existingAssignment = new UserAssignment
|
||||
{
|
||||
Id = 1,
|
||||
Key = "NORTH",
|
||||
Type = AssignmentType.RegionalManager,
|
||||
AppUser = new AppUser()
|
||||
};
|
||||
_mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(assignment.EmployeeId))
|
||||
.ReturnsAsync(userFromRepo);
|
||||
_mockUserAssignmentRepository.Setup(service => service.FindExistingAssignmentAsync(assignment.Type.Value,
|
||||
assignment.Key))
|
||||
.ReturnsAsync(existingAssignment);
|
||||
|
||||
var result = await _service.SetRegionalManager(assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.AreEqual(existingAssignment.AppUser.EmployeeId, userFromRepo.EmployeeId);
|
||||
Assert.AreEqual(existingAssignment.AppUser.AdEmail, userFromRepo.AdEmail);
|
||||
Assert.AreEqual(existingAssignment.AppUser.PersonId, userFromRepo.PersonId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetRegionalManager_AddsAssignmentToUser()
|
||||
{
|
||||
var assignment = new UserAssignmentRequest
|
||||
{
|
||||
EmployeeId = "123",
|
||||
Key = "NORTH",
|
||||
Type = AssignmentType.RegionalManager
|
||||
};
|
||||
var userFromRepo = new AppUser
|
||||
{
|
||||
Assignments = new List<UserAssignment>(),
|
||||
Departments = new List<UserDepartment>()
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Role = Role.RegionalManager
|
||||
}
|
||||
}
|
||||
};
|
||||
_mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(assignment.EmployeeId))
|
||||
.ReturnsAsync(userFromRepo);
|
||||
|
||||
var result = await _service.SetRegionalManager(assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.AreEqual(1, userFromRepo.Assignments.Count());
|
||||
Assert.AreEqual("NORTH", userFromRepo.Assignments.First().Key);
|
||||
Assert.AreEqual(AssignmentType.RegionalManager, userFromRepo.Assignments.First().Type);
|
||||
Assert.AreEqual(Role.RegionalManager, userFromRepo.Assignments.First().AppUser.Departments.First().Role);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetUserAssignment_ReturnsAssignment()
|
||||
{
|
||||
var type = AssignmentType.RegionalManager;
|
||||
var key = "NORTH";
|
||||
var assignment = new UserAssignment {
|
||||
Id = 1,
|
||||
Key = key,
|
||||
Type = type,
|
||||
AppUser = new AppUser { EmployeeId = "C0000" }
|
||||
};
|
||||
_mockUserAssignmentRepository.Setup(mock => mock.FindExistingAssignmentAsync(type, key))
|
||||
.ReturnsAsync(assignment);
|
||||
|
||||
var result = await _service.GetUserAssignment(type, key);
|
||||
|
||||
Assert.AreEqual(AssignmentType.RegionalManager, result.Type);
|
||||
Assert.AreEqual("NORTH", result.Key);
|
||||
Assert.AreEqual(AssignmentType.RegionalManager, result.Type);
|
||||
Assert.AreEqual("C0000", result.AppUser.EmployeeId);
|
||||
|
||||
_mockUserAssignmentRepository.Verify(mock => mock.FindExistingAssignmentAsync(type, key),
|
||||
Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1582
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user