1637 lines
68 KiB
C#
1637 lines
68 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models.GoalDispersal;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.DispersalStrategy;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Extensions;
|
|
using Moq;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using NUnit.Framework;
|
|
|
|
namespace Application.UnitTests.Services.DispersalStrategy
|
|
{
|
|
public class GoalDispersalServiceTest
|
|
{
|
|
public JObject JsonData;
|
|
public Mock<IUserService> _mockUserService;
|
|
public IDispersalStrategyService _dispersalStrategyService; // = new DispersalStrategyService(new Mock<IUserService>());
|
|
|
|
private readonly PerProductGoal _ModelMonthDepartmentGoals = new PerProductGoal()
|
|
{
|
|
ProductGoals = new Dictionary<Product, int>()
|
|
{
|
|
{ Product.Mortgage, 105 },
|
|
{ Product.Vehicle, 0 },
|
|
{ Product.CheckCard, 5 },
|
|
{ Product.DirectDeposit, 18 }
|
|
}
|
|
};
|
|
|
|
private readonly PerProductGoal _DispersalMonthDepartmentGoals = new PerProductGoal()
|
|
{
|
|
ProductGoals = new Dictionary<Product, int>()
|
|
{
|
|
{ Product.Mortgage, 200 },
|
|
{ Product.Vehicle, 10 },
|
|
{ Product.CheckCard, 20 },
|
|
{ Product.DirectDeposit, 35 }
|
|
}
|
|
};
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_mockUserService = new Mock<IUserService>();
|
|
_dispersalStrategyService = new DispersalStrategyService(_mockUserService.Object);
|
|
_mockUserService.Setup(mock => mock.GetActiveUserByEmployeeIdAsync(It.IsAny<string>()))
|
|
.ReturnsAsync(new AppUser
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
AdEmail = "[email protected]",
|
|
EmployeeId = "C0000",
|
|
Departments =
|
|
{
|
|
new UserDepartment
|
|
{
|
|
DepartmentId = 1
|
|
}
|
|
}
|
|
});
|
|
|
|
JsonData = JObject.Parse(
|
|
File.ReadAllText("Services/DispersalStrategy/DispersalStrategyServiceTestData.json"));
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void ExtrapolateFromExistingGoals_Baseline_OK()
|
|
{
|
|
var testData = JsonData["BaseLine"];
|
|
var personnel = JsonConvert.DeserializeObject<List<AppUser>>(testData["AllPersonnel"].ToString());
|
|
var modelPersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["ModelMonthPersonnelGoals"].ToString());
|
|
var dispersePersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["DispersalMonthPersonnelGoals"].ToString());
|
|
|
|
//Set All Users to BM
|
|
personnel = personnel.Select(user =>
|
|
{
|
|
user.Departments.First().Role = Role.BM;
|
|
return user;
|
|
}).ToList();
|
|
|
|
var modelPersonnelGoal = new PersonnelGoals(10, 2021, 07, personnel);
|
|
modelPersonnelGoal.ApplyAll(modelPersonnelGoalList);
|
|
|
|
//These are all set arbitrarily high so that there is no situation where the newValue is the same as the current value
|
|
var dispersalMonthPersonnelGoal = new PersonnelGoals(10, 2021, 08, personnel);
|
|
dispersalMonthPersonnelGoal.ApplyAll(dispersePersonnelGoalList);
|
|
|
|
var extrapolationGoalDispersalData = new ExtrapolationGoalDispersalData()
|
|
{
|
|
DepartmentId = 10,
|
|
ModelDepartmentGoals = _ModelMonthDepartmentGoals,
|
|
DispersalMonthDepartmentGoals = _DispersalMonthDepartmentGoals,
|
|
DispersalMonthPersonnelGoals = dispersalMonthPersonnelGoal,
|
|
ModelPersonnelGoals = modelPersonnelGoal,
|
|
DispersalMonthPersonnel = personnel,
|
|
DispersalMonthStartDate = DateTime.Parse("2021-08-1").StartOfMonth(),
|
|
};
|
|
|
|
var results =
|
|
_dispersalStrategyService.ExtrapolateFromExistingGoals(extrapolationGoalDispersalData);
|
|
|
|
Assert.AreEqual(8, results.GoalChanges.Count);
|
|
Assert.AreEqual(0, results.GoalDispersalErrors.Count);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(14,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
}
|
|
|
|
[Test]
|
|
public void ExtrapolateFromExistingGoals_UserNoLongerInDepartment_OK()
|
|
{
|
|
var testData = JsonData["UserNoLongerInDepartment"];
|
|
var modelMonthPersonnel =
|
|
JsonConvert.DeserializeObject<List<AppUser>>(testData["PersonnelInModelMonth"].ToString());
|
|
var dispersalMonthPersonnel =
|
|
JsonConvert.DeserializeObject<List<AppUser>>(testData["PersonnelInDispersalMonth"].ToString());
|
|
var modelPersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["ModelMonthPersonnelGoals"].ToString());
|
|
var dispersePersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["DispersalMonthPersonnelGoals"].ToString());
|
|
|
|
//Set All Users to BM
|
|
dispersalMonthPersonnel = dispersalMonthPersonnel.Select(user =>
|
|
{
|
|
user.Departments.First().Role = Role.BM;
|
|
return user;
|
|
}).ToList();
|
|
modelMonthPersonnel = modelMonthPersonnel.Select(user =>
|
|
{
|
|
user.Departments.First().Role = Role.BM;
|
|
return user;
|
|
}).ToList();
|
|
|
|
//Contains 2 users who do not exist in dispersal month (PersonID "PersonA" and "PersonB")
|
|
//Contains 1 user who does exist in dispersal mont (PersonId "1A")
|
|
var modelPersonnelGoal = new PersonnelGoals(10, 2021, 07, modelMonthPersonnel);
|
|
modelPersonnelGoal.ApplyAll(modelPersonnelGoalList);
|
|
|
|
var dispersalMonthPersonnelGoal = new PersonnelGoals(10, 2021, 08, dispersalMonthPersonnel);
|
|
dispersalMonthPersonnelGoal.ApplyAll(dispersePersonnelGoalList);
|
|
|
|
var extrapolationGoalDispersalData = new ExtrapolationGoalDispersalData()
|
|
{
|
|
DepartmentId = 10,
|
|
ModelDepartmentGoals = _ModelMonthDepartmentGoals,
|
|
DispersalMonthDepartmentGoals = _DispersalMonthDepartmentGoals,
|
|
DispersalMonthPersonnelGoals = dispersalMonthPersonnelGoal,
|
|
ModelPersonnelGoals = modelPersonnelGoal,
|
|
//The users that are in our modelMonthPersonnel goals are not in
|
|
DispersalMonthPersonnel = dispersalMonthPersonnel,
|
|
DispersalMonthStartDate = DateTime.Parse("2021-08-1").StartOfMonth(),
|
|
};
|
|
|
|
var results =
|
|
_dispersalStrategyService.ExtrapolateFromExistingGoals(extrapolationGoalDispersalData);
|
|
|
|
Assert.AreEqual(4, results.GoalChanges.Count);
|
|
Assert.AreEqual(2, results.GoalDispersalErrors.Count);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.True(results.GoalDispersalErrors.Any(x =>
|
|
x.EmployeeId == "PersonA" && x.ErrorType == GoalDispersalError.UserNoLongerInDepartment));
|
|
Assert.True(results.GoalDispersalErrors.Any(x =>
|
|
x.EmployeeId == "PersonB" && x.ErrorType == GoalDispersalError.UserNoLongerInDepartment));
|
|
}
|
|
|
|
[Test]
|
|
public void ExtrapolateFromExistingGoals_DispersedToUserWithoutPermission_OK()
|
|
{
|
|
var testData = JsonData["DispersedToUserWithoutPermission"];
|
|
var personnel = JsonConvert.DeserializeObject<List<AppUser>>(testData["AllPersonnel"].ToString());
|
|
var modelPersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["ModelMonthPersonnelGoals"].ToString());
|
|
var dispersePersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["DispersalMonthPersonnelGoals"].ToString());
|
|
|
|
//Set 1A to BM, they have hassalesgoal permission
|
|
//Set 2B and 3C to Teller, they do not have hassalesgoals permission
|
|
personnel = personnel.Select(user =>
|
|
{
|
|
user.Departments.First().Role = (user.EmployeeId == "1A") ? Role.BM : Role.Teller;
|
|
return user;
|
|
}).ToList();
|
|
|
|
var modelPersonnelGoal = new PersonnelGoals(10, 2021, 07, personnel);
|
|
modelPersonnelGoal.ApplyAll(modelPersonnelGoalList);
|
|
|
|
//These are all set arbitrarily high so that there is no situation where the newValue is the same as the current value
|
|
var dispersalMonthPersonnelGoal = new PersonnelGoals(10, 2021, 08, personnel);
|
|
dispersalMonthPersonnelGoal.ApplyAll(dispersePersonnelGoalList);
|
|
|
|
var extrapolationGoalDispersalData = new ExtrapolationGoalDispersalData()
|
|
{
|
|
DepartmentId = 10,
|
|
ModelDepartmentGoals = _ModelMonthDepartmentGoals,
|
|
DispersalMonthDepartmentGoals = _DispersalMonthDepartmentGoals,
|
|
DispersalMonthPersonnelGoals = dispersalMonthPersonnelGoal,
|
|
ModelPersonnelGoals = modelPersonnelGoal,
|
|
DispersalMonthPersonnel = personnel,
|
|
DispersalMonthStartDate = DateTime.Parse("2021-08-1").StartOfMonth(),
|
|
};
|
|
|
|
var results =
|
|
_dispersalStrategyService.ExtrapolateFromExistingGoals(extrapolationGoalDispersalData);
|
|
|
|
Assert.AreEqual(12, results.GoalChanges.Count);
|
|
Assert.AreEqual(1, results.GoalDispersalErrors.Count);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(14,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
//All of 3Cs goal changes are request values of 0. This means they have not been assigned any goals. Effectively 3Cs goals have been "Cleared"
|
|
//Because of this we do not want to issue a "DispersedToUserWithoutPermission" error
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
//User 4D has no goal changes, this should not dispatch the DispersedToUserWithoutPermission error
|
|
Assert.AreEqual(0, results.GoalChanges.Count(x => x.PersonId == "4D"));
|
|
Assert.True(results.GoalDispersalErrors.Exists(x =>
|
|
x.EmployeeId == "2B" && x.ErrorType == GoalDispersalError.DispersedToUserWithoutPermission));
|
|
}
|
|
|
|
[Test]
|
|
//Verify this alert is only sent when there are no values > 0
|
|
public void ExtrapolateFromExistingGoals_NewUserRequiresManualEntry_OK()
|
|
{
|
|
var testData = JsonData["NewUserRequiresManualEntry"];
|
|
var personnel = JsonConvert.DeserializeObject<List<AppUser>>(testData["AllPersonnel"].ToString());
|
|
var modelPersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["ModelMonthPersonnelGoals"].ToString());
|
|
var dispersePersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["DispersalMonthPersonnelGoals"].ToString());
|
|
|
|
//All users hasSalesGoal permission except for user 5D
|
|
personnel = personnel.Select(user =>
|
|
{
|
|
user.Departments.First().Role = (user.EmployeeId == "5E") ? Role.Teller : Role.BM;
|
|
return user;
|
|
}).ToList();
|
|
|
|
var modelPersonnelGoal = new PersonnelGoals(10, 2021, 07, personnel);
|
|
modelPersonnelGoal.ApplyAll(modelPersonnelGoalList);
|
|
|
|
//These are all set arbitrarily high so that there is no situation where the newValue is the same as the current value
|
|
var dispersalMonthPersonnelGoal = new PersonnelGoals(10, 2021, 08, personnel);
|
|
dispersalMonthPersonnelGoal.ApplyAll(dispersePersonnelGoalList);
|
|
|
|
var extrapolationGoalDispersalData = new ExtrapolationGoalDispersalData()
|
|
{
|
|
DepartmentId = 10,
|
|
ModelDepartmentGoals = _ModelMonthDepartmentGoals,
|
|
DispersalMonthDepartmentGoals = _DispersalMonthDepartmentGoals,
|
|
DispersalMonthPersonnelGoals = dispersalMonthPersonnelGoal,
|
|
ModelPersonnelGoals = modelPersonnelGoal,
|
|
DispersalMonthPersonnel = personnel,
|
|
DispersalMonthStartDate = DateTime.Parse("2021-08-1").StartOfMonth(),
|
|
};
|
|
|
|
var results =
|
|
_dispersalStrategyService.ExtrapolateFromExistingGoals(extrapolationGoalDispersalData);
|
|
|
|
Assert.AreEqual(12, results.GoalChanges.Count);
|
|
Assert.AreEqual(2, results.GoalDispersalErrors.Count);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(14,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
//All of 3Cs goal changes are request values of 0, this should dispatch because they havesales role
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
//4D has no goal changes, but they should still dispatch this notification because they have hassalesgoal role
|
|
Assert.AreEqual(0, results.GoalChanges.Count(x => x.PersonId == "4D"));
|
|
//5D has no goal changes, but they do not have the hassalesgoal permission, no error should be dispatched
|
|
Assert.AreEqual(0, results.GoalChanges.Count(x => x.PersonId == "5E"));
|
|
Assert.True(results.GoalDispersalErrors.Exists(x =>
|
|
x.EmployeeId == "3C" && x.ErrorType == GoalDispersalError.NewUserRequiresManualEntry));
|
|
Assert.True(results.GoalDispersalErrors.Exists(x =>
|
|
x.EmployeeId == "4D" && x.ErrorType == GoalDispersalError.NewUserRequiresManualEntry));
|
|
}
|
|
|
|
[Test]
|
|
public void ExtrapolateFromExistingGoals_NoPermission_OK()
|
|
{
|
|
//1A has permission
|
|
//2B Has No permission and No Model Month Goals
|
|
//3C Has No permission and No Dispersal Month Goals
|
|
//4D Hs No Permission and No Goals
|
|
var testData = JsonData["NoPermission"];
|
|
var personnel = JsonConvert.DeserializeObject<List<AppUser>>(testData["AllPersonnel"].ToString());
|
|
var modelPersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["ModelMonthPersonnelGoals"].ToString());
|
|
var dispersePersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["DispersalMonthPersonnelGoals"].ToString());
|
|
|
|
//Set All Users to BM
|
|
personnel = personnel.Select(user =>
|
|
{
|
|
user.Departments.First().Role = (user.EmployeeId == "1A") ? Role.BM : Role.Teller;
|
|
return user;
|
|
}).ToList();
|
|
|
|
var modelPersonnelGoal = new PersonnelGoals(10, 2021, 07, personnel);
|
|
modelPersonnelGoal.ApplyAll(modelPersonnelGoalList);
|
|
|
|
//These are all set arbitrarily high so that there is no situation where the newValue is the same as the current value
|
|
var dispersalMonthPersonnelGoal = new PersonnelGoals(10, 2021, 08, personnel);
|
|
dispersalMonthPersonnelGoal.ApplyAll(dispersePersonnelGoalList);
|
|
|
|
var extrapolationGoalDispersalData = new ExtrapolationGoalDispersalData()
|
|
{
|
|
DepartmentId = 10,
|
|
ModelDepartmentGoals = _ModelMonthDepartmentGoals,
|
|
DispersalMonthDepartmentGoals = _DispersalMonthDepartmentGoals,
|
|
DispersalMonthPersonnelGoals = dispersalMonthPersonnelGoal,
|
|
ModelPersonnelGoals = modelPersonnelGoal,
|
|
DispersalMonthPersonnel = personnel,
|
|
DispersalMonthStartDate = DateTime.Parse("2021-08-1").StartOfMonth(),
|
|
};
|
|
|
|
var results =
|
|
_dispersalStrategyService.ExtrapolateFromExistingGoals(extrapolationGoalDispersalData);
|
|
|
|
Assert.AreEqual(11, results.GoalChanges.Count);
|
|
Assert.AreEqual(1, results.GoalDispersalErrors.Count);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "1A").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(48,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.Mortgage).Value);
|
|
//Person 1B Product.Vehicle NewValue is 0 -> Does not save goal because value is already 0
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(14,
|
|
results.GoalChanges.Where(x => x.PersonId == "2B").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(0,
|
|
results.GoalChanges.Where(x => x.PersonId == "3C").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(0, results.GoalChanges.Count(x => x.PersonId == "4D"));
|
|
}
|
|
|
|
[Test]
|
|
public void ExtrapolateFromExistingGoals_NoGoalChangeWhenNewValueSame_Ok()
|
|
{
|
|
var testData = JsonData["NewValueSame"];
|
|
var personnel = JsonConvert.DeserializeObject<List<AppUser>>(testData["AllPersonnel"].ToString());
|
|
var modelPersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["ModelMonthPersonnelGoals"].ToString());
|
|
var dispersePersonnelGoalList =
|
|
JsonConvert.DeserializeObject<List<Goal>>(testData["DispersalMonthPersonnelGoals"].ToString());
|
|
|
|
//Set All Users to BM
|
|
personnel = personnel.Select(user =>
|
|
{
|
|
user.Departments.First().Role = Role.BM;
|
|
return user;
|
|
}).ToList();
|
|
|
|
//Model Personnel Goals and Dispersal Personnel Goal Values are Identical
|
|
var modelPersonnelGoal = new PersonnelGoals(10, 2021, 07, personnel);
|
|
modelPersonnelGoal.ApplyAll(modelPersonnelGoalList);
|
|
var dispersalMonthPersonnelGoal = new PersonnelGoals(10, 2021, 08, personnel);
|
|
dispersalMonthPersonnelGoal.ApplyAll(dispersePersonnelGoalList);
|
|
|
|
var extrapolationGoalDispersalData = new ExtrapolationGoalDispersalData()
|
|
{
|
|
DepartmentId = 10,
|
|
//Department Goals are Identical
|
|
ModelDepartmentGoals = _DispersalMonthDepartmentGoals,
|
|
DispersalMonthDepartmentGoals = _DispersalMonthDepartmentGoals,
|
|
DispersalMonthPersonnelGoals = dispersalMonthPersonnelGoal,
|
|
ModelPersonnelGoals = modelPersonnelGoal,
|
|
DispersalMonthPersonnel = personnel,
|
|
DispersalMonthStartDate = DateTime.Parse("2021-08-1").StartOfMonth(),
|
|
};
|
|
|
|
var results =
|
|
_dispersalStrategyService.ExtrapolateFromExistingGoals(extrapolationGoalDispersalData);
|
|
|
|
Assert.AreEqual(0, results.GoalChanges.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void DefaultWeightedDispersal_OK()
|
|
{
|
|
var users = new List<AppUser>()
|
|
{
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "ABM1",
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
DepartmentId = 10,
|
|
Role = Role.ABM
|
|
}
|
|
}
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "BM1",
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
DepartmentId = 10,
|
|
Role = Role.BM
|
|
}
|
|
}
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "BM2",
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
DepartmentId = 10,
|
|
Role = Role.BM
|
|
}
|
|
}
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "PFO1",
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
DepartmentId = 10,
|
|
Role = Role.PFO
|
|
}
|
|
}
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "PFO2",
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
DepartmentId = 10,
|
|
Role = Role.PFO
|
|
}
|
|
}
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "PFO3",
|
|
Departments = new List<UserDepartment>()
|
|
{
|
|
new UserDepartment()
|
|
{
|
|
DepartmentId = 10,
|
|
Role = Role.PFO
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
var results = _dispersalStrategyService.DefaultWeightedDispersal(
|
|
new DefaultWeightedGoalDispersalData()
|
|
{
|
|
DepartmentId = 10,
|
|
DispersalMonthStartDate = DateTime.Parse("2021-08-01"),
|
|
DispersalMonthPersonnel = users,
|
|
DispersalMonthDepartmentGoals = _DispersalMonthDepartmentGoals
|
|
});
|
|
Assert.AreEqual(24, results.GoalChanges.Count);
|
|
Assert.AreEqual(GoalDispersalStrategy.DefaultDisperseWithWeights, results.Strategy);
|
|
Assert.AreEqual(30,
|
|
results.GoalChanges.Where(x => x.PersonId == "ABM1").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "ABM1").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(3,
|
|
results.GoalChanges.Where(x => x.PersonId == "ABM1").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(6,
|
|
results.GoalChanges.Where(x => x.PersonId == "ABM1").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
|
|
Assert.AreEqual(25,
|
|
results.GoalChanges.Where(x => x.PersonId == "BM1").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "BM1").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(3,
|
|
results.GoalChanges.Where(x => x.PersonId == "BM1").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(5,
|
|
results.GoalChanges.Where(x => x.PersonId == "BM1").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(25,
|
|
results.GoalChanges.Where(x => x.PersonId == "BM2").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "BM2").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(3,
|
|
results.GoalChanges.Where(x => x.PersonId == "BM2").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(5,
|
|
results.GoalChanges.Where(x => x.PersonId == "BM2").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
|
|
Assert.AreEqual(40,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO1").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO1").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO1").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(7,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO1").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(40,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO2").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO2").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO2").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(7,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO2").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
Assert.AreEqual(40,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO3").First(x => x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(2,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO3").First(x => x.Product == Product.Vehicle).Value);
|
|
Assert.AreEqual(4,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO3").First(x => x.Product == Product.CheckCard).Value);
|
|
Assert.AreEqual(7,
|
|
results.GoalChanges.Where(x => x.PersonId == "PFO3").First(x => x.Product == Product.DirectDeposit)
|
|
.Value);
|
|
}
|
|
|
|
[TestCase(10, 2, 3, "PFO")]
|
|
[TestCase(10, 1, 6, "PFO")]
|
|
[TestCase(10, 10, 1, "PFO")]
|
|
[TestCase(10, 2, 2, "BM")]
|
|
[TestCase(10, 1, 3, "BM")]
|
|
[TestCase(10, 10, 1, "BM")]
|
|
[TestCase(100, 2, 8, "ABM")]
|
|
[TestCase(100, 1, 15, "ABM")]
|
|
[TestCase(100, 10, 2, "ABM")]
|
|
public void CalculateDefaultWeightedValue_OK(int value, int numberOfUsersWithRole, int expect,
|
|
string userRoleName)
|
|
{
|
|
var userRole = Role.GetRolesList().Find(x => x.Name == userRoleName);
|
|
|
|
List<Role> allRolesInDept = new List<Role>();
|
|
|
|
for (int i = 0; i < numberOfUsersWithRole; i++)
|
|
{
|
|
allRolesInDept.Add(userRole);
|
|
}
|
|
|
|
Assert.AreEqual(expect,
|
|
_dispersalStrategyService.CalculateDefaultWeightedValue(userRole, value, allRolesInDept));
|
|
}
|
|
|
|
[TestCase(67, 81, 95, 79)]
|
|
[TestCase(35, 58, 8, 5)]
|
|
[TestCase(78, 95, 82, 68)]
|
|
[TestCase(53, 95, 9, 6)]
|
|
[TestCase(31, 78, 58, 24)]
|
|
[TestCase(6, 60, 80, 8)]
|
|
[TestCase(25, 62, 35, 15)]
|
|
[TestCase(96, 6, 61, 976)]
|
|
[TestCase(92, 39, 30, 71)]
|
|
[TestCase(24, 41, 73, 43)]
|
|
[TestCase(0, 100, 50, 0)]
|
|
[TestCase(100, 0, 50, 0)]
|
|
[TestCase(100, 100, 0, 0)]
|
|
[TestCase(1, 100000, 10, 1)]
|
|
public void ExtrapolateAndCreateEmployeeGoalChanges_OK(int modelPersonnelValue, int modelDeptValue,
|
|
int dispersalDeptValue, int expected)
|
|
{
|
|
var modelDeptGoals = new PerProductGoal()
|
|
{
|
|
ProductGoals = new Dictionary<Product, int>()
|
|
{
|
|
{ Product.Vehicle, modelDeptValue },
|
|
}
|
|
};
|
|
|
|
var dispersalDepartmentGoals = new PerProductGoal()
|
|
{
|
|
ProductGoals = new Dictionary<Product, int>()
|
|
{
|
|
{ Product.Vehicle, dispersalDeptValue },
|
|
}
|
|
};
|
|
|
|
var personnel = new List<AppUser>()
|
|
{
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "ABM1",
|
|
Role = Role.ABM
|
|
},
|
|
};
|
|
|
|
var modelPersonnelGoalList = new List<Goal>()
|
|
{
|
|
new Goal()
|
|
{
|
|
Id = 10,
|
|
EmployeeId = "ABM1",
|
|
Product = Product.Vehicle,
|
|
Value = modelPersonnelValue,
|
|
StartDate = DateTime.Parse("2021-07-01").StartOfMonth(),
|
|
EndDate = DateTime.Parse("2021-07-01").EndOfMonth(),
|
|
}
|
|
};
|
|
|
|
var dispersalPersonnelGoalList = new List<Goal>()
|
|
{
|
|
new Goal()
|
|
{
|
|
Id = 10,
|
|
EmployeeId = "ABM1",
|
|
Product = Product.Vehicle,
|
|
//set arbitrarily high so that newValue is never the same
|
|
Value = Int32.MaxValue,
|
|
StartDate = DateTime.Parse("2021-07-01").StartOfMonth(),
|
|
EndDate = DateTime.Parse("2021-07-01").EndOfMonth(),
|
|
}
|
|
};
|
|
|
|
|
|
var modelPersonnelGoal = new PersonnelGoals(10, 2021, 07, personnel);
|
|
modelPersonnelGoal.ApplyAll(modelPersonnelGoalList);
|
|
|
|
//These are all set arbitrarily high so that there is no situation where the newValue is the same as the current value
|
|
var dispersalMonthPersonnelGoal = new PersonnelGoals(10, 2021, 08, personnel);
|
|
dispersalMonthPersonnelGoal.ApplyAll(dispersalPersonnelGoalList);
|
|
|
|
var extrapolationGoalDispersalData = new ExtrapolationGoalDispersalData()
|
|
{
|
|
DepartmentId = 10,
|
|
ModelDepartmentGoals = modelDeptGoals,
|
|
DispersalMonthDepartmentGoals = dispersalDepartmentGoals,
|
|
DispersalMonthPersonnelGoals = dispersalMonthPersonnelGoal,
|
|
ModelPersonnelGoals = modelPersonnelGoal,
|
|
DispersalMonthPersonnel = personnel,
|
|
DispersalMonthStartDate = DateTime.Parse("2021-08-1").StartOfMonth(),
|
|
};
|
|
|
|
var results =
|
|
_dispersalStrategyService.ExtrapolateFromExistingGoals(extrapolationGoalDispersalData);
|
|
|
|
Assert.AreEqual(expected,
|
|
results.GoalChanges.FirstOrDefault(x => x.PersonId == "ABM1" && x.Product == Product.Vehicle).Value);
|
|
}
|
|
|
|
//Employee1 = 10, Employee2 = 15, Employee3 = 7
|
|
[TestCase(10, 100, 100, 150, 70)]
|
|
[TestCase(25, 50, 20, 30, 14)]
|
|
[TestCase(80, 40, 5, 8, 4)]
|
|
[TestCase(33, 57, 18, 26, 13)]
|
|
[TestCase(57, 33, 6, 9, 5)]
|
|
public void ExtrapolateSingleDepartmentProduct_OK(int oldDepartmentGoal, int newDepartmentGoal, int expect1,
|
|
int expect2, int expect3)
|
|
{
|
|
var appUsers = new List<AppUser>()
|
|
{
|
|
new AppUser()
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
EmployeeId = "1"
|
|
},
|
|
new AppUser()
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
EmployeeId = "2"
|
|
},
|
|
new AppUser()
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
EmployeeId = "3"
|
|
}
|
|
};
|
|
|
|
var personnelGoals = new PersonnelGoals(5, DateTime.Today.Month, DateTime.Today.Year, appUsers);
|
|
|
|
personnelGoals.ApplyAll(new List<Goal>()
|
|
{
|
|
new Goal()
|
|
{
|
|
AppUserId = appUsers[0].Id,
|
|
EmployeeId = appUsers[0].EmployeeId,
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 10
|
|
},
|
|
new Goal()
|
|
{
|
|
AppUserId = appUsers[1].Id,
|
|
EmployeeId = appUsers[1].EmployeeId,
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 15
|
|
},
|
|
new Goal()
|
|
{
|
|
AppUserId = appUsers[2].Id,
|
|
EmployeeId = appUsers[2].EmployeeId,
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 7
|
|
},
|
|
new Goal()
|
|
{
|
|
AppUserId = appUsers[0].Id,
|
|
EmployeeId = appUsers[0].EmployeeId,
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
},
|
|
new Goal()
|
|
{
|
|
AppUserId = appUsers[1].Id,
|
|
EmployeeId = appUsers[1].EmployeeId,
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
},
|
|
new Goal()
|
|
{
|
|
AppUserId = appUsers[2].Id,
|
|
EmployeeId = appUsers[2].EmployeeId,
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
}
|
|
});
|
|
|
|
var results = _dispersalStrategyService.ExtrapolateSingleDepartmentProduct(
|
|
new DepartmentGoalExtrapolationRequest()
|
|
{
|
|
DepartmentId = 5,
|
|
DepartmentGoalStartDate = DateTime.Today.StartOfMonth(),
|
|
DepartmentGoalEndDate = DateTime.Today.EndOfMonth(),
|
|
NewDepartmentGoal = newDepartmentGoal,
|
|
OriginalDepartmentGoal = oldDepartmentGoal,
|
|
Product = Product.Mortgage
|
|
}, personnelGoals);
|
|
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(3, results.GoalChanges.Count());
|
|
Assert.AreEqual(expect1,
|
|
results.GoalChanges.Single(x => x.PersonId == "1" && x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(expect2,
|
|
results.GoalChanges.Single(x => x.PersonId == "2" && x.Product == Product.Mortgage).Value);
|
|
Assert.AreEqual(expect3,
|
|
results.GoalChanges.Single(x => x.PersonId == "3" && x.Product == Product.Mortgage).Value);
|
|
}
|
|
|
|
[TestCase(10, 10)]
|
|
[TestCase(1000, 999)]
|
|
public void ExtrapolateSingleDepartmentProduct_NoChanges_OK(int oldDepartmentGoal, int newDepartmentGoal)
|
|
{
|
|
var personnelGoals = new PersonnelGoals(5, DateTime.Today.Month, DateTime.Today.Year, new List<AppUser>()
|
|
{
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "1"
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "2"
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "3"
|
|
},
|
|
});
|
|
|
|
personnelGoals.ApplyAll(new List<Goal>()
|
|
{
|
|
new Goal()
|
|
{
|
|
EmployeeId = "1",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 10
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "2",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 15
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "3",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 7
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "1",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "2",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "3",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
}
|
|
});
|
|
|
|
var results = _dispersalStrategyService.ExtrapolateSingleDepartmentProduct(
|
|
new DepartmentGoalExtrapolationRequest()
|
|
{
|
|
DepartmentId = 5,
|
|
DepartmentGoalStartDate = DateTime.Today.StartOfMonth(),
|
|
DepartmentGoalEndDate = DateTime.Today.EndOfMonth(),
|
|
NewDepartmentGoal = newDepartmentGoal,
|
|
OriginalDepartmentGoal = oldDepartmentGoal,
|
|
Product = Product.Mortgage
|
|
}, personnelGoals);
|
|
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(0, results.GoalChanges.Count());
|
|
}
|
|
|
|
//This is here to prove behaviour, the business may want to change this later
|
|
[TestCase(100, 0)]
|
|
public void ExtrapolateSingleDepartmentProduct_NewValue0ClearsGoals_OK(int oldDepartmentGoal,
|
|
int newDepartmentGoal)
|
|
{
|
|
var personnelGoals = new PersonnelGoals(5, DateTime.Today.Month, DateTime.Today.Year, new List<AppUser>()
|
|
{
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "1"
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "2"
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "3"
|
|
},
|
|
});
|
|
|
|
personnelGoals.ApplyAll(new List<Goal>()
|
|
{
|
|
new Goal()
|
|
{
|
|
EmployeeId = "1",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 10
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "2",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 15
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "3",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 7
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "1",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "2",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "3",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
}
|
|
});
|
|
|
|
var results = _dispersalStrategyService.ExtrapolateSingleDepartmentProduct(
|
|
new DepartmentGoalExtrapolationRequest()
|
|
{
|
|
DepartmentId = 5,
|
|
DepartmentGoalStartDate = DateTime.Today.StartOfMonth(),
|
|
DepartmentGoalEndDate = DateTime.Today.EndOfMonth(),
|
|
NewDepartmentGoal = newDepartmentGoal,
|
|
OriginalDepartmentGoal = oldDepartmentGoal,
|
|
Product = Product.Mortgage
|
|
}, personnelGoals);
|
|
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(3, results.GoalChanges.Count());
|
|
Assert.True(results.GoalChanges.All(x => x.Value == 0));
|
|
}
|
|
|
|
[TestCase(0, 100)]
|
|
public void ExtrapolateSingleDepartmentProduct_OrigValue0CarriesOverExistingGoals_OK(int oldDepartmentGoal,
|
|
int newDepartmentGoal)
|
|
{
|
|
var personnelGoals = new PersonnelGoals(5, DateTime.Today.Month, DateTime.Today.Year, new List<AppUser>()
|
|
{
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "1"
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "2"
|
|
},
|
|
new AppUser()
|
|
{
|
|
EmployeeId = "3"
|
|
},
|
|
});
|
|
|
|
personnelGoals.ApplyAll(new List<Goal>()
|
|
{
|
|
new Goal()
|
|
{
|
|
EmployeeId = "1",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 10
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "2",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 15
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "3",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Mortgage,
|
|
Value = 7
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "1",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "2",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
},
|
|
new Goal()
|
|
{
|
|
EmployeeId = "3",
|
|
DepartmentId = 5,
|
|
StartDate = DateTime.Now.StartOfMonth(),
|
|
EndDate = DateTime.Now.EndOfMonth(),
|
|
Product = Product.Vehicle,
|
|
Value = 1
|
|
}
|
|
});
|
|
|
|
var results = _dispersalStrategyService.ExtrapolateSingleDepartmentProduct(
|
|
new DepartmentGoalExtrapolationRequest()
|
|
{
|
|
DepartmentId = 5,
|
|
DepartmentGoalStartDate = DateTime.Today.StartOfMonth(),
|
|
DepartmentGoalEndDate = DateTime.Today.EndOfMonth(),
|
|
NewDepartmentGoal = newDepartmentGoal,
|
|
OriginalDepartmentGoal = oldDepartmentGoal,
|
|
Product = Product.Mortgage
|
|
}, personnelGoals);
|
|
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(0, results.GoalChanges.Count());
|
|
}
|
|
|
|
[Test]
|
|
public void CustomWeightedDispersal_OK_1()
|
|
{
|
|
var customWeightedDispersalRequest = new CustomWeightedDispersalRequest()
|
|
{
|
|
DepartmentId = 10,
|
|
month = 10,
|
|
year = 2021,
|
|
DispersalProduct = Product.Mortgage,
|
|
DispersalWeightByRole = new Dictionary<string, double>() { { "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 receipt = _dispersalStrategyService.CustomWeightedDispersal(customWeightedDispersalRequest, users, 100);
|
|
|
|
Assert.AreEqual(3, receipt.GoalChanges.Count());
|
|
Assert.True(receipt.GoalChanges.TrueForAll(x => x.StartDate.Equals(DateTime.Parse("2021-10-01"))));
|
|
Assert.NotNull(receipt.GoalChanges.SingleOrDefault(x => x.PersonId == "PFO1"));
|
|
Assert.NotNull(receipt.GoalChanges.SingleOrDefault(x => x.PersonId == "PFO2"));
|
|
Assert.NotNull(receipt.GoalChanges.SingleOrDefault(x => x.PersonId == "PFO3"));
|
|
//25% of 100 -> 25
|
|
//25/3 -> Ceil 8.33 -> 9
|
|
Assert.True(receipt.GoalChanges.All(x => x.Value == 9 && x.Product == Product.Mortgage));
|
|
}
|
|
|
|
[Test]
|
|
public void CustomWeightedDispersal_OK_2()
|
|
{
|
|
var customWeightedDispersalRequest = new CustomWeightedDispersalRequest()
|
|
{
|
|
DepartmentId = 10,
|
|
month = 10,
|
|
year = 2021,
|
|
DispersalProduct = Product.Mortgage,
|
|
DispersalWeightByRole = new Dictionary<string, double>() { { "BM", .10 } }
|
|
};
|
|
|
|
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 receipt = _dispersalStrategyService.CustomWeightedDispersal(customWeightedDispersalRequest, users, 100);
|
|
|
|
Assert.AreEqual(2, receipt.GoalChanges.Count());
|
|
Assert.NotNull(receipt.GoalChanges.SingleOrDefault(x => x.PersonId == "BM1"));
|
|
Assert.NotNull(receipt.GoalChanges.SingleOrDefault(x => x.PersonId == "BM2"));
|
|
|
|
//10% of 100 -> 10
|
|
//10/2 -> Ceil 5 -> 5
|
|
Assert.True(receipt.GoalChanges.All(x => x.Value == 5 && x.Product == Product.Mortgage));
|
|
}
|
|
|
|
[Test]
|
|
public void CustomWeightedDispersal_OK_3()
|
|
{
|
|
var customWeightedDispersalRequest = new CustomWeightedDispersalRequest()
|
|
{
|
|
DepartmentId = 10,
|
|
month = 10,
|
|
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 receipt = _dispersalStrategyService.CustomWeightedDispersal(customWeightedDispersalRequest, users, 100);
|
|
|
|
Assert.AreEqual(5, receipt.GoalChanges.Count());
|
|
Assert.False(receipt.GoalChanges.Any(x => x.PersonId == "ABM1"));
|
|
Assert.AreEqual(2, receipt.GoalChanges.Count(x => x.Value == 5 && x.Product == Product.Mortgage));
|
|
Assert.AreEqual(3, receipt.GoalChanges.Count(x => x.Value == 9 && x.Product == Product.Mortgage));
|
|
}
|
|
|
|
[Test]
|
|
public void CustomWeightedDispersal_RolesDontExist_OK()
|
|
{
|
|
var customWeightedDispersalRequest = new CustomWeightedDispersalRequest()
|
|
{
|
|
DepartmentId = 10,
|
|
month = 10,
|
|
year = 2021,
|
|
DispersalProduct = Product.Mortgage,
|
|
DispersalWeightByRole = new Dictionary<string, double>() { { "BWAT", .10 }, { "BWOW", .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 receipt = _dispersalStrategyService.CustomWeightedDispersal(customWeightedDispersalRequest, users, 100);
|
|
|
|
Assert.AreEqual(0, receipt.GoalChanges.Count());
|
|
}
|
|
|
|
[Test]
|
|
public void CustomWeightedDispersal_NoRolesInDepartment_OK()
|
|
{
|
|
var customWeightedDispersalRequest = new CustomWeightedDispersalRequest()
|
|
{
|
|
DepartmentId = 23,
|
|
month = 10,
|
|
year = 2021,
|
|
DispersalProduct = Product.Mortgage,
|
|
DispersalWeightByRole = new Dictionary<string, double>()
|
|
{ { "PFO", .10 }, { "BM", .25 }, { "BOWOW", .50 } }
|
|
};
|
|
|
|
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 receipt = _dispersalStrategyService.CustomWeightedDispersal(customWeightedDispersalRequest, users, 100);
|
|
|
|
Assert.AreEqual(0, receipt.GoalChanges.Count());
|
|
}
|
|
}
|
|
}
|