Skip to content

Commit

Permalink
Remove broken support for comparing unrelated types.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremySkinner committed Feb 19, 2020
1 parent b89af81 commit 7ff8ac2
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 354 deletions.
116 changes: 0 additions & 116 deletions src/FluentValidation.Tests/ComparerTester.cs

This file was deleted.

4 changes: 1 addition & 3 deletions src/FluentValidation.Tests/FluentValidation.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Moq" Version="4.7.99" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies"
Version="1.0.0"
PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0-preview.2" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FluentValidation\FluentValidation.csproj" />
Expand Down
33 changes: 14 additions & 19 deletions src/FluentValidation.Tests/LessThanOrEqualToValidatorTester.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#region License
// Copyright (c) Jeremy Skinner (http://www.jeremyskinner.co.uk)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// The latest version of this file can be found at https://github.com/jeremyskinner/FluentValidation
#endregion

Expand All @@ -25,7 +25,7 @@ namespace FluentValidation.Tests {
using Xunit;
using Validators;


public class LessThanOrEqualToValidatorTester {
private TestValidator validator;
private const int value = 1;
Expand All @@ -47,11 +47,6 @@ public class LessThanOrEqualToValidatorTester {
result.IsValid.ShouldBeTrue();
}

[Fact]
public void Should_succeed_when_less_than_input_using_different_types() {
new LessThanOrEqualValidator(100M).IsValid(20D, 100M).ShouldBeTrue();
}

[Fact]
public void Should_succeed_when_equal_to_input() {
var result = validator.Validate(new Person{Id=value});
Expand Down Expand Up @@ -134,4 +129,4 @@ public class LessThanOrEqualToValidatorTester {
result.IsValid.ShouldBeFalse();
}
}
}
}
5 changes: 0 additions & 5 deletions src/FluentValidation.Tests/LessThanValidatorTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public class LessThanValidatorTester {
);
}

[Fact]
public void Should_not_throw_when_value_to_compare_is_of_different_type() {
new LessThanValidator(10M).IsValid(5M, 10).ShouldBeTrue();
}

[Fact]
public void Extracts_property_from_expression() {
var validator = new TestValidator(v => v.RuleFor(x => x.Id).LessThan(x => x.AnotherInt));
Expand Down
12 changes: 3 additions & 9 deletions src/FluentValidation/FluentValidation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
FluentValidation 9 is a major release. Please read the upgrade notes at https://docs.fluentvalidation.net/en/latest/upgrading-to-9.html

Changes in 9.0.0:
* Removed support for netstandard1.1, netstandard1.6 and net45 (net461 still supported)
* Removed support for netstandard1.1 and netstandard1.6
* Default email validation mode now uses the same logic as ASP.NET Core. Previous regex behaviour is opt-in.
* TestHelper advanced mode now has more features (see https://docs.fluentvalidation.net/en/latest/testing.html#advanced-test-extensions)
* Equal/NotEqual now perform ordinal comparison when used with string properties
* Severity can now be set dynamically with a callback
* Removed WithLocalizedMessage (WithMessage that takes a callback is the replacement)
* Removed ResourceName from ValidationFailure
* Removed ResourceName and ResourceType from IStringSource.
* Removed SetCollectionValidator which was deprecated in 8.0
* Removed DelegatingValidator which was deprecated in 8.x.
* Removed SetCollectionValidator which was deprecated in 8.0
* Additional overload of OnAnyFailure that can receive a collection of validation failures
* Remove DisplayAttribute integration and reference to DataAnnotations.
* ComparisonProperty placeholder is now formatted like PropertyName
* Translations of default error messages into other languages are now lazily-loaded
* PropertyValidator.ShouldValidateAsync reanamed to ShouldValidateAsynchronously to remove confusion where the naming suggested this was an async method
* PropertyValidatorContext.Instance renamed to InstanceToValidate for consistency with ValidationContext.
* Removed various methods from MessageFormatter that were deprecated in 8.x

Full release notes can be found at https://github.com/JeremySkinner/FluentValidation/blob/master/Changelog.txt
</PackageReleaseNotes>
Expand All @@ -40,8 +36,6 @@ Full release notes can be found at https://github.com/JeremySkinner/FluentValida
<Compile Include="..\CommonAssemblyInfo.cs" Link="CommonAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies"
Version="1.0.0"
PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0-preview.2" PrivateAssets="All" />
</ItemGroup>
</Project>
85 changes: 0 additions & 85 deletions src/FluentValidation/Internal/Comparer.cs

This file was deleted.

30 changes: 15 additions & 15 deletions src/FluentValidation/Validators/ExclusiveBetweenValidator.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#region License
// Copyright (c) Jeremy Skinner (http://www.jeremyskinner.co.uk)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// The latest version of this file can be found at https://github.com/jeremyskinner/FluentValidation
#endregion

Expand All @@ -26,7 +26,7 @@ public class ExclusiveBetweenValidator : PropertyValidator, IBetweenValidator {
To = to;
From = from;

if (Comparer.GetComparisonResult(to, from) == -1) {
if (to.CompareTo(from) == -1) {
throw new ArgumentOutOfRangeException(nameof(to), "To should be larger than from.");
}
}
Expand All @@ -41,7 +41,7 @@ public class ExclusiveBetweenValidator : PropertyValidator, IBetweenValidator {
// This should not be a failure condition - only a NotNull/NotEmpty should cause a null to fail.
if (propertyValue == null) return true;

if (Comparer.GetComparisonResult(propertyValue, From) <= 0 || Comparer.GetComparisonResult(propertyValue, To) >= 0) {
if (propertyValue.CompareTo(From) <= 0 || propertyValue.CompareTo(To) >= 0) {

context.MessageFormatter
.AppendArgument("From", From)
Expand All @@ -53,4 +53,4 @@ public class ExclusiveBetweenValidator : PropertyValidator, IBetweenValidator {
return true;
}
}
}
}

0 comments on commit 7ff8ac2

Please sign in to comment.