diff --git a/Px.Utils.UnitTests/Validation/ContentValidationTests/ContentValidationTests.cs b/Px.Utils.UnitTests/Validation/ContentValidationTests/ContentValidationTests.cs index 94640ad..8711d52 100644 --- a/Px.Utils.UnitTests/Validation/ContentValidationTests/ContentValidationTests.cs +++ b/Px.Utils.UnitTests/Validation/ContentValidationTests/ContentValidationTests.cs @@ -187,6 +187,27 @@ public void ValidateFindStubOrHeadingCalledWithWithMissingHeadingReturnsWithErro Assert.AreEqual(ValidationFeedbackRule.MissingStubAndHeading, result.First().Key.Rule); } + [TestMethod] + public void ValidateFindStubOrHeadingCalledWithDuplicateDimensionsReturnsWithWarning() + { + // Arrange + ValidationStructuredEntry[] entries = ContentValidationFixtures.STRUCTURED_ENTRY_ARRAY_WITH_DUPLICATE_DIMENSION; + ContentValidator validator = new(filename, encoding, entries); + SetValidatorField(validator, "_defaultLanguage", defaultLanguage); + SetValidatorField(validator, "_availableLanguages", availableLanguages); + + // Act + ValidationFeedback? result = ContentValidator.ValidateFindStubAndHeading( + entries, + validator + ); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(1, result.Count); + Assert.AreEqual(ValidationFeedbackRule.DuplicateDimension, result.First().Key.Rule); + } + [TestMethod] public void ValidateFindRecommendedKeysCalledWithMissingDescriptionsReturnsWithWarnings() { diff --git a/Px.Utils.UnitTests/Validation/Fixtures/ContentValidationFixtures.cs b/Px.Utils.UnitTests/Validation/Fixtures/ContentValidationFixtures.cs index 20e5e32..47eca8b 100644 --- a/Px.Utils.UnitTests/Validation/Fixtures/ContentValidationFixtures.cs +++ b/Px.Utils.UnitTests/Validation/Fixtures/ContentValidationFixtures.cs @@ -159,6 +159,15 @@ internal static class ContentValidationFixtures 5, Utils.Validation.ValueType.ListOfStrings); + private static readonly ValidationStructuredEntry headingEntryWithBar = + new(filename, + new ValidationStructuredEntryKey("HEADING"), + "\"bar-time\",\"bar\"", + 10, + [], + 5, + Utils.Validation.ValueType.ListOfStrings); + private static readonly ValidationStructuredEntry headingEnEntry = new(filename, new ValidationStructuredEntryKey("HEADING", "en"), @@ -485,6 +494,14 @@ internal static class ContentValidationFixtures stubEntry, ]; + internal static ValidationStructuredEntry[] STRUCTURED_ENTRY_ARRAY_WITH_DUPLICATE_DIMENSION => + [ + stubEntry, + stubEnEntry, + headingEntryWithBar, + headingEnEntry + ]; + internal static ValidationStructuredEntry[] STRUCTURED_ENTRY_ARRAY_WITH_MULTIPLE_DIMENSION_NAMES => [ multipleStubNamesEntry, diff --git a/Px.Utils/Validation/ContentValidation/ContentValidator.ValidationFunctions.cs b/Px.Utils/Validation/ContentValidation/ContentValidator.ValidationFunctions.cs index ac2e1d5..3ab7e6a 100644 --- a/Px.Utils/Validation/ContentValidation/ContentValidator.ValidationFunctions.cs +++ b/Px.Utils/Validation/ContentValidation/ContentValidator.ValidationFunctions.cs @@ -296,6 +296,25 @@ public sealed partial class ContentValidator $"{language}") ); + feedbackItems.Add(feedback); + } + // Check if any of the heading names are also in the stub names + else if (validator._stubDimensionNames is not null && + validator._headingDimensionNames is not null && + validator._stubDimensionNames.TryGetValue(language, out string[]? stubValue) && + validator._headingDimensionNames.TryGetValue(language, out string[]? headingValue) && + stubValue.Intersect(headingValue).Any()) + { + string[] duplicates = stubValue.Intersect(headingValue).ToArray(); + KeyValuePair feedback = new( + new(ValidationFeedbackLevel.Warning, + ValidationFeedbackRule.DuplicateDimension), + new(validator._filename, + 0, + 0, + $"{language}, {string.Join(", ", duplicates)}") + ); + feedbackItems.Add(feedback); } } diff --git a/Px.Utils/Validation/Enums.cs b/Px.Utils/Validation/Enums.cs index 58873ba..05e1b8d 100644 --- a/Px.Utils/Validation/Enums.cs +++ b/Px.Utils/Validation/Enums.cs @@ -84,6 +84,7 @@ public enum ValidationFeedbackRule AliasFileMissing = 54, DuplicateFileNames = 55, StartOfDataSectionNotFound = 56, - DuplicateEntry = 57 + DuplicateEntry = 57, + DuplicateDimension = 58 } }