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

Add missing tests (according to coveralls) for Data* objects #1882

Merged
merged 7 commits into from Apr 9, 2022
Merged
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
22 changes: 22 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs
Expand Up @@ -703,5 +703,27 @@ public void When_ExtendedProperties_do_not_match_and_property_is_excluded_it_sho
dataColumn1.Should().BeEquivalentTo(dataColumn2,
options => options.Excluding(dataColumn => dataColumn.ExtendedProperties));
}

[Fact]
public void Data_column_is_not_equivalent_to_another_type()
{
// Arrange
var subject = new
{
DataColumn = "foobar"
};

var expected = new
{
DataColumn = new DataColumn()
};

// Act
Action act = () => subject.Should().BeEquivalentTo(expected);

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*System.Data.DataColumn*found System.String*");
}
}
}
96 changes: 96 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs
Expand Up @@ -254,5 +254,101 @@ public void When_ChildColumns_do_not_match_and_property_is_excluded_it_should_su
.ExcludingRelated((DataRelation dataRelation) => dataRelation.ParentKeyConstraint)
.ExcludingRelated((DataRelation dataRelation) => dataRelation.ChildKeyConstraint));
}

[Fact]
public void Data_relation_is_not_equivalent_to_another_type()
{
// Arrange
var dataSet = new DataSet();
var table = new DataTable();
var col1 = new DataColumn();
var col2 = new DataColumn();

table.Columns.Add(col1);
table.Columns.Add(col2);

dataSet.Tables.Add(table);

var subject = new
{
DataRelation = "foobar"
};

var expected = new
{
DataRelation = new DataRelation("bar", col1, col2)
};

// Act
Action act = () => subject.Should().BeEquivalentTo(expected);

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*System.Data.DataRelation*found System.String*");
}

[Fact]
public void Null_is_not_equivalent_to_a_data_relation()
{
// Arrange
var dataSet = new DataSet();
var table = new DataTable();
var col1 = new DataColumn();
var col2 = new DataColumn();

table.Columns.Add(col1);
table.Columns.Add(col2);

dataSet.Tables.Add(table);

var subject = new
{
DataRelation = (DataRelation)null
};

var expected = new
{
DataRelation = new DataRelation("bar", col1, col2)
};

// Act
Action act = () => subject.Should().BeEquivalentTo(expected);

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected *value to be non-null, but found*");
}

[Fact]
public void Data_relation_is_not_equivalent_to_null()
{
// Arrange
var dataSet = new DataSet();
var table = new DataTable();
var col1 = new DataColumn();
var col2 = new DataColumn();

table.Columns.Add(col1);
table.Columns.Add(col2);

dataSet.Tables.Add(table);

var subject = new
{
DataRelation = new DataRelation("bar", col1, col2)
};

var expected = new
{
DataRelation = (DataRelation)null
};

// Act
Action act = () => subject.Should().BeEquivalentTo(expected);

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected *to be null, but found*");
}
}
}
38 changes: 38 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs
Expand Up @@ -335,6 +335,44 @@ public void When_data_row_data_does_not_match_but_the_column_is_excluded_then_eq
dataRow1.Should().BeEquivalentTo(dataRow2, config => config.ExcludingColumn(dataSet2.TypedDataTable1.DateTimeColumn));
}

[Fact]
public void Data_row_is_not_equivalent_to_another_type()
{
// Arrange
var table = new DataTable();
var dataRow = table.NewRow();
var subject = new
{
DataRow = "foobar"
};

var expected = new
{
DataRow = dataRow
};

// Act
Action act = () => subject.Should().BeEquivalentTo(expected);

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*System.Data.DataRow*found System.String*");
}

[Fact]
public void Any_type_is_not_equivalent_to_data_row_colletion()
{
// Arrange
var o = new object();

// Act
Action act = () => o.Should().BeEquivalentTo((DataRowCollection)null);

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected* to be of type DataRowCollection, but found*");
}

[Fact]
public void When_data_row_has_column_then_asserting_that_it_has_that_column_should_succeed()
{
Expand Down
22 changes: 22 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs
Expand Up @@ -615,6 +615,28 @@ public void When_data_set_tables_contain_different_data_equivalence_test_should_
action.Should().Throw<XunitException>().WithMessage("Expected dataSet1[TypedDataTable2].Rows[0] to have RowState value of *Modified*, but found *Unchanged* instead*");
}

[Fact]
public void Data_set_is_not_equivalent_to_another_type()
{
// Arrange
var subject = new
{
DataSet = "foobar"
};

var expected = new
{
DataSet = new DataSet()
};

// Act
Action act = () => subject.Should().BeEquivalentTo(expected);

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*System.Data.DataSet*found System.String*");
}

[Fact]
public void When_data_set_table_count_has_expected_value_equivalence_test_should_succeed()
{
Expand Down
22 changes: 22 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs
Expand Up @@ -721,6 +721,28 @@ public void When_data_table_data_matches_in_different_order_and_the_row_match_mo
dataTable1.Should().BeEquivalentTo(dataTable2, options => options.UsingRowMatchMode(RowMatchMode.PrimaryKey));
}

[Fact]
public void Data_table_is_not_equivalent_to_another_type()
{
// Arrange
var subject = new
{
DataTable = "foobar"
};

var expected = new
{
DataTable = new DataTable()
};

// Act
Action act = () => subject.Should().BeEquivalentTo(expected);

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*System.Data.DataTable*found System.String*");
}

[Fact]
public void When_data_table_has_expected_row_count_it_should_succeed()
{
Expand Down