diff --git a/Tests/FluentAssertions.Specs/Numeric/ComparableSpecs.cs b/Tests/FluentAssertions.Specs/Numeric/ComparableSpecs.cs index 3d4c618b5c..0f8c4be5f8 100644 --- a/Tests/FluentAssertions.Specs/Numeric/ComparableSpecs.cs +++ b/Tests/FluentAssertions.Specs/Numeric/ComparableSpecs.cs @@ -7,603 +7,602 @@ namespace FluentAssertions.Specs.Numeric { public class ComparableSpecs { - #region Be / Not Be - - [Fact] - public void When_two_instances_are_equal_it_should_succeed() + public class Be { - // Arrange - var subject = new EquatableOfInt(1); - var other = new EquatableOfInt(1); - - // Act / Assert - subject.Should().Be(other); - } - - [Fact] - public void When_two_instances_are_the_same_reference_but_are_not_considered_equal_it_should_not_succeed() - { - // Arrange - var subject = new SameInstanceIsNotEqualClass(); - var other = subject; - - // Act - Action act = () => subject.Should().Be(other, "they have the same property values"); - - // Assert - act - .Should().Throw() - .WithMessage( - "Expected*SameInstanceIsNotEqualClass*because they have the same property values, but found*SameInstanceIsNotEqualClass*."); - } + [Fact] + public void When_two_instances_are_equal_it_should_succeed() + { + // Arrange + var subject = new EquatableOfInt(1); + var other = new EquatableOfInt(1); - [Fact] - public void When_two_instances_are_not_equal_it_should_throw() - { - // Arrange - var subject = new EquatableOfInt(1); - var other = new EquatableOfInt(2); - - // Act - Action act = () => subject.Should().Be(other, "they have the same property values"); - - // Assert - act - .Should().Throw() - .WithMessage( - "Expected*2*because they have the same property values, but found*1*."); - } + // Act / Assert + subject.Should().Be(other); + } - [Fact] - public void When_two_references_to_the_same_instance_are_not_equal_it_should_succeed() - { - // Arrange - var subject = new SameInstanceIsNotEqualClass(); - var other = subject; + [Fact] + public void When_two_instances_are_the_same_reference_but_are_not_considered_equal_it_should_not_succeed() + { + // Arrange + var subject = new SameInstanceIsNotEqualClass(); + var other = subject; + + // Act + Action act = () => subject.Should().Be(other, "they have the same property values"); + + // Assert + act + .Should().Throw() + .WithMessage( + "Expected*SameInstanceIsNotEqualClass*because they have the same property values, but found*SameInstanceIsNotEqualClass*."); + } + + [Fact] + public void When_two_instances_are_not_equal_it_should_throw() + { + // Arrange + var subject = new EquatableOfInt(1); + var other = new EquatableOfInt(2); - // Act - Action act = () => subject.Should().NotBe(other); + // Act + Action act = () => subject.Should().Be(other, "they have the same property values"); - // Assert - act.Should().NotThrow(); + // Assert + act + .Should().Throw() + .WithMessage( + "Expected*2*because they have the same property values, but found*1*."); + } } - [Fact] - public void When_two_equal_objects_should_not_be_equal_it_should_throw() + public class NotBe { - // Arrange - var subject = new EquatableOfInt(1); - var other = new EquatableOfInt(1); - - // Act - Action act = () => subject.Should().NotBe(other, "they represent different things"); - - // Assert - act - .Should().Throw() - .WithMessage( - "*Did not expect subject to be equal to*1*because they represent different things.*"); - } - - [Fact] - public void When_two_unequal_objects_should_not_be_equal_it_should_not_throw() - { - // Arrange - var subject = new EquatableOfInt(1); - var other = new EquatableOfInt(2); + [Fact] + public void When_two_references_to_the_same_instance_are_not_equal_it_should_succeed() + { + // Arrange + var subject = new SameInstanceIsNotEqualClass(); + var other = subject; - // Act - Action act = () => subject.Should().NotBe(other); + // Act + Action act = () => subject.Should().NotBe(other); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - #endregion + [Fact] + public void When_two_equal_objects_should_not_be_equal_it_should_throw() + { + // Arrange + var subject = new EquatableOfInt(1); + var other = new EquatableOfInt(1); + + // Act + Action act = () => subject.Should().NotBe(other, "they represent different things"); + + // Assert + act + .Should().Throw() + .WithMessage( + "*Did not expect subject to be equal to*1*because they represent different things.*"); + } + + [Fact] + public void When_two_unequal_objects_should_not_be_equal_it_should_not_throw() + { + // Arrange + var subject = new EquatableOfInt(1); + var other = new EquatableOfInt(2); - #region BeEquivalentTo - [Fact] - public void When_two_instances_are_equivalent_it_should_succeed() - { - // Arrange - var subject = new ComparableCustomer(42); - var expected = new CustomerDTO(42); + // Act + Action act = () => subject.Should().NotBe(other); - // Act / Assert - subject.Should().BeEquivalentTo(expected); + // Assert + act.Should().NotThrow(); + } } - [Fact] - public void When_two_instances_are_compared_it_should_allow_chaining() + public class BeEquivalentTo { - // Arrange - var subject = new ComparableCustomer(42); - var expected = new CustomerDTO(42); + [Fact] + public void When_two_instances_are_equivalent_it_should_succeed() + { + // Arrange + var subject = new ComparableCustomer(42); + var expected = new CustomerDTO(42); - // Act / Assert - subject.Should().BeEquivalentTo(expected) - .And.NotBeNull(); - } + // Act / Assert + subject.Should().BeEquivalentTo(expected); + } - [Fact] - public void When_two_instances_are_compared_with_config_it_should_allow_chaining() - { - // Arrange - var subject = new ComparableCustomer(42); - var expected = new CustomerDTO(42); + [Fact] + public void When_two_instances_are_compared_it_should_allow_chaining() + { + // Arrange + var subject = new ComparableCustomer(42); + var expected = new CustomerDTO(42); - // Act / Assert - subject.Should().BeEquivalentTo(expected, opt => opt) - .And.NotBeNull(); - } + // Act / Assert + subject.Should().BeEquivalentTo(expected) + .And.NotBeNull(); + } - [Fact] - public void When_two_instances_are_equivalent_due_to_exclusion_it_should_succeed() - { - // Arrange - var subject = new ComparableCustomer(42); - var expected = new AnotherCustomerDTO(42) + [Fact] + public void When_two_instances_are_compared_with_config_it_should_allow_chaining() { - SomeOtherProperty = 1337 - }; + // Arrange + var subject = new ComparableCustomer(42); + var expected = new CustomerDTO(42); - // Act / Assert - subject.Should().BeEquivalentTo(expected, - options => options.Excluding(x => x.SomeOtherProperty), - "they have the same property values"); - } + // Act / Assert + subject.Should().BeEquivalentTo(expected, opt => opt) + .And.NotBeNull(); + } - [Fact] - public void When_injecting_a_null_config_it_should_throw() - { - // Arrange - var subject = new ComparableCustomer(42); - var expected = new AnotherCustomerDTO(42); + [Fact] + public void When_two_instances_are_equivalent_due_to_exclusion_it_should_succeed() + { + // Arrange + var subject = new ComparableCustomer(42); + var expected = new AnotherCustomerDTO(42) + { + SomeOtherProperty = 1337 + }; + + // Act / Assert + subject.Should().BeEquivalentTo(expected, + options => options.Excluding(x => x.SomeOtherProperty), + "they have the same property values"); + } + + [Fact] + public void When_injecting_a_null_config_it_should_throw() + { + // Arrange + var subject = new ComparableCustomer(42); + var expected = new AnotherCustomerDTO(42); - // Act - Action act = () => subject.Should().BeEquivalentTo(expected, config: null); + // Act + Action act = () => subject.Should().BeEquivalentTo(expected, config: null); - // Assert - act.Should().ThrowExactly() - .WithParameterName("config"); - } + // Assert + act.Should().ThrowExactly() + .WithParameterName("config"); + } - [Fact] - public void When_two_instances_are_not_equivalent_it_should_throw() - { - // Arrange - var subject = new ComparableCustomer(42); - var expected = new AnotherCustomerDTO(42) + [Fact] + public void When_two_instances_are_not_equivalent_it_should_throw() { - SomeOtherProperty = 1337 - }; + // Arrange + var subject = new ComparableCustomer(42); + var expected = new AnotherCustomerDTO(42) + { + SomeOtherProperty = 1337 + }; - // Act - Action act = () => subject.Should().BeEquivalentTo(expected, "they have the same property values"); + // Act + Action act = () => subject.Should().BeEquivalentTo(expected, "they have the same property values"); - // Assert - act - .Should().Throw() - .WithMessage( - "Expectation has property subject.SomeOtherProperty*that the other object does not have*"); + // Assert + act + .Should().Throw() + .WithMessage( + "Expectation has property subject.SomeOtherProperty*that the other object does not have*"); + } } - #endregion - - #region BeNull / NotBeNull - [Fact] - public void When_assertion_an_instance_to_be_null_and_it_is_null_it_should_succeed() + public class BeNull { - // Arrange - ComparableOfString subject = null; + [Fact] + public void When_assertion_an_instance_to_be_null_and_it_is_null_it_should_succeed() + { + // Arrange + ComparableOfString subject = null; - // Act - Action action = () => - subject.Should().BeNull(); + // Act + Action action = () => + subject.Should().BeNull(); - // Assert - action.Should().NotThrow(); - } + // Assert + action.Should().NotThrow(); + } - [Fact] - public void When_assertion_an_instance_to_be_null_and_it_is_not_null_it_should_throw() - { - // Arrange - var subject = new ComparableOfString(""); + [Fact] + public void When_assertion_an_instance_to_be_null_and_it_is_not_null_it_should_throw() + { + // Arrange + var subject = new ComparableOfString(""); - // Act - Action action = () => - subject.Should().BeNull(); + // Act + Action action = () => + subject.Should().BeNull(); - // Assert - action.Should().Throw() - .WithMessage("Expected subject to be , but found*"); + // Assert + action.Should().Throw() + .WithMessage("Expected subject to be , but found*"); + } } - [Fact] - public void When_assertion_an_instance_not_to_be_null_and_it_is_not_null_it_should_succeed() + public class NotBeNull { - // Arrange - var subject = new ComparableOfString(""); + [Fact] + public void When_assertion_an_instance_not_to_be_null_and_it_is_not_null_it_should_succeed() + { + // Arrange + var subject = new ComparableOfString(""); - // Act - Action action = () => - subject.Should().NotBeNull(); + // Act + Action action = () => + subject.Should().NotBeNull(); - // Assert - action.Should().NotThrow(); - } + // Assert + action.Should().NotThrow(); + } - [Fact] - public void When_assertion_an_instance_not_to_be_null_and_it_is_null_it_should_throw() - { - // Arrange - ComparableOfString subject = null; + [Fact] + public void When_assertion_an_instance_not_to_be_null_and_it_is_null_it_should_throw() + { + // Arrange + ComparableOfString subject = null; - // Act - Action action = () => - subject.Should().NotBeNull(); + // Act + Action action = () => + subject.Should().NotBeNull(); - // Assert - action.Should().Throw() - .WithMessage("Expected subject not to be ."); + // Assert + action.Should().Throw() + .WithMessage("Expected subject not to be ."); + } } - #endregion - - #region BeInRange - - [Fact] - public void When_assertion_an_instance_to_be_in_a_certain_range_and_it_is_it_should_succeed() + public class BeInRange { - // Arrange - var subject = new ComparableOfInt(1); + [Fact] + public void When_assertion_an_instance_to_be_in_a_certain_range_and_it_is_it_should_succeed() + { + // Arrange + var subject = new ComparableOfInt(1); - // Act - Action action = () => - subject.Should().BeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); + // Act + Action action = () => + subject.Should().BeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); - // Assert - action.Should().NotThrow(); - } + // Assert + action.Should().NotThrow(); + } - [Fact] - public void When_asserting_an_instance_to_be_in_a_certain_range_and_it_is_it_should_succeed() - { - // Arrange - var subject = new ComparableOfInt(2); + [Fact] + public void When_asserting_an_instance_to_be_in_a_certain_range_and_it_is_it_should_succeed() + { + // Arrange + var subject = new ComparableOfInt(2); - // Act - Action action = () => - subject.Should().BeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); + // Act + Action action = () => + subject.Should().BeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); - // Assert - action.Should().NotThrow(); - } + // Assert + action.Should().NotThrow(); + } - [Fact] - public void When_assertion_an_instance_to_be_in_a_certain_range_but_it_is_not_it_should_throw() - { - // Arrange - var subject = new ComparableOfInt(3); + [Fact] + public void When_assertion_an_instance_to_be_in_a_certain_range_but_it_is_not_it_should_throw() + { + // Arrange + var subject = new ComparableOfInt(3); - // Act - Action action = () => - subject.Should().BeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); + // Act + Action action = () => + subject.Should().BeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); - // Assert - action.Should().Throw() - .WithMessage("Expected subject to be between*and*, but found *."); + // Assert + action.Should().Throw() + .WithMessage("Expected subject to be between*and*, but found *."); + } } - #endregion - - #region NotBeInRange - - [Fact] - public void When_assertion_an_instance_to_not_be_in_a_certain_range_and_it_is_not_it_should_succeed() + public class NotBeInRange { - // Arrange - var subject = new ComparableOfInt(3); + [Fact] + public void When_assertion_an_instance_to_not_be_in_a_certain_range_and_it_is_not_it_should_succeed() + { + // Arrange + var subject = new ComparableOfInt(3); - // Act - Action action = () => - subject.Should().NotBeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); + // Act + Action action = () => + subject.Should().NotBeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); - // Assert - action.Should().NotThrow(); - } + // Assert + action.Should().NotThrow(); + } - [Fact] - public void When_assertion_an_instance_to_not_be_in_a_certain_range_but_it_is_not_it_should_throw() - { - // Arrange - var subject = new ComparableOfInt(2); + [Fact] + public void When_assertion_an_instance_to_not_be_in_a_certain_range_but_it_is_not_it_should_throw() + { + // Arrange + var subject = new ComparableOfInt(2); - // Act - Action action = () => - subject.Should().NotBeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); + // Act + Action action = () => + subject.Should().NotBeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); - // Assert - action.Should().Throw() - .WithMessage("Expected subject to not be between*and*, but found *."); - } + // Assert + action.Should().Throw() + .WithMessage("Expected subject to not be between*and*, but found *."); + } - [Fact] - public void When_asserting_an_instance_to_not_be_in_a_certain_range_but_it_is_not_it_should_throw() - { - // Arrange - var subject = new ComparableOfInt(1); + [Fact] + public void When_asserting_an_instance_to_not_be_in_a_certain_range_but_it_is_not_it_should_throw() + { + // Arrange + var subject = new ComparableOfInt(1); - // Act - Action action = () => - subject.Should().NotBeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); + // Act + Action action = () => + subject.Should().NotBeInRange(new ComparableOfInt(1), new ComparableOfInt(2)); - // Assert - action.Should().Throw(); + // Assert + action.Should().Throw(); + } } - #endregion - - #region Be Ranked As Equal To - - [Fact] - public void When_subect_is_ranked_equal_to_another_subject_and_that_is_expected_it_should_not_throw() + public class BeRankedEquallyTo { - // Arrange - var subject = new ComparableOfString("Hello"); - var other = new ComparableOfString("Hello"); + [Fact] + public void When_subect_is_ranked_equal_to_another_subject_and_that_is_expected_it_should_not_throw() + { + // Arrange + var subject = new ComparableOfString("Hello"); + var other = new ComparableOfString("Hello"); - // Act - Action act = () => subject.Should().BeRankedEquallyTo(other); + // Act + Action act = () => subject.Should().BeRankedEquallyTo(other); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_subject_is_not_ranked_equal_to_another_subject_but_that_is_expected_it_should_throw() - { - // Arrange - var subject = new ComparableOfString("42"); - var other = new ComparableOfString("Forty two"); + [Fact] + public void When_subject_is_not_ranked_equal_to_another_subject_but_that_is_expected_it_should_throw() + { + // Arrange + var subject = new ComparableOfString("42"); + var other = new ComparableOfString("Forty two"); - // Act - Action act = () => subject.Should().BeRankedEquallyTo(other, "they represent the same number"); + // Act + Action act = () => subject.Should().BeRankedEquallyTo(other, "they represent the same number"); - // Assert - act - .Should().Throw() - .WithMessage("Expected subject*42*to be ranked as equal to*Forty two*because they represent the same number."); + // Assert + act + .Should().Throw() + .WithMessage( + "Expected subject*42*to be ranked as equal to*Forty two*because they represent the same number."); + } } - #endregion - - #region Not Be Ranked As Equal To - - [Fact] - public void When_subect_is_not_ranked_equal_to_another_subject_and_that_is_expected_it_should_not_throw() + public class NotBeRankedEquallyTo { - // Arrange - var subject = new ComparableOfString("Hello"); - var other = new ComparableOfString("Hi"); + [Fact] + public void When_subect_is_not_ranked_equal_to_another_subject_and_that_is_expected_it_should_not_throw() + { + // Arrange + var subject = new ComparableOfString("Hello"); + var other = new ComparableOfString("Hi"); - // Act - Action act = () => subject.Should().NotBeRankedEquallyTo(other); + // Act + Action act = () => subject.Should().NotBeRankedEquallyTo(other); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_subject_is_ranked_equal_to_another_subject_but_that_is_not_expected_it_should_throw() - { - // Arrange - var subject = new ComparableOfString("Lead"); - var other = new ComparableOfString("Lead"); + [Fact] + public void When_subject_is_ranked_equal_to_another_subject_but_that_is_not_expected_it_should_throw() + { + // Arrange + var subject = new ComparableOfString("Lead"); + var other = new ComparableOfString("Lead"); - // Act - Action act = () => subject.Should().NotBeRankedEquallyTo(other, "they represent different concepts"); + // Act + Action act = () => subject.Should().NotBeRankedEquallyTo(other, "they represent different concepts"); - // Assert - act - .Should().Throw() - .WithMessage("Expected subject*Lead*not to be ranked as equal to*Lead*because they represent different concepts."); + // Assert + act + .Should().Throw() + .WithMessage( + "Expected subject*Lead*not to be ranked as equal to*Lead*because they represent different concepts."); + } } - #endregion - - #region Be Less Than - - [Fact] - public void When_subject_is_less_than_another_subject_and_that_is_expected_it_should_not_throw() + public class BeLessThan { - // Arrange - var subject = new ComparableOfString("City"); - var other = new ComparableOfString("World"); + [Fact] + public void When_subject_is_less_than_another_subject_and_that_is_expected_it_should_not_throw() + { + // Arrange + var subject = new ComparableOfString("City"); + var other = new ComparableOfString("World"); - // Act - Action act = () => subject.Should().BeLessThan(other); + // Act + Action act = () => subject.Should().BeLessThan(other); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_subject_is_not_less_than_another_subject_but_that_is_expected_it_should_throw() - { - // Arrange - var subject = new ComparableOfString("World"); - var other = new ComparableOfString("City"); + [Fact] + public void When_subject_is_not_less_than_another_subject_but_that_is_expected_it_should_throw() + { + // Arrange + var subject = new ComparableOfString("World"); + var other = new ComparableOfString("City"); - // Act - Action act = () => subject.Should().BeLessThan(other, "a city is smaller than the world"); + // Act + Action act = () => subject.Should().BeLessThan(other, "a city is smaller than the world"); - // Assert - act - .Should().Throw() - .WithMessage("Expected subject*World*to be less than*City*because a city is smaller than the world."); - } + // Assert + act + .Should().Throw() + .WithMessage("Expected subject*World*to be less than*City*because a city is smaller than the world."); + } - [Fact] - public void When_subject_is_equal_to_another_subject_and_expected_to_be_less_it_should_throw() - { - // Arrange - var subject = new ComparableOfString("City"); - var other = new ComparableOfString("City"); + [Fact] + public void When_subject_is_equal_to_another_subject_and_expected_to_be_less_it_should_throw() + { + // Arrange + var subject = new ComparableOfString("City"); + var other = new ComparableOfString("City"); - // Act - Action act = () => subject.Should().BeLessThan(other); + // Act + Action act = () => subject.Should().BeLessThan(other); - // Assert - act.Should().Throw(); + // Assert + act.Should().Throw(); + } } - #endregion - - #region Be Less Than Or Equal To - - [Fact] - public void When_subject_is_greater_than_another_subject_and_that_is_not_expected_it_should_throw() + public class BeLessThanOrEqualTo { - // Arrange - var subject = new ComparableOfString("World"); - var other = new ComparableOfString("City"); + [Fact] + public void When_subject_is_greater_than_another_subject_and_that_is_not_expected_it_should_throw() + { + // Arrange + var subject = new ComparableOfString("World"); + var other = new ComparableOfString("City"); - // Act - Action act = () => subject.Should().BeLessThanOrEqualTo(other, "we want to order them"); + // Act + Action act = () => subject.Should().BeLessThanOrEqualTo(other, "we want to order them"); - // Assert - act - .Should().Throw() - .WithMessage("Expected subject*World*to be less than or equal to*City*because we want to order them."); - } + // Assert + act + .Should().Throw() + .WithMessage("Expected subject*World*to be less than or equal to*City*because we want to order them."); + } - [Fact] - public void When_subject_is_equal_to_another_subject_and_that_is_expected_it_should_not_throw() - { - // Arrange - var subject = new ComparableOfString("World"); - var other = new ComparableOfString("World"); + [Fact] + public void When_subject_is_equal_to_another_subject_and_that_is_expected_it_should_not_throw() + { + // Arrange + var subject = new ComparableOfString("World"); + var other = new ComparableOfString("World"); - // Act - Action act = () => subject.Should().BeLessThanOrEqualTo(other); + // Act + Action act = () => subject.Should().BeLessThanOrEqualTo(other); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_subject_is_less_than_another_subject_and_less_than_or_equal_is_expected_it_should_not_throw() - { - // Arrange - var subject = new ComparableOfString("City"); - var other = new ComparableOfString("World"); + [Fact] + public void When_subject_is_less_than_another_subject_and_less_than_or_equal_is_expected_it_should_not_throw() + { + // Arrange + var subject = new ComparableOfString("City"); + var other = new ComparableOfString("World"); - // Act - Action act = () => subject.Should().BeLessThanOrEqualTo(other); + // Act + Action act = () => subject.Should().BeLessThanOrEqualTo(other); - // Assert - act.Should().NotThrow(); + // Assert + act.Should().NotThrow(); + } } - #endregion - - #region Be Greater Than - - [Fact] - public void When_subject_is_greater_than_another_subject_and_that_is_expected_it_should_not_throw() + public class BeGreaterThan { - // Arrange - var subject = new ComparableOfString("efg"); - var other = new ComparableOfString("abc"); + [Fact] + public void When_subject_is_greater_than_another_subject_and_that_is_expected_it_should_not_throw() + { + // Arrange + var subject = new ComparableOfString("efg"); + var other = new ComparableOfString("abc"); - // Act - Action act = () => subject.Should().BeGreaterThan(other); + // Act + Action act = () => subject.Should().BeGreaterThan(other); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_subject_is_equal_to_another_subject_and_expected_to_be_greater_it_should_throw() - { - // Arrange - var subject = new ComparableOfString("efg"); - var other = new ComparableOfString("efg"); + [Fact] + public void When_subject_is_equal_to_another_subject_and_expected_to_be_greater_it_should_throw() + { + // Arrange + var subject = new ComparableOfString("efg"); + var other = new ComparableOfString("efg"); - // Act - Action act = () => subject.Should().BeGreaterThan(other); + // Act + Action act = () => subject.Should().BeGreaterThan(other); - // Assert - act.Should().Throw(); - } + // Assert + act.Should().Throw(); + } - [Fact] - public void When_subject_is_not_greater_than_another_subject_but_that_is_expected_it_should_throw() - { - // Arrange - var subject = new ComparableOfString("abc"); - var other = new ComparableOfString("def"); + [Fact] + public void When_subject_is_not_greater_than_another_subject_but_that_is_expected_it_should_throw() + { + // Arrange + var subject = new ComparableOfString("abc"); + var other = new ComparableOfString("def"); - // Act - Action act = () => subject.Should().BeGreaterThan(other, "'a' is smaller then 'e'"); + // Act + Action act = () => subject.Should().BeGreaterThan(other, "'a' is smaller then 'e'"); - // Assert - act - .Should().Throw() - .WithMessage("Expected subject*abc*to be greater than*def*because 'a' is smaller then 'e'."); + // Assert + act + .Should().Throw() + .WithMessage("Expected subject*abc*to be greater than*def*because 'a' is smaller then 'e'."); + } } - #endregion - - #region Be Greater Than Or Equal To - - [Fact] - public void When_subject_is_less_than_another_subject_and_that_is_not_expected_it_should_throw() + public class BeGreaterThanOrEqualTo { - // Arrange - var subject = new ComparableOfString("abc"); - var other = new ComparableOfString("def"); + [Fact] + public void When_subject_is_less_than_another_subject_and_that_is_not_expected_it_should_throw() + { + // Arrange + var subject = new ComparableOfString("abc"); + var other = new ComparableOfString("def"); - // Act - Action act = () => subject.Should().BeGreaterThanOrEqualTo(other, "'d' is bigger then 'a'"); + // Act + Action act = () => subject.Should().BeGreaterThanOrEqualTo(other, "'d' is bigger then 'a'"); - // Assert - act - .Should().Throw() - .WithMessage("Expected subject*abc*to be greater than or equal to*def*because 'd' is bigger then 'a'."); - } + // Assert + act + .Should().Throw() + .WithMessage("Expected subject*abc*to be greater than or equal to*def*because 'd' is bigger then 'a'."); + } - [Fact] - public void When_subject_is_equal_to_another_subject_and_that_is_equal_or_greater_it_should_not_throw() - { - // Arrange - var subject = new ComparableOfString("def"); - var other = new ComparableOfString("def"); + [Fact] + public void When_subject_is_equal_to_another_subject_and_that_is_equal_or_greater_it_should_not_throw() + { + // Arrange + var subject = new ComparableOfString("def"); + var other = new ComparableOfString("def"); - // Act - Action act = () => subject.Should().BeGreaterThanOrEqualTo(other); + // Act + Action act = () => subject.Should().BeGreaterThanOrEqualTo(other); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_subject_is_greater_than_another_subject_and_greater_than_or_equal_is_expected_it_should_not_throw() - { - // Arrange - var subject = new ComparableOfString("xyz"); - var other = new ComparableOfString("abc"); + [Fact] + public void When_subject_is_greater_than_another_subject_and_greater_than_or_equal_is_expected_it_should_not_throw() + { + // Arrange + var subject = new ComparableOfString("xyz"); + var other = new ComparableOfString("abc"); - // Act - Action act = () => subject.Should().BeGreaterThanOrEqualTo(other); + // Act + Action act = () => subject.Should().BeGreaterThanOrEqualTo(other); - // Assert - act.Should().NotThrow(); + // Assert + act.Should().NotThrow(); + } } - - #endregion } public class ComparableOfString : IComparable diff --git a/Tests/FluentAssertions.Specs/Numeric/NullableNumericAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Numeric/NullableNumericAssertionSpecs.cs index 1ce92ca196..72011ee1a6 100644 --- a/Tests/FluentAssertions.Specs/Numeric/NullableNumericAssertionSpecs.cs +++ b/Tests/FluentAssertions.Specs/Numeric/NullableNumericAssertionSpecs.cs @@ -6,205 +6,222 @@ namespace FluentAssertions.Specs.Numeric { public class NullableNumericAssertionSpecs { - [Fact] - public void Should_succeed_when_asserting_nullable_numeric_value_with_value_to_have_a_value() - { - // Arrange - int? nullableInteger = 1; - - // Act / Assert - nullableInteger.Should().HaveValue(); - } - - [Fact] - public void Should_succeed_when_asserting_nullable_numeric_value_with_value_to_not_be_null() + public class HaveValue { - // Arrange - int? nullableInteger = 1; + [Fact] + public void Should_succeed_when_asserting_nullable_numeric_value_with_value_to_have_a_value() + { + // Arrange + int? nullableInteger = 1; - // Act / Assert - nullableInteger.Should().NotBeNull(); - } + // Act / Assert + nullableInteger.Should().HaveValue(); + } - [Fact] - public void Should_fail_when_asserting_nullable_numeric_value_without_a_value_to_have_a_value() - { - // Arrange - int? nullableInteger = null; + [Fact] + public void Should_fail_when_asserting_nullable_numeric_value_without_a_value_to_have_a_value() + { + // Arrange + int? nullableInteger = null; - // Act - Action act = () => nullableInteger.Should().HaveValue(); + // Act + Action act = () => nullableInteger.Should().HaveValue(); - // Assert - act.Should().Throw(); - } + // Assert + act.Should().Throw(); + } - [Fact] - public void Should_fail_when_asserting_nullable_numeric_value_without_a_value_to_not_be_null() - { - // Arrange - int? nullableInteger = null; + [Fact] + public void + Should_fail_with_descriptive_message_when_asserting_nullable_numeric_value_without_a_value_to_have_a_value() + { + // Arrange + int? nullableInteger = null; - // Act - Action act = () => nullableInteger.Should().NotBeNull(); + // Act + Action act = () => nullableInteger.Should().HaveValue("because we want to test the failure {0}", "message"); - // Assert - act.Should().Throw(); + // Assert + act.Should().Throw() + .WithMessage("Expected a value because we want to test the failure message."); + } } - [Fact] - public void Should_fail_with_descriptive_message_when_asserting_nullable_numeric_value_without_a_value_to_have_a_value() + public class NotHaveValue { - // Arrange - int? nullableInteger = null; + [Fact] + public void Should_succeed_when_asserting_nullable_numeric_value_without_a_value_to_not_have_a_value() + { + // Arrange + int? nullableInteger = null; - // Act - Action act = () => nullableInteger.Should().HaveValue("because we want to test the failure {0}", "message"); + // Act / Assert + nullableInteger.Should().NotHaveValue(); + } - // Assert - act.Should().Throw() - .WithMessage("Expected a value because we want to test the failure message."); - } + [Fact] + public void Should_fail_when_asserting_nullable_numeric_value_with_a_value_to_not_have_a_value() + { + // Arrange + int? nullableInteger = 1; - [Fact] - public void Should_fail_with_descriptive_message_when_asserting_nullable_numeric_value_without_a_value_to_not_be_null() - { - // Arrange - int? nullableInteger = null; + // Act + Action act = () => nullableInteger.Should().NotHaveValue(); - // Act - Action act = () => nullableInteger.Should().NotBeNull("because we want to test the failure {0}", "message"); + // Assert + act.Should().Throw(); + } - // Assert - act.Should().Throw() - .WithMessage("Expected a value because we want to test the failure message."); - } + [Fact] + public void When_nullable_value_with_unexpected_value_is_found_it_should_throw_with_message() + { + // Arrange + int? nullableInteger = 1; - [Fact] - public void Should_succeed_when_asserting_nullable_numeric_value_without_a_value_to_not_have_a_value() - { - // Arrange - int? nullableInteger = null; + // Act + Action action = () => nullableInteger.Should().NotHaveValue("it was {0} expected", "not"); - // Act / Assert - nullableInteger.Should().NotHaveValue(); + // Assert + action + .Should().Throw() + .WithMessage("Did not expect a value because it was not expected, but found 1."); + } } - [Fact] - public void Should_succeed_when_asserting_nullable_numeric_value_without_a_value_to_be_null() + public class NotBeNull { - // Arrange - int? nullableInteger = null; + [Fact] + public void Should_succeed_when_asserting_nullable_numeric_value_with_value_to_not_be_null() + { + // Arrange + int? nullableInteger = 1; - // Act / Assert - nullableInteger.Should().BeNull(); - } + // Act / Assert + nullableInteger.Should().NotBeNull(); + } - [Fact] - public void Should_fail_when_asserting_nullable_numeric_value_with_a_value_to_not_have_a_value() - { - // Arrange - int? nullableInteger = 1; + [Fact] + public void Should_fail_when_asserting_nullable_numeric_value_without_a_value_to_not_be_null() + { + // Arrange + int? nullableInteger = null; - // Act - Action act = () => nullableInteger.Should().NotHaveValue(); + // Act + Action act = () => nullableInteger.Should().NotBeNull(); - // Assert - act.Should().Throw(); - } + // Assert + act.Should().Throw(); + } - [Fact] - public void Should_fail_when_asserting_nullable_numeric_value_with_a_value_to_be_null() - { - // Arrange - int? nullableInteger = 1; + [Fact] + public void + Should_fail_with_descriptive_message_when_asserting_nullable_numeric_value_without_a_value_to_not_be_null() + { + // Arrange + int? nullableInteger = null; - // Act - Action act = () => nullableInteger.Should().BeNull(); + // Act + Action act = () => nullableInteger.Should().NotBeNull("because we want to test the failure {0}", "message"); - // Assert - act.Should().Throw(); + // Assert + act.Should().Throw() + .WithMessage("Expected a value because we want to test the failure message."); + } } - [Fact] - public void When_nullable_value_with_unexpected_value_is_found_it_should_throw_with_message() + public class BeNull { - // Arrange - int? nullableInteger = 1; + [Fact] + public void Should_succeed_when_asserting_nullable_numeric_value_without_a_value_to_be_null() + { + // Arrange + int? nullableInteger = null; - // Act - Action action = () => nullableInteger.Should().NotHaveValue("it was {0} expected", "not"); + // Act / Assert + nullableInteger.Should().BeNull(); + } - // Assert - action - .Should().Throw() - .WithMessage("Did not expect a value because it was not expected, but found 1."); - } + [Fact] + public void Should_fail_when_asserting_nullable_numeric_value_with_a_value_to_be_null() + { + // Arrange + int? nullableInteger = 1; - [Fact] - public void Should_fail_with_descriptive_message_when_asserting_nullable_numeric_value_with_a_value_to_be_null() - { - // Arrange - int? nullableInteger = 1; + // Act + Action act = () => nullableInteger.Should().BeNull(); - // Act - Action act = () => nullableInteger.Should().BeNull("because we want to test the failure {0}", "message"); + // Assert + act.Should().Throw(); + } - // Assert - act.Should().Throw() - .WithMessage("Did not expect a value because we want to test the failure message, but found 1."); - } + [Fact] + public void Should_fail_with_descriptive_message_when_asserting_nullable_numeric_value_with_a_value_to_be_null() + { + // Arrange + int? nullableInteger = 1; - [Fact] - public void Should_succeed_when_asserting_nullable_numeric_value_equals_an_equal_value() - { - // Arrange - int? nullableIntegerA = 1; - int? nullableIntegerB = 1; + // Act + Action act = () => nullableInteger.Should().BeNull("because we want to test the failure {0}", "message"); - // Act / Assert - nullableIntegerA.Should().Be(nullableIntegerB); + // Assert + act.Should().Throw() + .WithMessage("Did not expect a value because we want to test the failure message, but found 1."); + } } - [Fact] - public void Should_succeed_when_asserting_nullable_numeric_null_value_equals_null() + public class Be { - // Arrange - int? nullableIntegerA = null; - int? nullableIntegerB = null; + [Fact] + public void Should_succeed_when_asserting_nullable_numeric_value_equals_an_equal_value() + { + // Arrange + int? nullableIntegerA = 1; + int? nullableIntegerB = 1; - // Act / Assert - nullableIntegerA.Should().Be(nullableIntegerB); - } + // Act / Assert + nullableIntegerA.Should().Be(nullableIntegerB); + } - [Fact] - public void Should_fail_when_asserting_nullable_numeric_value_equals_a_different_value() - { - // Arrange - int? nullableIntegerA = 1; - int? nullableIntegerB = 2; + [Fact] + public void Should_succeed_when_asserting_nullable_numeric_null_value_equals_null() + { + // Arrange + int? nullableIntegerA = null; + int? nullableIntegerB = null; - // Act - Action act = () => nullableIntegerA.Should().Be(nullableIntegerB); + // Act / Assert + nullableIntegerA.Should().Be(nullableIntegerB); + } - // Assert - act.Should().Throw(); - } + [Fact] + public void Should_fail_when_asserting_nullable_numeric_value_equals_a_different_value() + { + // Arrange + int? nullableIntegerA = 1; + int? nullableIntegerB = 2; - [Fact] - public void Should_fail_with_descriptive_message_when_asserting_nullable_numeric_value_equals_a_different_value() - { - // Arrange - int? nullableIntegerA = 1; - int? nullableIntegerB = 2; + // Act + Action act = () => nullableIntegerA.Should().Be(nullableIntegerB); + + // Assert + act.Should().Throw(); + } - // Act - Action act = () => - nullableIntegerA.Should().Be(nullableIntegerB, "because we want to test the failure {0}", "message"); + [Fact] + public void Should_fail_with_descriptive_message_when_asserting_nullable_numeric_value_equals_a_different_value() + { + // Arrange + int? nullableIntegerA = 1; + int? nullableIntegerB = 2; - // Assert - act.Should().Throw() - .WithMessage("Expected*2 because we want to test the failure message, but found 1."); + // Act + Action act = () => + nullableIntegerA.Should().Be(nullableIntegerB, "because we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw() + .WithMessage("Expected*2 because we want to test the failure message, but found 1."); + } } public class BeApproximately @@ -351,7 +368,7 @@ public void When_nullable_double_is_not_approximating_a_value_it_should_throw() .Should().Throw() .WithMessage("Expected value to approximate 1.0 +/- 0.1, but 3.14* differed by*"); } - + [Fact] public void A_double_cannot_approximate_NaN() { @@ -366,7 +383,7 @@ public void A_double_cannot_approximate_NaN() .Should().Throw() .WithMessage("*NaN*"); } - + [Fact] public void When_approximating_a_nullable_float_with_a_negative_precision_it_should_throw() { @@ -496,7 +513,7 @@ public void When_nullable_float_is_not_approximating_a_value_it_should_throw() .WithMessage( "Expected value to approximate *1* +/- *0.1* but 3.14* differed by*"); } - + [Fact] public void A_float_cannot_approximate_NaN() { @@ -800,7 +817,7 @@ public void When_asserting_not_approximately_and_nullable_double_is_approximatin // Assert act.Should().Throw(); } - + [Fact] public void A_double_cannot_approximate_NaN() { @@ -957,7 +974,7 @@ public void When_asserting_not_approximately_and_nullable_float_is_approximating // Assert act.Should().Throw(); } - + [Fact] public void A_float_cannot_approximate_NaN() {