Skip to content

Commit

Permalink
Removed extraneous quotes from failure messages in System.Data assert…
Browse files Browse the repository at this point in the history
…ions.

Updated assertions of exceptions in DataSetSpecs.cs, DataTableSpecs.cs and DataRowSpecs.cs to include exception message patterns to ensure that they are the _right_ exceptions.
  • Loading branch information
logiclrd committed Feb 19, 2022
1 parent a182326 commit a54b7b3
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 79 deletions.
6 changes: 3 additions & 3 deletions Src/FluentAssertions/Data/DataRowAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public DataRowAssertions(TDataRow dataRow)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:DataRow} to contain a column named '{0}'{reason}, but found <null>.", expectedColumnName);
.FailWith("Expected {context:DataRow} to contain a column named {0}{reason}, but found <null>.", expectedColumnName);
}
else if (!Subject.Table.Columns.Contains(expectedColumnName))
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:DataRow} to contain a column named '{0}'{reason}, but it does not.", expectedColumnName);
.FailWith("Expected {context:DataRow} to contain a column named {0}{reason}, but it does not.", expectedColumnName);
}
else
{
Expand Down Expand Up @@ -93,7 +93,7 @@ public AndConstraint<DataRowAssertions<TDataRow>> HaveColumns(IEnumerable<string
Execute.Assertion
.ForCondition(Subject.Table.Columns.Contains(expectedColumnName))
.BecauseOf(because, becauseArgs)
.FailWith("Expected table containing {context:DataRow} to contain a column named '{0}'{reason}, but it does not.", expectedColumnName);
.FailWith("Expected table containing {context:DataRow} to contain a column named {0}{reason}, but it does not.", expectedColumnName);
}

return new AndConstraint<DataRowAssertions<TDataRow>>(this);
Expand Down
6 changes: 3 additions & 3 deletions Src/FluentAssertions/Data/DataSetAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public AndConstraint<DataSetAssertions<TDataSet>> HaveTableCount(int expected, s
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:DataSet} to contain a table named '{0}'{reason}, but found <null>.", expectedTableName);
.FailWith("Expected {context:DataSet} to contain a table named {0}{reason}, but found <null>.", expectedTableName);
}
else if (!Subject.Tables.Contains(expectedTableName))
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:DataSet} to contain a table named '{0}'{reason}, but it does not.", expectedTableName);
.FailWith("Expected {context:DataSet} to contain a table named {0}{reason}, but it does not.", expectedTableName);
}
else
{
Expand Down Expand Up @@ -123,7 +123,7 @@ public AndConstraint<DataSetAssertions<TDataSet>> HaveTables(IEnumerable<string>
Execute.Assertion
.ForCondition(Subject.Tables.Contains(expectedTableName))
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:DataSet} to contain a table named '{0}'{reason}, but it does not.", expectedTableName);
.FailWith("Expected {context:DataSet} to contain a table named {0}{reason}, but it does not.", expectedTableName);
}

return new AndConstraint<DataSetAssertions<TDataSet>>(this);
Expand Down
6 changes: 3 additions & 3 deletions Src/FluentAssertions/Data/DataTableAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public AndConstraint<DataTableAssertions<TDataTable>> HaveRowCount(int expected,
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:DataTable} to contain a column named '{0}'{reason}, but found <null>.", expectedColumnName);
.FailWith("Expected {context:DataTable} to contain a column named {0}{reason}, but found <null>.", expectedColumnName);
}
else if (!Subject.Columns.Contains(expectedColumnName))
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:DataTable} to contain a column named '{0}'{reason}, but it does not.", expectedColumnName);
.FailWith("Expected {context:DataTable} to contain a column named {0}{reason}, but it does not.", expectedColumnName);
}
else
{
Expand Down Expand Up @@ -123,7 +123,7 @@ public AndConstraint<DataTableAssertions<TDataTable>> HaveColumns(IEnumerable<st
Execute.Assertion
.ForCondition(Subject.Columns.Contains(expectedColumnName))
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:DataTable} to contain a column named '{0}'{reason}, but it does not.", expectedColumnName);
.FailWith("Expected {context:DataTable} to contain a column named {0}{reason}, but it does not.", expectedColumnName);
}

return new AndConstraint<DataTableAssertions<TDataTable>>(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalenc
{
AssertionScope.Current
.ForCondition(subject.RelationName == expectation.RelationName)
.FailWith("Expected {context:DataRelation} to have RelationName of '{0}'{reason}, but found '{1}'",
.FailWith("Expected {context:DataRelation} to have RelationName of {0}{reason}, but found {1}",
expectation.RelationName, subject.RelationName);
}

if (selectedMembers.ContainsKey(nameof(expectation.Nested)))
{
AssertionScope.Current
.ForCondition(subject.Nested == expectation.Nested)
.FailWith("Expected {context:DataRelation} to have Nested value of '{0}'{reason}, but found '{1}'",
.FailWith("Expected {context:DataRelation} to have Nested value of {0}{reason}, but found {1}",
expectation.Nested, subject.Nested);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static Type[] GatherPrimaryKeyColumnTypes(DataTable table, string compar
if ((table.PrimaryKey is null) || (table.PrimaryKey.Length == 0))
{
AssertionScope.Current
.FailWith("Table '{0}' containing {1} {context:DataRowCollection} does not have a primary key. RowMatchMode.PrimaryKey cannot be applied.", table.TableName, comparisonTerm);
.FailWith("Table {0} containing {1} {context:DataRowCollection} does not have a primary key. RowMatchMode.PrimaryKey cannot be applied.", table.TableName, comparisonTerm);
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions Src/FluentAssertions/Equivalency/Steps/DataRowEquivalencyStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalenc
{
AssertionScope.Current
.ForCondition(subject.GetType() == expectation.GetType())
.FailWith("Expected {context:DataRow} to be of type '{0}'{reason}, but found '{1}'",
.FailWith("Expected {context:DataRow} to be of type {0}{reason}, but found {1}",
expectation.GetType(), subject.GetType());
}

Expand All @@ -74,15 +74,15 @@ private static void CompareScalarProperties(DataRow subject, DataRow expectation
{
AssertionScope.Current
.ForCondition(subject.HasErrors == expectation.HasErrors)
.FailWith("Expected {context:DataRow} to have HasErrors value of '{0}'{reason}, but found '{1}' instead",
.FailWith("Expected {context:DataRow} to have HasErrors value of {0}{reason}, but found {1} instead",
expectation.HasErrors, subject.HasErrors);
}

if (selectedMembers.RowState)
{
AssertionScope.Current
.ForCondition(subject.RowState == expectation.RowState)
.FailWith("Expected {context:DataRow} to have RowState value of '{0}'{reason}, but found '{1}' instead",
.FailWith("Expected {context:DataRow} to have RowState value of {0}{reason}, but found {1} instead",
expectation.RowState, subject.RowState);
}
}
Expand Down Expand Up @@ -139,11 +139,11 @@ private static void CompareScalarProperties(DataRow subject, DataRow expectation
{
AssertionScope.Current
.ForCondition(subjectColumn is not null)
.FailWith("Expected {context:DataRow} to have column '{0}'{reason}, but found none", columnName);
.FailWith("Expected {context:DataRow} to have column {0}{reason}, but found none", columnName);

AssertionScope.Current
.ForCondition(expectationColumn is not null)
.FailWith("Found unexpected column '{0}' in {context:DataRow}", columnName);
.FailWith("Found unexpected column {0} in {context:DataRow}", columnName);
}

if ((subjectColumn is not null) && (expectationColumn is not null))
Expand Down
24 changes: 12 additions & 12 deletions Src/FluentAssertions/Equivalency/Steps/DataSetEquivalencyStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalenc
{
AssertionScope.Current
.ForCondition(subject.GetType() == expectation.GetType())
.FailWith("Expected {context:DataSet} to be of type '{0}'{reason}, but found '{1}'", expectation.GetType(), subject.GetType());
.FailWith("Expected {context:DataSet} to be of type {0}{reason}, but found {1}", expectation.GetType(), subject.GetType());
}

var selectedMembers = GetMembersFromExpectation(comparands, context.CurrentNode, context.Options)
Expand All @@ -64,63 +64,63 @@ private static void CompareScalarProperties(DataSet subject, DataSet expectation
{
AssertionScope.Current
.ForCondition(subject.DataSetName == expectation.DataSetName)
.FailWith("Expected {context:DataSet} to have DataSetName '{0}'{reason}, but found '{1}' instead", expectation.DataSetName, subject.DataSetName);
.FailWith("Expected {context:DataSet} to have DataSetName {0}{reason}, but found {1} instead", expectation.DataSetName, subject.DataSetName);
}

if (selectedMembers.ContainsKey(nameof(expectation.CaseSensitive)))
{
AssertionScope.Current
.ForCondition(subject.CaseSensitive == expectation.CaseSensitive)
.FailWith("Expected {context:DataSet} to have CaseSensitive value of '{0}'{reason}, but found '{1}' instead", expectation.CaseSensitive, subject.CaseSensitive);
.FailWith("Expected {context:DataSet} to have CaseSensitive value of {0}{reason}, but found {1} instead", expectation.CaseSensitive, subject.CaseSensitive);
}

if (selectedMembers.ContainsKey(nameof(expectation.EnforceConstraints)))
{
AssertionScope.Current
.ForCondition(subject.EnforceConstraints == expectation.EnforceConstraints)
.FailWith("Expected {context:DataSet} to have EnforceConstraints value of '{0}'{reason}, but found '{1}' instead", expectation.EnforceConstraints, subject.EnforceConstraints);
.FailWith("Expected {context:DataSet} to have EnforceConstraints value of {0}{reason}, but found {1} instead", expectation.EnforceConstraints, subject.EnforceConstraints);
}

if (selectedMembers.ContainsKey(nameof(expectation.HasErrors)))
{
AssertionScope.Current
.ForCondition(subject.HasErrors == expectation.HasErrors)
.FailWith("Expected {context:DataSet} to have HasErrors value of '{0}'{reason}, but found '{1}' instead", expectation.HasErrors, subject.HasErrors);
.FailWith("Expected {context:DataSet} to have HasErrors value of {0}{reason}, but found {1} instead", expectation.HasErrors, subject.HasErrors);
}

if (selectedMembers.ContainsKey(nameof(expectation.Locale)))
{
AssertionScope.Current
.ForCondition(subject.Locale == expectation.Locale)
.FailWith("Expected {context:DataSet} to have Locale value of '{0}'{reason}, but found '{1}' instead", expectation.Locale, subject.Locale);
.FailWith("Expected {context:DataSet} to have Locale value of {0}{reason}, but found {1} instead", expectation.Locale, subject.Locale);
}

if (selectedMembers.ContainsKey(nameof(expectation.Namespace)))
{
AssertionScope.Current
.ForCondition(subject.Namespace == expectation.Namespace)
.FailWith("Expected {context:DataSet} to have Namespace value of '{0}'{reason}, but found '{1}' instead", expectation.Namespace, subject.Namespace);
.FailWith("Expected {context:DataSet} to have Namespace value of {0}{reason}, but found {1} instead", expectation.Namespace, subject.Namespace);
}

if (selectedMembers.ContainsKey(nameof(expectation.Prefix)))
{
AssertionScope.Current
.ForCondition(subject.Prefix == expectation.Prefix)
.FailWith("Expected {context:DataSet} to have Prefix value of '{0}'{reason}, but found '{1}' instead", expectation.Prefix, subject.Prefix);
.FailWith("Expected {context:DataSet} to have Prefix value of {0}{reason}, but found {1} instead", expectation.Prefix, subject.Prefix);
}

if (selectedMembers.ContainsKey(nameof(expectation.RemotingFormat)))
{
AssertionScope.Current
.ForCondition(subject.RemotingFormat == expectation.RemotingFormat)
.FailWith("Expected {context:DataSet} to have RemotingFormat value of '{0}'{reason}, but found '{1}' instead", expectation.RemotingFormat, subject.RemotingFormat);
.FailWith("Expected {context:DataSet} to have RemotingFormat value of {0}{reason}, but found {1} instead", expectation.RemotingFormat, subject.RemotingFormat);
}

if (selectedMembers.ContainsKey(nameof(expectation.SchemaSerializationMode)))
{
AssertionScope.Current
.ForCondition(subject.SchemaSerializationMode == expectation.SchemaSerializationMode)
.FailWith("Expected {context:DataSet} to have SchemaSerializationMode value of '{0}'{reason}, but found '{1}' instead", expectation.SchemaSerializationMode, subject.SchemaSerializationMode);
.FailWith("Expected {context:DataSet} to have SchemaSerializationMode value of {0}{reason}, but found {1} instead", expectation.SchemaSerializationMode, subject.SchemaSerializationMode);
}
}

Expand Down Expand Up @@ -210,10 +210,10 @@ private static void CompareTables(IEquivalencyValidationContext context, IEquiva

bool success = AssertionScope.Current
.ForCondition(subjectTable is not null)
.FailWith("Expected {context:DataSet} to contain table '{0}'{reason}, but did not find it", tableName)
.FailWith("Expected {context:DataSet} to contain table {0}{reason}, but did not find it", tableName)
.Then
.ForCondition(expectationTable is not null)
.FailWith("Found unexpected table '{0}' in DataSet", tableName);
.FailWith("Found unexpected table {0} in DataSet", tableName);

if (success)
{
Expand Down

0 comments on commit a54b7b3

Please sign in to comment.