From 5426a12cd70e8801cf5b0179419d7318fdb2f95d Mon Sep 17 00:00:00 2001 From: Matthias Lischka Date: Sat, 20 Oct 2018 19:00:15 +0200 Subject: [PATCH] rename ContainEquivalentTo to ContainEquivalentOf and minor cleanup Feedback from PR. --- .../Collections/CollectionAssertions.cs | 14 ++++--- .../Shared.Specs/CollectionAssertionSpecs.cs | 39 ++++++++----------- docs/_pages/documentation.md | 2 +- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/Src/FluentAssertions/Collections/CollectionAssertions.cs b/Src/FluentAssertions/Collections/CollectionAssertions.cs index 34bd582912..c44e3b4d81 100644 --- a/Src/FluentAssertions/Collections/CollectionAssertions.cs +++ b/Src/FluentAssertions/Collections/CollectionAssertions.cs @@ -463,7 +463,7 @@ public AndConstraint BeEquivalentTo(params object[] expectations) } /// - /// Asserts that a collection of objects contains an object equivalent to another object. + /// Asserts that a collection of objects contains at least one object equivalent to another object. /// /// /// Objects within the collection are equivalent to the expected object when both object graphs have equally named properties with the same @@ -478,14 +478,14 @@ public AndConstraint BeEquivalentTo(params object[] expectations) /// /// Zero or more objects to format using the placeholders in . /// - public AndConstraint ContainEquivalentTo(TExpectation expectation, string because = "", + public AndConstraint ContainEquivalentOf(TExpectation expectation, string because = "", params object[] becauseArgs) { - return ContainEquivalentTo(expectation, config => config, because, becauseArgs); + return ContainEquivalentOf(expectation, config => config, because, becauseArgs); } /// - /// Asserts that a collection of objects contains an object equivalent to another object. + /// Asserts that a collection of objects contains at least one object equivalent to another object. /// /// /// Objects within the collection are equivalent to the expected object when both object graphs have equally named properties with the same @@ -506,7 +506,7 @@ public AndConstraint BeEquivalentTo(params object[] expectations) /// /// Zero or more objects to format using the placeholders in . /// - public AndConstraint ContainEquivalentTo(TExpectation expectation, Func, + public AndConstraint ContainEquivalentOf(TExpectation expectation, Func, EquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { if(ReferenceEquals(Subject, null)) @@ -539,13 +539,15 @@ public AndConstraint BeEquivalentTo(params object[] expectations) string[] failures = scope.Discard(); if (!failures.Any()) + { return new AndConstraint((TAssertions)this); + } } } Execute.Assertion .BecauseOf(because, becauseArgs) - .FailWith("Expected collection {0} to contain equivalent to {1}.", Subject, expectation); + .FailWith("Expected {context:collection} {0} to contain equivalent to {1}.", Subject, expectation); return new AndConstraint((TAssertions)this); } diff --git a/Tests/Shared.Specs/CollectionAssertionSpecs.cs b/Tests/Shared.Specs/CollectionAssertionSpecs.cs index d424e0d50e..15149eee41 100644 --- a/Tests/Shared.Specs/CollectionAssertionSpecs.cs +++ b/Tests/Shared.Specs/CollectionAssertionSpecs.cs @@ -2336,7 +2336,7 @@ public void When_testing_collections_not_to_be_equivalent_against_same_collectio #endregion - #region Contain Equivalent To + #region Contain Equivalent Of [Fact] public void When_collection_contains_object_equal_to_another_it_should_succeed() @@ -2350,7 +2350,7 @@ public void When_collection_contains_object_equal_to_another_it_should_succeed() //----------------------------------------------------------------------------------------------------------- // Act / Assert //----------------------------------------------------------------------------------------------------------- - collection.Should().ContainEquivalentTo(item); + collection.Should().ContainEquivalentOf(item); } [Fact] @@ -2365,7 +2365,7 @@ public void When_collection_contains_object_equivalent_to_another_it_should_succ //----------------------------------------------------------------------------------------------------------- // Act / Assert //----------------------------------------------------------------------------------------------------------- - collection.Should().ContainEquivalentTo(item); + collection.Should().ContainEquivalentOf(item); } [Fact] @@ -2374,13 +2374,13 @@ public void When_character_collection_does_contain_equivalent_it_should_succeed( //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- - char[] list = ("abc123ab").ToCharArray(); + char[] collection = ("abc123ab").ToCharArray(); char item = 'c'; //----------------------------------------------------------------------------------------------------------- // Act / Assert //----------------------------------------------------------------------------------------------------------- - list.Should().ContainEquivalentTo(item); + collection.Should().ContainEquivalentOf(item); } [Fact] @@ -2395,7 +2395,7 @@ public void When_collection_does_not_contain_object_equivalent_to_another_it_sho //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- - Action act = () => collection.Should().ContainEquivalentTo(item); ; + Action act = () => collection.Should().ContainEquivalentOf(item); ; //----------------------------------------------------------------------------------------------------------- // Act / Assert @@ -2409,24 +2409,20 @@ public void When_asserting_collection_to_contain_equivalent_but_collection_is_nu //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- - IEnumerable actual = null; + IEnumerable collection = null; int expectation = 1; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => - actual.Should().ContainEquivalentTo(expectation, "because we want to test the behaviour with a null subject"); + collection.Should().ContainEquivalentOf(expectation, "because we want to test the behaviour with a null subject"); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.Should().Throw().WithMessage( -#if NETCOREAPP1_1 "Expected collection to contain equivalent to 1 because we want to test the behaviour with a null subject, but found ."); -#else - "Expected actual to contain equivalent to 1 because we want to test the behaviour with a null subject, but found ."); -#endif } [Fact] @@ -2435,13 +2431,13 @@ public void When_collection_contains_equivalent_null_object_it_should_succeed() //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- - IEnumerable subject = new[] { 1, 2, 3, (int?)null }; + IEnumerable collection = new[] { 1, 2, 3, (int?)null }; int? item = null; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- - Action act = () => subject.Should().ContainEquivalentTo(item); + Action act = () => collection.Should().ContainEquivalentOf(item); //----------------------------------------------------------------------------------------------------------- // Assert @@ -2461,7 +2457,7 @@ public void When_collection_does_not_contain_equivalent_null_object_it_should_th //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- - Action act = () => collection.Should().ContainEquivalentTo(item); + Action act = () => collection.Should().ContainEquivalentOf(item); //----------------------------------------------------------------------------------------------------------- // Assert @@ -2475,13 +2471,13 @@ public void When_empty_collection_does_not_contain_equivalent_it_should_throw() //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- - IEnumerable subject = new int[0]; + IEnumerable collection = new int[0]; int item = 1; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- - Action act = () => subject.Should().ContainEquivalentTo(item); + Action act = () => collection.Should().ContainEquivalentOf(item); //----------------------------------------------------------------------------------------------------------- // Assert @@ -2513,7 +2509,7 @@ public void When_collection_does_not_contain_equivalent_because_of_second_proper //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- - Action act = () => subject.Should().ContainEquivalentTo(item); + Action act = () => subject.Should().ContainEquivalentOf(item); //----------------------------------------------------------------------------------------------------------- // Assert @@ -2527,7 +2523,7 @@ public void When_collection_does_contain_equivalent_by_including_single_property //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- - IEnumerable subject = new [] + IEnumerable collection = new [] { new Customer { @@ -2545,7 +2541,7 @@ public void When_collection_does_contain_equivalent_by_including_single_property //----------------------------------------------------------------------------------------------------------- // Act / Assert //----------------------------------------------------------------------------------------------------------- - subject.Should().ContainEquivalentTo(item, options => options.Including(x => x.Name)); + collection.Should().ContainEquivalentOf(item, options => options.Including(x => x.Name)); } [Fact] @@ -2560,8 +2556,7 @@ public void When_collection_contains_object_equivalent_to_boxed_object_it_should //----------------------------------------------------------------------------------------------------------- // Act / Assert //----------------------------------------------------------------------------------------------------------- - 2.Should().Equals(boxedValue); - collection.Should().ContainEquivalentTo(boxedValue); + collection.Should().ContainEquivalentOf(boxedValue); } #endregion diff --git a/docs/_pages/documentation.md b/docs/_pages/documentation.md index d448ae1973..58b62ed98f 100644 --- a/docs/_pages/documentation.md +++ b/docs/_pages/documentation.md @@ -462,7 +462,7 @@ collection.Should().NotContainNulls(); collection.Should().NotContain(x => x > 10); object boxedValue = 2; -collection.Should().ContainEquivalentTo(boxedValue); // Compared by object equivalence +collection.Should().ContainEquivalentOf(boxedValue); // Compared by object equivalence const int successor = 5; const int predecessor = 5;