Adding
This commit is contained in:
+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