-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get cash import by date Entity Framework rewrite #155
base: development
Are you sure you want to change the base?
Changes from all commits
bfb331e
ab5dd26
41d2b38
7a34b30
0f1b955
2e01203
d27d0ab
4b4cadf
fbf8daa
e100a92
714be5e
a4e6142
b83b275
e9291f5
de56f89
f9a7e32
7b37f99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ dotnet_naming_symbols.public_symbols.applicable_accessibilities = public | |
|
||
#Parameters should be camel case | ||
dotnet_naming_style.camel_case_style.capitalization = camel_case | ||
dotnet_naming_rule.local_objects_must_be_camel_case.severity = error | ||
dotnet_naming_rule.local_objects_must_be_camel_case.severity = suggestion | ||
dotnet_naming_rule.local_objects_must_be_camel_case.symbols = local_objects | ||
dotnet_naming_rule.local_objects_must_be_camel_case.style = camel_case_Style | ||
dotnet_naming_symbols.local_objects.applicable_kinds = parameter | ||
|
@@ -136,3 +136,6 @@ dotnet_diagnostic.CA1001.severity = none | |
|
||
#Can reassign collections | ||
dotnet_diagnostic.CA2227.severity = none | ||
|
||
# No need to mark CLSCompliant | ||
dotnet_diagnostic.CA1014.severity = none | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't something we've been following so this suppresses the warnings |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -552,95 +552,6 @@ await _classUnderTest | |
} | ||
#endregion | ||
|
||
#region Cash Import | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are redundant now because we're no longer calling this method for this report - there's nothing to mock and the new test runs directly against the Dockerised db |
||
[Fact] | ||
public async Task ReportGatewayCashImportByDateMethodReturnsTheTableDataThatItHasReceivedFromTheHFSDatabaseContext() | ||
{ | ||
// arrange | ||
DateTime startDate = RandomGen.DateTimeBetween(); | ||
DateTime endDate = RandomGen.DateTimeBetween(); | ||
|
||
var dbContextResult = new List<string[]>() | ||
{ | ||
new string[] { "some_header", "other_header" } | ||
}; | ||
|
||
_mockHFSDatabaseContext | ||
.Setup( | ||
g => g.GetCashImportByDateAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>()) | ||
) | ||
.ReturnsAsync(dbContextResult); | ||
|
||
// act | ||
var tableDataFromGW = await _classUnderTest | ||
.GetCashImportByDateAsync(startDate, endDate) | ||
.ConfigureAwait(false); | ||
|
||
// assert | ||
tableDataFromGW.Should().IsSameOrEqualTo(dbContextResult); | ||
} | ||
|
||
[Fact] | ||
public async Task ReportGatewayCashImportByDateMethodThrowsWhenHFSDatabaseContextThrows() | ||
{ | ||
// arrange | ||
DateTime startDate = RandomGen.DateTimeBetween(); | ||
DateTime endDate = RandomGen.DateTimeBetween(); | ||
|
||
var errorMessage = "An existing connection was forcibly closed by the remote host."; | ||
var dbContextResult = new ConnectionResetException(errorMessage); | ||
|
||
_mockHFSDatabaseContext | ||
.Setup(g => g.GetCashImportByDateAsync( | ||
It.IsAny<DateTime>(), | ||
It.IsAny<DateTime>() | ||
)) | ||
.ThrowsAsync(dbContextResult); | ||
|
||
// act | ||
Func<Task> getReportDataGWCall = async () => await _classUnderTest | ||
.GetCashImportByDateAsync(startDate, endDate) | ||
.ConfigureAwait(false); | ||
|
||
// assert | ||
await getReportDataGWCall.Should().ThrowAsync<ConnectionResetException>().WithMessage(errorMessage).ConfigureAwait(false); | ||
} | ||
|
||
[Fact] | ||
public async Task ReportGatewayCashImportByDateMethodCallsTheHFSDatabaseContextCashImportByDateMethodWithExpectedParameters() | ||
{ | ||
// arrange | ||
DateTime startDate = RandomGen.DateTimeBetween(); | ||
DateTime endDate = RandomGen.DateTimeBetween(); | ||
|
||
var dbContextResult = new List<string[]>() | ||
{ | ||
new string[] { "some_header", "other_header" } | ||
}; | ||
|
||
_mockHFSDatabaseContext | ||
.Setup( | ||
g => g.GetCashImportByDateAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>()) | ||
) | ||
.ReturnsAsync(dbContextResult); | ||
|
||
// act | ||
await _classUnderTest | ||
.GetCashImportByDateAsync(startDate, endDate) | ||
.ConfigureAwait(false); | ||
|
||
// assert | ||
_mockHFSDatabaseContext | ||
.Verify( | ||
g => g.GetCashImportByDateAsync( | ||
It.Is<DateTime>(s => s == startDate), | ||
It.Is<DateTime>(e => e == endDate) | ||
), | ||
Times.Once | ||
); | ||
} | ||
#endregion | ||
|
||
#region Housing Benefit Academy | ||
[Fact] | ||
public async Task ReportGatewayHousingBenefitAcademyByYearMethodReturnsTheTableDataThatItHasReceivedFromTheHFSDatabaseContext() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,15 @@ public GetCashImportByDateTests(BaseContextTest baseContextTest) | |
cleanups.Add(() => ClearTable.ClearTables(_context, tablesToClear)); | ||
} | ||
|
||
/* | ||
* Given a list of cash loads and linked SSMiniTransactions | ||
* When GetCashImportByDate is called with a date range | ||
* Then it should return a list of cash imports by date | ||
* within the date range | ||
* with the total value of transactions for each rent group | ||
* with summed totals across all rent groups | ||
*/ | ||
|
||
[Fact] | ||
public async void ShouldGetCashImportByDate() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expanded this test to insert multiple records and ensure that they were being grouped and aggregated correctly |
||
{ | ||
|
@@ -42,52 +51,59 @@ public async void ShouldGetCashImportByDate() | |
var ReportStartDate = DateTime.Now - TimeSpan.FromDays(7); | ||
var ReportEndDate = DateTime.Now; | ||
|
||
var TestDateThisWeek = DateTime.Now.Date - TimeSpan.FromDays(4); // Within the report date range | ||
|
||
var cashDumpFileNameFileName = $"CashFile{TestDateThisWeek:yyyyMMdd}.dat"; | ||
var cashDumpFileName = _fixture.Build<UPCashDumpFileName>() | ||
.Without(x => x.Id) | ||
.With(x => x.FileName, cashDumpFileNameFileName) | ||
.Create(); | ||
_context.UpCashDumpFileNames.Add(cashDumpFileName); | ||
_context.SaveChanges(); | ||
|
||
var cashDump = _fixture.Build<UPCashDump>() | ||
.Without(x => x.Id) | ||
.With(x => x.UpCashDumpFileName, cashDumpFileName) | ||
.With(x => x.FullText, CashDumpTestData.FullText()) | ||
.Create(); | ||
_context.Add(cashDump); | ||
_context.SaveChanges(); | ||
|
||
var cashLoad = _fixture.Build<UPCashLoad>() | ||
.Without(x => x.Id) | ||
.With(x => x.UpCashDump, cashDump) | ||
.Create(); | ||
_context.UpCashLoads.Add(cashLoad); | ||
_context.SaveChanges(); | ||
// Within the report date range | ||
var testDatesThisWeek = new List<DateTime> | ||
{ | ||
DateTime.Now.Date - TimeSpan.FromDays(4), | ||
DateTime.Now.Date - TimeSpan.FromDays(3) | ||
}; | ||
|
||
var ssminiList = new List<SSMiniTransaction>(); | ||
var allCashLoads = new List<UPCashLoad>(); | ||
var allSsminis = new List<SSMiniTransaction>(); | ||
var rentGroups = new List<string> { "GPS", "HGF", "HRA", "LMW", "LSC", "TAG", "TAH", "TRA", "ZZZZZZ", "SSSSSS" }; | ||
|
||
foreach (var rentGroup in rentGroups) | ||
foreach (var testDate in testDatesThisWeek) | ||
{ | ||
foreach (var isSuspense in new List<bool> { true, false }) | ||
{ | ||
var ssminiPre = _fixture.Build<SSMiniTransaction>() | ||
.With(x => x.PostDate, TestDateThisWeek) | ||
.With(x => x.OriginDesc, "Cash File") | ||
.With(x => x.RentGroup, rentGroup[..3]); | ||
if (isSuspense) | ||
ssminiPre.With(x => x.TagRef, "SSSSSS"); | ||
|
||
var ssmini = ssminiPre.Create(); | ||
_context.Add(ssmini); | ||
ssminiList.Add(ssmini); | ||
} | ||
var cashDumpFileNameFileName = $"CashFile{testDate:yyyyMMdd}.dat"; | ||
var cashDumpFileName = _fixture.Build<UPCashDumpFileName>() | ||
.Without(x => x.Id) | ||
.With(x => x.FileName, cashDumpFileNameFileName) | ||
.Create(); | ||
_context.UpCashDumpFileNames.Add(cashDumpFileName); | ||
_context.SaveChanges(); | ||
|
||
var cashDump = _fixture.Build<UPCashDump>() | ||
.Without(x => x.Id) | ||
.With(x => x.UpCashDumpFileName, cashDumpFileName) | ||
.With(x => x.FullText, CashDumpTestData.FullText()) | ||
.Create(); | ||
_context.Add(cashDump); | ||
_context.SaveChanges(); | ||
|
||
var cashLoad = _fixture.Build<UPCashLoad>() | ||
.Without(x => x.Id) | ||
.With(x => x.UpCashDump, cashDump) | ||
.Create(); | ||
_context.UpCashLoads.Add(cashLoad); | ||
_context.SaveChanges(); | ||
allCashLoads.Add(cashLoad); | ||
|
||
foreach (var rentGroup in rentGroups) | ||
foreach (var isSuspense in new List<bool> { true, false }) | ||
{ | ||
var ssminiPre = _fixture.Build<SSMiniTransaction>() | ||
.With(x => x.PostDate, testDate) | ||
.With(x => x.OriginDesc, "Cash File") | ||
.With(x => x.RentGroup, rentGroup[..3]); | ||
if (isSuspense) | ||
ssminiPre.With(x => x.TagRef, "SSSSSS"); | ||
|
||
var ssmini = ssminiPre.Create(); | ||
_context.Add(ssmini); | ||
allSsminis.Add(ssmini); | ||
} | ||
_context.SaveChanges(); | ||
} | ||
_context.SaveChanges(); | ||
|
||
|
||
// Act | ||
IList<string[]> reportCashImport = await testClass.GetCashImportByDateAsync(ReportStartDate, ReportEndDate).ConfigureAwait(false); | ||
|
@@ -107,22 +123,31 @@ public async void ShouldGetCashImportByDate() | |
reportData.Add(rowData); | ||
} | ||
|
||
Assert.Single(reportData); | ||
var reportItem = reportData[0]; | ||
|
||
var expectedDateString = TestDateThisWeek.ToString("dd/MM/yyyy"); | ||
Assert.Equal(expectedDateString, reportItem["Date"]); | ||
|
||
var expectedIfsTotal = ssminiList.Sum(x => x.RealValue); | ||
Assert.Equal(expectedIfsTotal, decimal.Parse((string) reportItem["IFSTotal"])); | ||
Assert.Equal(-cashLoad.AmountPaid, decimal.Parse((string) reportItem["FileTotal"])); | ||
|
||
// Report should have one col per rent group with the total value of transactions for that group | ||
foreach (var rentGroup in rentGroups) | ||
Assert.Equal( | ||
ssminiList.Where(x => x.RentGroup == rentGroup[..3] && x.TagRef != "SSSSSS") | ||
.Sum(x => x.RealValue), | ||
decimal.Parse((string) reportItem[rentGroup]) | ||
); | ||
// One row created per cash load date | ||
Assert.Equal(testDatesThisWeek.Count, reportData.Count); | ||
foreach (var reportItem in reportData) | ||
{ | ||
var relatedSsminis = allSsminis | ||
.Where(x => x.PostDate == DateTime.ParseExact(s: (string) reportItem["Date"], format: "dd/MM/yyyy", null)) | ||
.ToList(); | ||
|
||
var expectedIfsTotal = relatedSsminis | ||
.Sum(x => x.RealValue); | ||
Assert.Equal(expectedIfsTotal, decimal.Parse((string) reportItem["IFSTotal"])); | ||
|
||
// File total is set from the related cash load | ||
var matchingCashLoads = allCashLoads | ||
.Where(x => x.AmountPaid == -decimal.Parse((string) reportItem["FileTotal"])) | ||
.ToList(); | ||
Assert.Single(matchingCashLoads); | ||
|
||
// Report should have one col per rent group with the total value of transactions for that group | ||
foreach (var rentGroup in rentGroups) | ||
Assert.Equal( | ||
relatedSsminis.Where(x => x.RentGroup == rentGroup[..3] && x.TagRef != "SSSSSS") | ||
.Sum(x => x.RealValue), | ||
decimal.Parse((string) reportItem[rentGroup]) | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ public async Task ShouldLoadHousingFilesAndReturnStepResponse() | |
|
||
// Assert | ||
result.Continue.Should().BeTrue(); | ||
result.NextStepTime.Should().BeCloseTo(DateTime.Now.AddSeconds(_waitDuration)); | ||
result.NextStepTime.Should().BeCloseTo(DateTime.Now.AddSeconds(_waitDuration), 500); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was flaky on CircleCI |
||
|
||
_mockBatchLogGateway.Verify(x => x.CreateAsync(It.IsAny<string>(), false), Times.Once); | ||
_mockUpHousingCashLoadGateway.Verify(x => x.LoadHousingFiles(), Times.Once); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
|
||
namespace HousingFinanceInterimApi.V1.Domain.Reports; | ||
|
||
|
||
public class CashImportReport | ||
{ | ||
public DateTime Date { get; set; } | ||
public decimal IFSTotal { get; set; } | ||
public decimal FileTotal { get; set; } | ||
public decimal GPS { get; set; } | ||
public decimal HGF { get; set; } | ||
public decimal HRA { get; set; } | ||
public decimal LMW { get; set; } | ||
public decimal LSC { get; set; } | ||
public decimal TAG { get; set; } | ||
public decimal TAH { get; set; } | ||
public decimal TRA { get; set; } | ||
public decimal ZZZZZZ { get; set; } | ||
public decimal SSSSSS { get; set; } | ||
|
||
public string[] ToRow() | ||
{ | ||
return new string[] { | ||
Date.ToString("dd/MM/yyyy"), IFSTotal.ToString("0.00"), FileTotal.ToString("0.00"), | ||
GPS.ToString("0.00"), HGF.ToString("0.00"), HRA.ToString("0.00"), LMW.ToString("0.00"), | ||
LSC.ToString("0.00"), TAG.ToString("0.00"), TAH.ToString("0.00"), TRA.ToString("0.00"), | ||
ZZZZZZ.ToString("0.00"), SSSSSS.ToString("0.00") | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We consistently don't follow this rule, so it just gets in the way