Skip to content

Commit

Permalink
rename ContainEquivalentTo to ContainEquivalentOf and minor cleanup
Browse files Browse the repository at this point in the history
Feedback from PR.
  • Loading branch information
matthiaslischka committed Oct 20, 2018
1 parent 5b27bc7 commit 39666a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
14 changes: 8 additions & 6 deletions Src/FluentAssertions/Collections/CollectionAssertions.cs
Expand Up @@ -463,7 +463,7 @@ public AndConstraint<TAssertions> BeEquivalentTo(params object[] expectations)
}

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// Objects within the collection are equivalent to the expected object when both object graphs have equally named properties with the same
Expand All @@ -478,14 +478,14 @@ public AndConstraint<TAssertions> BeEquivalentTo(params object[] expectations)
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <see cref="because" />.
/// </param>
public AndConstraint<TAssertions> ContainEquivalentTo<TExpectation>(TExpectation expectation, string because = "",
public AndConstraint<TAssertions> ContainEquivalentOf<TExpectation>(TExpectation expectation, string because = "",
params object[] becauseArgs)
{
return ContainEquivalentTo(expectation, config => config, because, becauseArgs);
return ContainEquivalentOf(expectation, config => config, because, becauseArgs);
}

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// Objects within the collection are equivalent to the expected object when both object graphs have equally named properties with the same
Expand All @@ -506,7 +506,7 @@ public AndConstraint<TAssertions> BeEquivalentTo(params object[] expectations)
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <see cref="because" />.
/// </param>
public AndConstraint<TAssertions> ContainEquivalentTo<TExpectation>(TExpectation expectation, Func<EquivalencyAssertionOptions<TExpectation>,
public AndConstraint<TAssertions> ContainEquivalentOf<TExpectation>(TExpectation expectation, Func<EquivalencyAssertionOptions<TExpectation>,
EquivalencyAssertionOptions<TExpectation>> config, string because = "", params object[] becauseArgs)
{
if(ReferenceEquals(Subject, null))
Expand Down Expand Up @@ -539,13 +539,15 @@ public AndConstraint<TAssertions> BeEquivalentTo(params object[] expectations)
string[] failures = scope.Discard();

if (!failures.Any())
{
return new AndConstraint<TAssertions>((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>((TAssertions)this);
}
Expand Down
39 changes: 17 additions & 22 deletions Tests/Shared.Specs/CollectionAssertionSpecs.cs
Expand Up @@ -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()
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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<XunitException>().WithMessage(
#if NETCOREAPP1_1
"Expected collection to contain equivalent to 1 because we want to test the behaviour with a null subject, but found <null>.");
#else
"Expected actual to contain equivalent to 1 because we want to test the behaviour with a null subject, but found <null>.");
#endif
}

[Fact]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -2527,7 +2523,7 @@ public void When_collection_does_contain_equivalent_by_including_single_property
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
IEnumerable subject = new []
IEnumerable collection = new []
{
new Customer
{
Expand All @@ -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]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/_pages/documentation.md
Expand Up @@ -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;
Expand Down

0 comments on commit 39666a3

Please sign in to comment.