Skip to content

Commit

Permalink
Ensure tests build on CoreClr
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremySkinner committed Sep 23, 2015
1 parent 4e48695 commit 313c2f2
Show file tree
Hide file tree
Showing 30 changed files with 125 additions and 68 deletions.
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/AbstractValidatorTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class AbstractValidatorTester {
TestValidator validator;

public AbstractValidatorTester() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
validator = new TestValidator();
}

Expand Down
2 changes: 1 addition & 1 deletion src/FluentValidation.Tests/AssemblyScannerTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace FluentValidation.Tests {
using System.Linq;
using Xunit;

#if !PORTABLETESTS
#if !PORTABLETESTS && !CoreCLR
public class AssemblyScannerTester {

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/CreditCardValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class CreditCardValidatorTests {
TestValidator validator;

public CreditCardValidatorTests() {
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
CultureScope.SetDefaultCulture();

validator = new TestValidator {
v => v.RuleFor(x => x.CreditCard).CreditCard()
Expand Down
11 changes: 11 additions & 0 deletions src/FluentValidation.Tests/CultureScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,31 @@ public class CultureScope : IDisposable {
CultureInfo _originalCulture;

public CultureScope(CultureInfo culture) {
#if !CoreCLR
_originalCulture = Thread.CurrentThread.CurrentCulture;
_originalUiCulture = Thread.CurrentThread.CurrentUICulture;

Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
#endif
}

public CultureScope(string culture) : this(new CultureInfo(culture)) {

}

public void Dispose() {
#if !CoreCLR
Thread.CurrentThread.CurrentCulture = _originalCulture;
Thread.CurrentThread.CurrentUICulture = _originalUiCulture;
#endif
}

public static void SetDefaultCulture() {
#if !CoreCLR
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
#endif
}
}
}
5 changes: 3 additions & 2 deletions src/FluentValidation.Tests/DisplayAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ namespace FluentValidation.Tests {
public class DisplayAttributeTests {

public DisplayAttributeTests() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
}

[Fact]
Expand All @@ -56,7 +55,9 @@ public class DisplayNameTestModel {
[Display(Name = "Foo")]
public string Name1 { get; set; }

#if !CoreCLR
[DisplayName("Bar")]
#endif
public string Name2 { get; set; }
}
}
Expand Down
33 changes: 17 additions & 16 deletions src/FluentValidation.Tests/EmailValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// The latest version of this file can be found at http://www.codeplex.com/FluentValidation
#endregion

using Xunit.Extensions;

namespace FluentValidation.Tests {
using System;
using System.Globalization;
Expand All @@ -29,8 +31,7 @@ public class EmailValidatorTests {
TestValidator validator;

public EmailValidatorTests() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();

validator = new TestValidator {
v => v.RuleFor(x => x.Email).EmailAddress()
Expand Down Expand Up @@ -72,20 +73,20 @@ public void double_period_with_uk_Domain() {
result.IsValid.ShouldBeFalse();
}

[Xunit.Extensions.Theory]
[Xunit.Extensions.InlineData((string)null)]
[Xunit.Extensions.InlineData("[email protected]")]
[Xunit.Extensions.InlineData("[email protected]")]
[Xunit.Extensions.InlineData("[email protected]")]
[Xunit.Extensions.InlineData("\"Abc\\@def\"@example.com")]
[Xunit.Extensions.InlineData("\"Fred Bloggs\"@example.com")]
[Xunit.Extensions.InlineData("\"Joe\\Blow\"@example.com")]
[Xunit.Extensions.InlineData("\"Abc@def\"@example.com")]
[Xunit.Extensions.InlineData("customer/[email protected]")]
[Xunit.Extensions.InlineData("[email protected]")]
[Xunit.Extensions.InlineData("!def!xyz%[email protected]")]
[Xunit.Extensions.InlineData("[email protected]")]
[Xunit.Extensions.InlineData("[email protected]")]
[Theory]
[InlineData((string)null)]
[InlineData("[email protected]")]
[InlineData("[email protected]")]
[InlineData("[email protected]")]
[InlineData("\"Abc\\@def\"@example.com")]
[InlineData("\"Fred Bloggs\"@example.com")]
[InlineData("\"Joe\\Blow\"@example.com")]
[InlineData("\"Abc@def\"@example.com")]
[InlineData("customer/[email protected]")]
[InlineData("[email protected]")]
[InlineData("!def!xyz%[email protected]")]
[InlineData("[email protected]")]
[InlineData("[email protected]")]
public void Valid_email_addresses(string email) {
var result = validator.Validate(new Person {Email = email});
result.IsValid.ShouldBeTrue(string.Format("The email address {0} should be valid", email));
Expand Down
9 changes: 7 additions & 2 deletions src/FluentValidation.Tests/EqualValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// The latest version of this file can be found at http://www.codeplex.com/FluentValidation
#endregion

using System.Reflection;

namespace FluentValidation.Tests {
using System;
using System.Collections;
Expand All @@ -31,8 +33,7 @@ namespace FluentValidation.Tests {
public class EqualValidatorTests {

public EqualValidatorTests() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
}

[Fact]
Expand Down Expand Up @@ -65,7 +66,11 @@ public void Should_store_property_to_compare() {
var descriptor = validator.CreateDescriptor();
var propertyValidator = descriptor.GetValidatorsForMember("Forename").Cast<EqualValidator>().Single();

#if CoreCLR
propertyValidator.MemberToCompare.ShouldEqual(typeof (Person).GetRuntimeProperty("Surname"));
#else
propertyValidator.MemberToCompare.ShouldEqual(typeof(Person).GetProperty("Surname"));
#endif
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/ExactLengthValidatorTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ namespace FluentValidation.Tests {
public class ExactLengthValidatorTester {

public ExactLengthValidatorTester() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/ExclusiveBetweenValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class ExclusiveBetweenValidatorTests {
DateTime toDate;

public ExclusiveBetweenValidatorTests() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
fromDate = new DateTime(2009, 1, 1);
toDate = new DateTime(2009, 12, 31);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public class GreaterThanOrEqualToValidatorTester {
private TestValidator validator;
private const int value = 1;
public GreaterThanOrEqualToValidatorTester() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
validator = new TestValidator(v => v.RuleFor(x => x.Id).GreaterThanOrEqualTo(value));
}

Expand Down
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/GreaterThanValidatorTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public class GreaterThanValidatorTester {
private const int value = 1;

public GreaterThanValidatorTester() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
validator = new TestValidator(v => v.RuleFor(x => x.Id).GreaterThan(value));

}
Expand Down
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/InclusiveBetweenValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class InclusiveBetweenValidatorTests {
DateTime toDate;

public InclusiveBetweenValidatorTests() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
fromDate = new DateTime(2009, 1, 1);
toDate = new DateTime(2009, 12, 31);
}
Expand Down
5 changes: 2 additions & 3 deletions src/FluentValidation.Tests/LengthValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ namespace FluentValidation.Tests {

public class LengthValidatorTests {
public LengthValidatorTests() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
}
CultureScope.SetDefaultCulture();
}

[Fact]
public void When_the_text_is_between_the_range_specified_then_the_validator_should_pass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class LessThanOrEqualToValidatorTester {

public LessThanOrEqualToValidatorTester() {
validator = new TestValidator(v => v.RuleFor(x => x.Id).LessThanOrEqualTo(value));
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
}

[Fact]
Expand Down
9 changes: 6 additions & 3 deletions src/FluentValidation.Tests/LessThanValidatorTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ namespace FluentValidation.Tests {
using Internal;
using Xunit;
using Validators;

using System.Reflection;

public class LessThanValidatorTester {
int value = 1;

public LessThanValidatorTester() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
}

[Fact]
Expand Down Expand Up @@ -88,7 +87,11 @@ public void Should_not_throw_when_value_to_compare_is_of_different_type() {
public void Extracts_property_from_expression() {
var validator = new TestValidator(v => v.RuleFor(x => x.Id).LessThan(x => x.AnotherInt));
var propertyValidator = validator.CreateDescriptor().GetValidatorsForMember("Id").OfType<LessThanValidator>().Single();
#if CoreCLR
propertyValidator.MemberToCompare.ShouldEqual(typeof(Person).GetRuntimeProperty("AnotherInt"));
#else
propertyValidator.MemberToCompare.ShouldEqual(typeof(Person).GetProperty("AnotherInt"));
#endif
}

[Fact]
Expand Down
4 changes: 4 additions & 0 deletions src/FluentValidation.Tests/LocalisedMessagesTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void Dispose()

[Fact]
public void Correctly_assigns_default_localized_error_message() {
#if CoreCLR
Assert.True(false, "Not implemented on coreclr");
#else
var originalCulture = Thread.CurrentThread.CurrentUICulture;
try {
var validator = new TestValidator(v => v.RuleFor(x => x.Surname).NotEmpty());
Expand All @@ -59,6 +62,7 @@ public void Correctly_assigns_default_localized_error_message() {
// Always reset the culture.
Thread.CurrentThread.CurrentUICulture = originalCulture;
}
#endif
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/NotEmptyTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ namespace FluentValidation.Tests {

public class NotEmptyTester {
public NotEmptyTester() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
}

[Fact]
Expand Down
5 changes: 2 additions & 3 deletions src/FluentValidation.Tests/NotEqualValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ namespace FluentValidation.Tests {
using Internal;
using Xunit;
using Validators;

using System.Reflection;

public class NotEqualValidatorTests {
public NotEqualValidatorTests() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/NotNullTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ namespace FluentValidation.Tests {

public class NotNullTester {
public NotNullTester() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions src/FluentValidation.Tests/PredicateValidatorTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class PredicateValidatorTester {
private TestValidator validator;

public PredicateValidatorTester() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureScope.SetDefaultCulture();
validator = new TestValidator {
v => v.RuleFor(x => x.Forename).Must(forename => forename == "Jeremy")
};
Expand Down
15 changes: 13 additions & 2 deletions src/FluentValidation.Tests/PropertyChainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace FluentValidation.Tests {
using System.Linq.Expressions;
using Internal;
using Xunit;
using System.Reflection;


public class PropertyChainTests {
Expand All @@ -32,20 +33,30 @@ public PropertyChainTests() {

[Fact]
public void Calling_ToString_should_construct_string_representation_of_chain() {

#if CoreCLR
chain.Add(typeof(Parent).GetRuntimeProperty("Child"));
chain.Add(typeof(Child).GetRuntimeProperty("GrandChild"));
#else
chain.Add(typeof(Parent).GetProperty("Child"));
chain.Add(typeof(Child).GetProperty("GrandChild"));

#endif
const string expected = "Child.GrandChild";

chain.ToString().ShouldEqual(expected);
}

[Fact]
public void Calling_ToString_should_construct_string_representation_of_chain_with_indexers() {
#if CoreCLR
chain.Add(typeof(Parent).GetRuntimeProperty("Child"));
chain.AddIndexer(0);
chain.Add(typeof(Child).GetRuntimeProperty("GrandChild"));
#else
chain.Add(typeof(Parent).GetProperty("Child"));
chain.AddIndexer(0);
chain.Add(typeof(Child).GetProperty("GrandChild"));

#endif
const string expected = "Child[0].GrandChild";

chain.ToString().ShouldEqual(expected);
Expand Down
5 changes: 2 additions & 3 deletions src/FluentValidation.Tests/RegularExpressionValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public class RegularExpressionValidatorTests {
TestValidator validator3;

public RegularExpressionValidatorTests() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
validator = new TestValidator {
CultureScope.SetDefaultCulture();
validator = new TestValidator {
v => v.RuleFor(x => x.Surname).Matches(@"^\w\d$")
};

Expand Down
Loading

0 comments on commit 313c2f2

Please sign in to comment.