Skip to content

Commit

Permalink
Merge pull request fluentassertions#1008 from jnyrup/assertions
Browse files Browse the repository at this point in the history
Improve robustness against localization
  • Loading branch information
jnyrup committed Mar 10, 2019
2 parents f360725 + 776f9db commit 38ab041
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 134 deletions.
12 changes: 7 additions & 5 deletions Tests/Shared.Specs/BasicEquivalencySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net;
using FluentAssertions.Common;
using FluentAssertions.Equivalency;
using FluentAssertions.Extensions;
using Xunit;
using Xunit.Sdk;

Expand Down Expand Up @@ -139,12 +140,12 @@ public void When_asserting_equivalence_on_a_value_type_from_system_it_should_not
// would hit the recursion-depth limit if structural equivalence were attempted.
var date1 = new
{
Property = DateTime.Parse("2011-01-01")
Property = 1.January(2011)
};

var date2 = new
{
Property = DateTime.Parse("2011-01-01")
Property = 1.January(2011)
};

//-----------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -776,8 +777,9 @@ public void When_a_non_property_expression_is_provided_it_should_throw()
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentException>().WithMessage(
"Expression <d.GetType()> cannot be used to select a member.*");
act.Should().Throw<ArgumentException>()
.WithMessage("Expression <d.GetType()> cannot be used to select a member.*")
.And.ParamName.Should().Be("expression");
}

[Fact]
Expand Down Expand Up @@ -1231,7 +1233,7 @@ class ClassWithGuidProperty
public string Property { get; set; } = Guid.NewGuid().ToString();
}

class ClassThatHidesBaseClassProperty: ClassWithGuidProperty
class ClassThatHidesBaseClassProperty : ClassWithGuidProperty
{
public new string[] Property { get; set; }
}
Expand Down
21 changes: 12 additions & 9 deletions Tests/Shared.Specs/CollectionAssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1647,8 +1647,9 @@ public void When_asserting_collections_to_be_equal_but_expected_collection_is_nu
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot compare collection with <null>.*: expectation");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot compare collection with <null>.*")
.And.ParamName.Should().Be("expectation");
}

[Fact]
Expand Down Expand Up @@ -1973,8 +1974,9 @@ public void When_asserting_collections_not_to_be_equal_but_expected_collection_i
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot compare collection with <null>.*: unexpected");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot compare collection with <null>.*")
.And.ParamName.Should().Be("unexpected");
}

[Fact]
Expand Down Expand Up @@ -2309,7 +2311,8 @@ public void When_testing_collections_not_to_be_equivalent_against_null_collectio
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot verify inequivalence against a <null> collection.*");
.WithMessage("Cannot verify inequivalence against a <null> collection.*")
.And.ParamName.Should().Be("unexpected");
}

[Fact]
Expand Down Expand Up @@ -2415,7 +2418,7 @@ public void When_collection_does_not_contain_object_equivalent_of_another_it_sho
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => collection.Should().ContainEquivalentOf(item); ;
Action act = () => collection.Should().ContainEquivalentOf(item);

//-----------------------------------------------------------------------------------------------------------
// Act / Assert
Expand Down Expand Up @@ -2511,7 +2514,7 @@ public void When_collection_does_not_contain_equivalent_because_of_second_proper
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
IEnumerable subject = new []
IEnumerable subject = new[]
{
new Customer
{
Expand Down Expand Up @@ -2543,7 +2546,7 @@ public void When_collection_does_contain_equivalent_by_including_single_property
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
IEnumerable collection = new []
IEnumerable collection = new[]
{
new Customer
{
Expand Down Expand Up @@ -5257,7 +5260,7 @@ public void When_collection_of_types_match_expected_type_exactly_it_should_succe
//-----------------------------------------------------------------------------------------------------------
collection.Should().AllBeOfType<int>();
}

[Fact]
public void When_collection_of_types_and_objects_match_type_excactly_it_should_succeed()
{
Expand Down
11 changes: 5 additions & 6 deletions Tests/Shared.Specs/DateTimeAssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ public void Should_fail_with_descriptive_message_when_asserting_datetime_null_va
// Assert
//-----------------------------------------------------------------------------------------------------------
action.Should().Throw<XunitException>()
.WithMessage(string.Format("Expected <{0}> because we want to test the failure message, but found <null>.",
new DateTime(2016, 06, 04).ToString("yyyy-MM-dd")));
.WithMessage("Expected <2016-06-04> because we want to test the failure message, but found <null>.");
}

#endregion
Expand Down Expand Up @@ -2740,8 +2739,8 @@ public void When_time_is_not_at_exactly_20_minutes_before_another_time_it_should
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTime target = DateTime.Parse("0001/1/1 12:55");
DateTime subject = DateTime.Parse("0001/1/1 12:36");
DateTime target = 1.January(0001).At(12, 55);
DateTime subject = 1.January(0001).At(12, 36);

//-----------------------------------------------------------------------------------------------------------
// Act
Expand All @@ -2762,8 +2761,8 @@ public void When_time_is_exactly_90_seconds_before_another_time_it_should_not_th
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTime target = DateTime.Parse("0001/1/1 12:55:00");
DateTime subject = DateTime.Parse("0001/1/1 12:53:30");
DateTime target = 1.January(0001).At(12, 55);
DateTime subject = 1.January(0001).At(12, 53, 30);

//-----------------------------------------------------------------------------------------------------------
// Act / Assert
Expand Down
8 changes: 4 additions & 4 deletions Tests/Shared.Specs/DateTimeOffsetAssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2827,8 +2827,8 @@ public void When_time_is_not_at_exactly_20_minutes_before_another_time_it_should
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTimeOffset target = DateTimeOffset.Parse("0001/1/1 12:55 +0:00");
DateTimeOffset subject = DateTimeOffset.Parse("0001/1/1 12:36 +0:00");
DateTimeOffset target = 1.January(0001).At(12, 55).ToDateTimeOffset();
DateTimeOffset subject = 1.January(0001).At(12, 36).ToDateTimeOffset();

//-----------------------------------------------------------------------------------------------------------
// Act
Expand All @@ -2853,8 +2853,8 @@ public void When_time_is_exactly_90_seconds_before_another_time_it_should_not_th
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTimeOffset target = DateTimeOffset.Parse("0001/1/1 12:55:00");
DateTimeOffset subject = DateTimeOffset.Parse("0001/1/1 12:53:30");
DateTimeOffset target = 1.January(0001).At(12, 55).ToDateTimeOffset();
DateTimeOffset subject = 1.January(0001).At(12, 53, 30).ToDateTimeOffset();

//-----------------------------------------------------------------------------------------------------------
// Act / Assert
Expand Down
8 changes: 4 additions & 4 deletions Tests/Shared.Specs/DateTimeOffsetValueFormatterSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;

using System.Globalization;
using FluentAssertions.Extensions;
using FluentAssertions.Formatting;
using Xunit;
Expand Down Expand Up @@ -122,7 +122,7 @@ public void When_a_full_date_and_time_is_specified_all_parts_should_be_included_
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
result.Should().Be(dateTime.ToString("<yyyy-MM-dd HH:mm:ss.fff>"));
result.Should().Be("<2012-05-01 20:15:30.318>");
}

[Theory]
Expand All @@ -147,7 +147,7 @@ public void When_datetime_components_are_not_relevant_they_should_not_be_include
// Arrange
//-----------------------------------------------------------------------------------------------------------
var formatter = new DateTimeOffsetValueFormatter();
var value = DateTime.Parse(actual);
var value = DateTime.Parse(actual, CultureInfo.InvariantCulture);

//-----------------------------------------------------------------------------------------------------------
// Act
Expand Down Expand Up @@ -182,7 +182,7 @@ public void When_datetimeoffset_components_are_not_relevant_they_should_not_be_i
// Arrange
//-----------------------------------------------------------------------------------------------------------
var formatter = new DateTimeOffsetValueFormatter();
var value = DateTimeOffset.Parse(actual);
var value = DateTimeOffset.Parse(actual, CultureInfo.InvariantCulture);

//-----------------------------------------------------------------------------------------------------------
// Act
Expand Down
19 changes: 10 additions & 9 deletions Tests/Shared.Specs/EventAssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace FluentAssertions.Specs
[Collection("EventMonitoring")]
public class EventAssertionSpecs
{
#region ShouldRaise
#region ShouldRaise

[Fact]
public void When_asserting_an_event_that_doesnt_exist_it_should_throw()
Expand Down Expand Up @@ -442,9 +442,9 @@ public void When_a_non_conventional_event_with_many_specific_arguments_was_not_r
}
}

#endregion
#endregion

#region Should(Not)RaisePropertyChanged events
#region Should(Not)RaisePropertyChanged events

[Fact]
public void When_a_property_changed_event_was_raised_for_the_expected_property_it_should_not_throw()
Expand Down Expand Up @@ -633,9 +633,9 @@ public void When_monitoring_a_class_it_should_be_possible_to_attach_to_additiona
}
}

#endregion
#endregion

#region Precondition Checks
#region Precondition Checks

[Fact]
public void When_monitoring_a_null_object_it_should_throw()
Expand All @@ -653,7 +653,8 @@ public void When_monitoring_a_null_object_it_should_throw()
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage("Cannot monitor the events of a <null> object*");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot monitor the events of a <null> object*");
}

[Fact]
Expand All @@ -678,9 +679,9 @@ public void When_nesting_monitoring_requests_scopes_should_be_isolated()
}
}

#endregion
#endregion

#region Metadata
#region Metadata

[Fact]
public void When_monitoring_an_object_it_should_monitor_all_the_events_it_exposes()
Expand Down Expand Up @@ -885,7 +886,7 @@ public void When_an_object_raises_two_events_it_should_provide_the_data_about_th
}
}

#endregion
#endregion

public class ClassThatRaisesEventsItself : IEventRaisingInterface
{
Expand Down
10 changes: 6 additions & 4 deletions Tests/Shared.Specs/GenericCollectionAssertionOfStringSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,9 @@ public void When_asserting_collections_not_to_be_equal_but_expected_collection_i
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot compare collection with <null>.*: unexpected");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot compare collection with <null>.*")
.And.ParamName.Should().Be("unexpected");
}

[Fact]
Expand Down Expand Up @@ -894,8 +895,9 @@ public void When_asserting_collections_to_be_equal_but_expected_collection_is_nu
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot compare collection with <null>.*: expectation");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot compare collection with <null>.*")
.And.ParamName.Should().Be("expectation");
}

[Fact]
Expand Down
6 changes: 4 additions & 2 deletions Tests/Shared.Specs/GenericCollectionAssertionsSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,8 @@ public void When_asserting_the_items_in_a_collection_are_ordered_and_the_specifi
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot assert collection ordering without specifying a property*propertyExpression*");
.WithMessage("Cannot assert collection ordering without specifying a property*")
.And.ParamName.Should().Be("propertyExpression");
}

[Fact]
Expand All @@ -973,7 +974,8 @@ public void When_asserting_the_items_in_a_collection_are_ordered_and_the_given_c
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot assert collection ordering without specifying a comparer*comparer*");
.WithMessage("Cannot assert collection ordering without specifying a comparer*")
.And.ParamName.Should().Be("comparer");
}

[Fact]
Expand Down
20 changes: 12 additions & 8 deletions Tests/Shared.Specs/GenericDictionaryAssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,9 @@ public void When_asserting_dictionaries_to_be_equal_but_expected_dictionary_is_n
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot compare dictionary with <null>.*: expected");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot compare dictionary with <null>.*")
.And.ParamName.Should().Be("expected");
}

[Fact]
Expand Down Expand Up @@ -1366,8 +1367,9 @@ public void When_asserting_dictionaries_not_to_be_equal_but_expected_dictionary_
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot compare dictionary with <null>.*: unexpected");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot compare dictionary with <null>.*")
.And.ParamName.Should().Be("unexpected");
}

[Fact]
Expand Down Expand Up @@ -2508,8 +2510,9 @@ public void When_asserting_dictionary_contains_key_value_pairs_but_expected_key_
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot compare dictionary with <null>.*: expected");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot compare dictionary with <null>.*")
.And.ParamName.Should().Be("expected");
}

[Fact]
Expand Down Expand Up @@ -2584,8 +2587,9 @@ public void When_asserting_dictionary_does_not_contain_key_value_pairs_but_expec
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot compare dictionary with <null>.*: items");
act.Should().Throw<ArgumentNullException>()
.WithMessage("Cannot compare dictionary with <null>.*")
.And.ParamName.Should().Be("items");
}

[Fact]
Expand Down

0 comments on commit 38ab041

Please sign in to comment.