Skip to content

Feature/adr9506 #8

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<PackageVersion>$(Version)$(SemanticVersionSuffix)</PackageVersion>
<Authors>Enterprise Library Open Source Project</Authors>
<Copyright>Copyright © Microsoft 2008</Copyright>
<PackageIconUrl>https://nuget.org/Media/Default/Packages/Unity/2.0/entlib_new_icon_100x100.png</PackageIconUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/EnterpriseLibrary/validation-application-block</PackageProjectUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
Expand Down
2 changes: 1 addition & 1 deletion source/Src/Validation/Validation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\..\package.props" />

<PropertyGroup>
<TargetFrameworks>net45;net46;net47;net472;netstandard2.0;netcoreapp2.0;netcoreapp3.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net45;net46;net47;net472;netstandard2.0;netcoreapp3.0;net6.0;net7.0;net8.0</TargetFrameworks>

<AssemblyVersion>$(MajorVersion).0.0.0</AssemblyVersion>
<FileVersion>$(Version).$(Revision)</FileVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\..\package.props" />

<PropertyGroup>
<TargetFrameworks>net45;net46;net47;net472;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>net45;net46;net47;net472;netcoreapp3.0;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>

<AssemblyVersion>$(MajorVersion).0.0.0</AssemblyVersion>
Expand Down Expand Up @@ -34,7 +34,7 @@

</ItemGroup>

<ItemGroup Condition="!$(TargetFramework.StartsWith('netstandard')) AND !$(TargetFramework.StartsWith('netcoreapp'))">
<ItemGroup Condition="!$(TargetFramework.StartsWith('netstandard')) AND !$(TargetFramework.StartsWith('netcoreapp')) AND '$(TargetFramework)' != 'net8.0'">
<Reference Include="System.Configuration" />
<Reference Include="System.Management" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down
15 changes: 13 additions & 2 deletions source/Tests/Validation.Tests/PropertyValidationFactoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Validator validator
Assert.AreEqual("message1-RuleA", resultsList[0].Message);
}

#if !NET8_0_OR_GREATER
[TestMethod]
public void RequestForValidatorBasedOnConfigurationReturnsAppropriateValidator()
{
Expand All @@ -104,6 +105,8 @@ Validator validator
Assert.AreEqual(1, resultsList.Count);
Assert.AreEqual("message-from-config1", resultsList[0].Message);
}
#endif


[TestMethod]
public void RequestForValidatorBasedOnConfigurationReturnsNullForNonExistingRuleName()
Expand All @@ -115,7 +118,7 @@ Validator validator

Assert.IsNull(validator);
}

#if !NET8_0_OR_GREATER
[TestMethod]
public void RequestForValidatorBasedOnConfigurationWithRulesetReturnsAppropriateValidator()
{
Expand All @@ -134,6 +137,8 @@ Validator validator
Assert.AreEqual("message-from-config2-RuleA", resultsList[1].Message);
}



[TestMethod]
public void RequestForValidatorBasedOnConfigurationWithRulesetAndValidationSpecificationSourceReturnsAppropriateValidator()
{
Expand All @@ -153,7 +158,7 @@ Validator validator
Assert.AreEqual("message-from-config1-RuleA", resultsList[0].Message);
Assert.AreEqual("message-from-config2-RuleA", resultsList[1].Message);
}

#endif
[TestMethod]
public void RequestForValidatorBasedOnAttributesAndConfigurationWithRulesetThroughStaticFacadeReturnsAppropriateValidator()
{
Expand All @@ -169,9 +174,15 @@ Validator validator
ValidationResults validationResults = validator.Validate(objectToTest);

IDictionary<string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);

#if !NET8_0_OR_GREATER
Assert.AreEqual(3, resultsMapping.Count);
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2-RuleA"));
#else
Assert.AreEqual(1, resultsMapping.Count);
#endif

Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleA"));
}

Expand Down
4 changes: 2 additions & 2 deletions source/Tests/Validation.Tests/Validation.Tests.VSTS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\..\package.props" />

<PropertyGroup>
<TargetFrameworks>net47;net472</TargetFrameworks>
<TargetFrameworks>net47;net472;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>

<AssemblyVersion>$(MajorVersion).0.0.0</AssemblyVersion>
Expand Down Expand Up @@ -35,7 +35,7 @@

</ItemGroup>

<ItemGroup Condition="!$(TargetFramework.StartsWith('netstandard')) AND !$(TargetFramework.StartsWith('netcoreapp'))">
<ItemGroup Condition="!$(TargetFramework.StartsWith('netstandard')) AND !$(TargetFramework.StartsWith('netcoreapp')) AND '$(TargetFramework)' != 'net8.0'">
<Reference Include="System.Configuration" />
<Reference Include="System.Management" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down
3 changes: 3 additions & 0 deletions source/Tests/Validation.Tests/ValidationFactoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void CanGetValidatorFromDataAnnotationsAndVABAttributes()
Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithDataAnnotationsAttributes" && vr.Message == "data annotations-only"));
}

#if !NET8_0_OR_GREATER
[TestMethod]
public void CanGetValidatorFromConfigurationOly()
{
Expand All @@ -248,6 +249,8 @@ public void CanGetValidatorFromConfigurationOly()
Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithDataAnnotationsAttributes" && vr.Message == "configuration1"));
Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithVABOnlyAttributes" && vr.Message == "configuration2"));
}
#endif


#endregion
}
Expand Down
53 changes: 34 additions & 19 deletions source/Tests/Validation.Tests/ValidationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ValidationResults validationResults
Assert.AreEqual("message1-RuleA", resultsList[0].Message);
Assert.AreEqual("message1-RuleB", resultsList[1].Message);
}

#if !NET8_0_OR_GREATER
[TestMethod]
public void CanValidateObjectFromConfigWithMultipleRuleSets()
{
Expand All @@ -78,8 +78,7 @@ ValidationResults validationResults
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2"));
}

[TestMethod]
[TestMethod]
public void CanValidateObjectWithDefaultRulesetFromConfiguration()
{
ValidationResults validationResults
Expand All @@ -91,7 +90,7 @@ ValidationResults validationResults
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2"));
}

[TestMethod]
public void CanValidateObjectWithRulesetFromConfiguration()
{
Expand Down Expand Up @@ -120,6 +119,25 @@ ValidationResults validationResults
Assert.IsTrue(resultsMapping.ContainsKey("message2"));
}

[TestMethod]
public void CanValidateObjectWithRulesetFromAttributesAndConfiguration()
{
ValidationResults validationResults
= Validation.Validate(new TestObjectWithFailingAttributesOnProperties(), "RuleA");

Assert.IsFalse(validationResults.IsValid);
IDictionary<string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);
Assert.AreEqual(3, resultsMapping.Count);
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleA"));
}
#endif





[TestMethod]
public void CanValidateObjectWithDefaultRulesetFromAttributesAndConfigurationForTheActualType()
{
Expand All @@ -144,19 +162,7 @@ ValidationResults validationResults
Assert.IsFalse(validationResults.IsValid);
}

[TestMethod]
public void CanValidateObjectWithRulesetFromAttributesAndConfiguration()
{
ValidationResults validationResults
= Validation.Validate(new TestObjectWithFailingAttributesOnProperties(), "RuleA");

Assert.IsFalse(validationResults.IsValid);
IDictionary<string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);
Assert.AreEqual(3, resultsMapping.Count);
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleA"));
}


[TestMethod]
public void CanValidateObjectFromAttributesAndConfigurationWithMultipleRulesets()
Expand All @@ -166,13 +172,22 @@ ValidationResults validationResults

Assert.IsFalse(validationResults.IsValid);
IDictionary<string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);

#if !NET8_0_OR_GREATER
Assert.AreEqual(6, resultsMapping.Count);

Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleB"));

Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2"));

#else
Assert.AreEqual(2, resultsMapping.Count);
Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleB"));
#endif

}

[TestMethod]
Expand Down
48 changes: 47 additions & 1 deletion source/Tests/Validation.Tests/ValidationResultsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.Practices.EnterpriseLibrary.Validation.TestSupport.TestClasses;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -240,7 +241,8 @@ public void CanAddValidationResultsFromCollection()
Assert.IsTrue(resultsMapping.ContainsKey("new 3"));
}

[TestMethod]
#if !NET8_0
[TestMethod]
public void ResultsCanBeSerializedAndDeserialized()
{
BinaryFormatter formatter = new BinaryFormatter();
Expand Down Expand Up @@ -275,5 +277,49 @@ public void ResultsCanBeSerializedAndDeserialized()
Assert.IsNull(resultsList[0].Target);
Assert.IsNull(resultsList[0].Validator);
}
#else
[TestMethod]
public void ResultsCanBeSerializedAndDeserialized()
{
// Initialize the DataContractSerializer for the ValidationResults type.
var serializer = new DataContractSerializer(typeof(ValidationResults));
byte[] serializedResults = null;

// Prepare test data.
ValidationResults validationResults = new ValidationResults();
ValidationResult validationResult = new ValidationResult("message", this, "key", "tag", new MockValidator(false));
validationResults.AddResult(validationResult);

// Serialize the ValidationResults object to a byte array.
using (var binaryStream = new MemoryStream())
{
serializer.WriteObject(binaryStream, validationResults);
serializedResults = binaryStream.ToArray();
}

ValidationResults deserializedValidationResults = null;

// Deserialize the byte array back to a ValidationResults object.
using (var binaryStream = new MemoryStream(serializedResults))
{
deserializedValidationResults = (ValidationResults)serializer.ReadObject(binaryStream);
}

// Assertions to verify deserialization integrity.
Assert.IsNotNull(deserializedValidationResults);
Assert.AreNotSame(validationResults, deserializedValidationResults);

IList<ValidationResult> resultsList = ValidationTestHelper.GetResultsList(deserializedValidationResults);
Assert.AreEqual(1, resultsList.Count);
Assert.IsNotNull(resultsList[0]);
Assert.AreNotSame(validationResult, resultsList[0]);
Assert.AreEqual("message", resultsList[0].Message);
Assert.AreEqual("tag", resultsList[0].Tag);
Assert.AreEqual("key", resultsList[0].Key);
Assert.IsNull(resultsList[0].Target);
Assert.IsNull(resultsList[0].Validator);
}
#endif

}
}
12 changes: 12 additions & 0 deletions source/Tests/Validation.Tests/ValidatorFactoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,15 @@ Validator<TestObjectWithFailingAttributesOnProperties> validator

Assert.IsFalse(validationResults.IsValid);
IDictionary<string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);
#if NET8_0_OR_GREATER
Assert.AreEqual(1, resultsMapping.Count);
#else
Assert.AreEqual(3, resultsMapping.Count);
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1-RuleA"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2-RuleA"));
#endif


Assert.IsTrue(resultsMapping.ContainsKey("message1-RuleA"));
}

Expand All @@ -437,9 +443,15 @@ Validator<TestObjectWithFailingAttributesOnProperties> validator

Assert.IsFalse(validationResults.IsValid);
IDictionary<string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);

#if NET8_0_OR_GREATER
Assert.AreEqual(2, resultsMapping.Count);
#else
Assert.AreEqual(4, resultsMapping.Count);
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config1"));
Assert.IsTrue(resultsMapping.ContainsKey("message-from-config2"));
#endif

Assert.IsTrue(resultsMapping.ContainsKey("message1"));
Assert.IsTrue(resultsMapping.ContainsKey("message2"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public void NegatedFailuresForSameUpperBoundValueUsingExclusiveBoundaryType()
RelativeDateTimeValidator validator = new RelativeDateTimeValidator(-5, DateTimeUnit.Day, RangeBoundaryType.Exclusive,
3, DateTimeUnit.Day, RangeBoundaryType.Exclusive, true);

ValidationResults results = validator.Validate(DateTime.Now.AddDays(3));
ValidationResults results = validator.Validate(DateTime.Now.AddDays(2));

Assert.IsTrue(results.IsValid);
}
Expand Down