Skip to content

Commit

Permalink
Augmented ValidationServiceTests to better highlight the aggregation …
Browse files Browse the repository at this point in the history
…of error code entries
  • Loading branch information
IdrisEviden committed Nov 2, 2024
1 parent 6314a16 commit 4297850
Showing 1 changed file with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public async Task ValidateAsync_EnabledSubsidiaryValidation_NoErrorsFromSubsidia
}

[TestMethod]
public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiaryValidation_AggregatesErrors()
public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiaryValidation_AggregatesErrorsDistinctEntryPerErrorCode()
{
// Arrange
var producerRows = new List<ProducerRow>
Expand All @@ -515,11 +515,11 @@ public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiary

var expectedErrors = new List<ProducerValidationEventIssueRequest>
{
new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", string.Empty, new List<string> { "Error1" })
new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", new List<string> { "Error1" })
};
var validationErrors = new List<ProducerValidationEventIssueRequest>
{
new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", ErrorCodes: new List<string> { "Error1" })
new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", ErrorCodes: new List<string> { "Error1" })
};

_validationServiceProducerRowValidatorMock.Setup(x => x.ProcessRowsForValidationErrors(It.IsAny<List<ProducerRow>>(), It.IsAny<SubsidiaryDetailsResponse>())).Returns(validationErrors);
Expand All @@ -532,7 +532,55 @@ public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiary
.Callback<IEnumerable<ProducerRow>, List<ProducerValidationEventIssueRequest>, List<ProducerValidationEventIssueRequest>, string>((rows, errors, warnings, blob) =>
{
// No warnings
errors.Add(new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", string.Empty, new List<string> { "Error1" }));
errors.Add(new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", new List<string> { "Error2" }));
});

_featureManagerMock.Setup(x => x.IsEnabledAsync(FeatureFlags.EnableSubsidiaryValidationPom)).ReturnsAsync(true);

var service = CreateSystemUnderTest();

// Act
var result = await service.ValidateAsync(producer);

// Assert
result.ValidationWarnings.Should().BeEmpty();
result.ValidationErrors.Count.Should().Be(1);
result.ValidationErrors[0].ErrorCodes.Count.Should().Be(2);
result.ValidationErrors[0].ErrorCodes[0].Should().Be("Error2");
result.ValidationErrors[0].ErrorCodes[1].Should().Be("Error1");
}

[TestMethod]
public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiaryValidation_AggregatesErrorsSingleEntryForSameErrorCode()
{
// Arrange
var producerRows = new List<ProducerRow>
{
ModelGenerator.CreateProducerRow(1)
};

var producer = new Producer(_submissionId, ProducerId, BlobName, producerRows);

var expectedErrors = new List<ProducerValidationEventIssueRequest>
{
new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", new List<string> { "Error1" })
};
var validationErrors = new List<ProducerValidationEventIssueRequest>
{
new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", ErrorCodes: new List<string> { "Error1" })
};

_validationServiceProducerRowValidatorMock.Setup(x => x.ProcessRowsForValidationErrors(It.IsAny<List<ProducerRow>>(), It.IsAny<SubsidiaryDetailsResponse>())).Returns(validationErrors);

// Mocking
_issueCountServiceMock.Setup(x => x.GetRemainingIssueCapacityAsync(It.IsAny<string>())).ReturnsAsync(5);
_issueCountServiceMock.Setup(x => x.GetRemainingIssueCapacityAsync(It.IsAny<string>())).ReturnsAsync(5);

_compositeValidatorMock.Setup(x => x.ValidateAndFetchForIssuesAsync(It.IsAny<IEnumerable<ProducerRow>>(), It.IsAny<List<ProducerValidationEventIssueRequest>>(), It.IsAny<List<ProducerValidationEventIssueRequest>>(), BlobName))
.Callback<IEnumerable<ProducerRow>, List<ProducerValidationEventIssueRequest>, List<ProducerValidationEventIssueRequest>, string>((rows, errors, warnings, blob) =>
{
// No warnings
errors.Add(new ProducerValidationEventIssueRequest("Sub1", "2024Q1", 1, "Prod1", "TypeA", "Large", "WasteTypeA", "CategoryA", "MaterialA", "SubTypeA", "NationA", "NationB", "100", "10", "Any old Blob Name", new List<string> { "Error1" }));
});

_featureManagerMock.Setup(x => x.IsEnabledAsync(FeatureFlags.EnableSubsidiaryValidationPom)).ReturnsAsync(true);
Expand All @@ -544,7 +592,9 @@ public async Task ValidateAsync_EnabledSubsidiaryValidation_ErrorsFromSubsidiary

// Assert
result.ValidationWarnings.Should().BeEmpty();
result.ValidationErrors.Count.Should().Be(2);
result.ValidationErrors.Count.Should().Be(1);
result.ValidationErrors[0].ErrorCodes.Count.Should().Be(1);
result.ValidationErrors[0].ErrorCodes[0].Should().Be("Error1");
}

[TestMethod]
Expand Down

0 comments on commit 4297850

Please sign in to comment.