912 lines
37 KiB
C#
912 lines
37 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.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);
|
|
}
|
|
}
|
|
}
|