737 lines
32 KiB
C#
737 lines
32 KiB
C#
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));
|
|
}
|
|
}
|
|
}
|