Skip to content

Commit

Permalink
Consistency of error-log format
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGHippo committed Jul 3, 2024
1 parent 195c86d commit 0178e84
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private List<Qualification> FilterQualificationsByDate(int startDateMonth, int s
var splitQualificationDate = qualificationDate.Split('-');
if (splitQualificationDate.Length != 2)
{
logger.LogError("Found qualification date {QualificationDate} with unexpected format", qualificationDate);
logger.LogError("Qualification date {QualificationDate} has unexpected format", qualificationDate);
return (false, 0, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,43 @@ public async Task GetFilteredQualifications_ContentfulClientThrowsException_Retu
filteredQualifications.Should().BeEmpty();
}

[TestMethod]
public async Task GetFilteredQualifications_DataContainsInvalidDateFormat_LogsError()
{
var results = new ContentfulCollection<Qualification>
{
Items = new[]
{
new Qualification(
"EYQ-123",
"test",
"NCFE",
4,
"Sep15", // We expect Mmm-yy, e.g. "Sep-15"
"Aug-19",
"abc/123/987",
"requirements")
}
};

var mockContentfulClient = new Mock<IContentfulClient>();
mockContentfulClient.Setup(x => x.GetEntries(
It.IsAny<QueryBuilder<Qualification>>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync(results);

var mockQueryBuilder = new MockQueryBuilder();
var mockLogger = new Mock<ILogger<ContentfulContentFilterService>>();
var filterService = new ContentfulContentFilterService(mockContentfulClient.Object, mockLogger.Object)
{
QueryBuilder = mockQueryBuilder
};

await filterService.GetFilteredQualifications(4, 5, 2016);

mockLogger.VerifyError("Qualification date Sep15 has unexpected format");
}

[TestMethod]
public async Task GetFilteredQualifications_DataContainsInvalidMonth_LogsError()
{
Expand Down

0 comments on commit 0178e84

Please sign in to comment.