Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataSet Collections: ContainItemWithName #1893

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 77 additions & 0 deletions Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs
Expand Up @@ -165,5 +165,82 @@ public static class DataColumnCollectionAssertionExtensions

return new AndConstraint<GenericCollectionAssertions<DataColumn>>(assertion);
}

/// <summary>
/// Asserts that the current collection of <see cref="DataColumn"/>s contains a <see cref="DataColumn"/> with the
/// specified <paramref name="expectedColumnName"/> name.
/// </summary>
/// <param name="expectedColumnName">A name for a <see cref="DataColumn"/> that is expected to be in the
/// <see cref="DataColumnCollection"/>.</param>
/// <param name="because">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public static AndConstraint<GenericCollectionAssertions<DataColumn>> ContainColumnWithName(
this GenericCollectionAssertions<DataColumn> assertion, string expectedColumnName, string because = "",
params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(
expectedColumnName, nameof(expectedColumnName), "Cannot verify that the collection contains a <null> DataColumn.");

Execute.Assertion
.BecauseOf(because, becauseArgs)
.WithExpectation("Expected {context:collection} to contain column named {0}{reason}, ", expectedColumnName)
.Given(() => assertion.Subject)
.ForCondition(subject => subject is not null)
.FailWith("but found {0}.", assertion.Subject)
.Then
.ForCondition(
(subject) => (subject is ReadOnlyNonGenericCollectionWrapper<DataColumnCollection, DataColumn> wrapper)
? wrapper.UnderlyingCollection.Contains(expectedColumnName)
: assertion.Subject.Any(column => column.ColumnName == expectedColumnName))
.FailWith("but it does not.")
.Then
.ClearExpectation();

return new AndConstraint<GenericCollectionAssertions<DataColumn>>(assertion);
}

/// <summary>
/// Asserts that the current collection of <see cref="DataColumn"/>s does not contain a column with the the supplied
/// <paramref name="unexpectedColumnName" />.
/// </summary>
/// <param name="unexpectedColumnName">The column name that is not expected to be in the
/// <see cref="DataColumnCollection" /></param>
/// <param name="because">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public static AndConstraint<GenericCollectionAssertions<DataColumn>> NotContainColumnWithName(
this GenericCollectionAssertions<DataColumn> assertion, string unexpectedColumnName, string because = "",
params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(
unexpectedColumnName, nameof(unexpectedColumnName),
"Cannot verify that the collection does not contain a <null> DataColumn.");

Execute.Assertion
.BecauseOf(because, becauseArgs)
.WithExpectation("Expected {context:collection} to not contain column named {0}{reason}, ", unexpectedColumnName)
.Given(() => assertion.Subject)
.ForCondition(subject => subject is not null)
.FailWith("but found {0}.", assertion.Subject)
.Then
.ForCondition(
(subject) => (subject is ReadOnlyNonGenericCollectionWrapper<DataColumnCollection, DataColumn> wrapper)
? !wrapper.UnderlyingCollection.Contains(unexpectedColumnName)
: !assertion.Subject.Any(column => column.ColumnName == unexpectedColumnName))
.FailWith("but it does.")
.Then
.ClearExpectation();

return new AndConstraint<GenericCollectionAssertions<DataColumn>>(assertion);
}
}
}
78 changes: 78 additions & 0 deletions Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs
Expand Up @@ -195,5 +195,83 @@ public static class DataTableCollectionAssertionExtensions

return new AndConstraint<GenericCollectionAssertions<DataTable>>(assertion);
}

/// <summary>
/// Asserts that the current collection of <see cref="DataTable"/>s contains a <see cref="DataTable"/> with the specified
/// <paramref name="expectedTableName"/> name.
/// </summary>
/// <param name="expectedTableName">A name for a <see cref="DataTable"/> that is expected to be in the
/// <see cref="DataTableCollection"/>.</param>
/// <param name="because">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public static AndConstraint<GenericCollectionAssertions<DataTable>> ContainTableWithName(
this GenericCollectionAssertions<DataTable> assertion, string expectedTableName, string because = "",
params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(
expectedTableName, nameof(expectedTableName), "Cannot verify that the collection contains a <null> DataTable.");

Execute.Assertion
.BecauseOf(because, becauseArgs)
.WithExpectation("Expected {context:collection} to contain ")
.Given(() => assertion.Subject)
.ForCondition(subject => subject is not null)
.FailWith("table named {0}{reason}, but found {1}.", expectedTableName, assertion.Subject)
.Then
.ForCondition(
(subject) => (subject is ReadOnlyNonGenericCollectionWrapper<DataColumnCollection, DataColumn> wrapper)
? wrapper.UnderlyingCollection.Contains(expectedTableName)
: assertion.Subject.Any(table => table.TableName == expectedTableName))
.FailWith("table named {0}{reason}, but it does not.", expectedTableName)
.Then
.ClearExpectation();

return new AndConstraint<GenericCollectionAssertions<DataTable>>(assertion);
}

/// <summary>
/// Asserts that the current collection of <see cref="DataTable"/>s does not contain a table with the the supplied
/// <paramref name="unexpectedTableName" />.
/// </summary>
/// <param name="unexpectedTableName">The table name that is not expected to be in the
/// <see cref="DataTableCollection"/></param>
/// <param name="because">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public static AndConstraint<GenericCollectionAssertions<DataTable>> NotContainTableWithName(
this GenericCollectionAssertions<DataTable> assertion, string unexpectedTableName, string because = "",
params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(
unexpectedTableName, nameof(unexpectedTableName),
"Cannot verify that the collection does not contain a <null> DataTable.");

Execute.Assertion
.BecauseOf(because, becauseArgs)
.WithExpectation("Expected {context:collection} to not contain ")
.Given(() => assertion.Subject)
.ForCondition(subject => subject is not null)
.FailWith("table named {0}{reason}, but found {1}.", unexpectedTableName, assertion.Subject)
.Then
.Given(
(subject) => (subject is ReadOnlyNonGenericCollectionWrapper<DataColumnCollection, DataColumn> wrapper)
? wrapper.UnderlyingCollection.Contains(unexpectedTableName)
: assertion.Subject.Any(table => table.TableName == unexpectedTableName))
.ForCondition(containsTable => !containsTable)
.FailWith("table named {0}{reason}, but it does.", unexpectedTableName)
.Then
.ClearExpectation();

return new AndConstraint<GenericCollectionAssertions<DataTable>>(assertion);
}
}
}
Expand Up @@ -201,8 +201,10 @@ namespace FluentAssertions
public static class DataColumnCollectionAssertionExtensions
{
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, System.Data.DataColumnCollection expected, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> ContainColumnWithName(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, string expectedColumnName, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, System.Data.DataColumnCollection unexpected, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> NotContainColumnWithName(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, string unexpectedColumnName, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { }
}
public static class DataRowAssertionExtensions
Expand Down Expand Up @@ -230,9 +232,11 @@ namespace FluentAssertions
public static class DataTableCollectionAssertionExtensions
{
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataTableCollection expected, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> ContainTableWithName(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, string expectedTableName, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataTableCollection unexpected, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> NotContainTableWithName(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, string unexpectedTableName, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { }
}
Expand Down
Expand Up @@ -213,8 +213,10 @@ namespace FluentAssertions
public static class DataColumnCollectionAssertionExtensions
{
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, System.Data.DataColumnCollection expected, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> ContainColumnWithName(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, string expectedColumnName, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, System.Data.DataColumnCollection unexpected, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> NotContainColumnWithName(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, string unexpectedColumnName, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn>> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataColumn> assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { }
}
public static class DataRowAssertionExtensions
Expand Down Expand Up @@ -242,9 +244,11 @@ namespace FluentAssertions
public static class DataTableCollectionAssertionExtensions
{
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataTableCollection expected, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> ContainTableWithName(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, string expectedTableName, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataTableCollection unexpected, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> NotContainTableWithName(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, string unexpectedTableName, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { }
public static FluentAssertions.AndConstraint<FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable>> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { }
}
Expand Down