Skip to content

Commit

Permalink
Add missing tests (according to coveralls) for Data* objects
Browse files Browse the repository at this point in the history
This ref. #1823
  • Loading branch information
IT-VBFK committed Apr 7, 2022
1 parent d53e8d9 commit 8e2634d
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 0 deletions.
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 When_object_of_type_unequal_to_DataColumn_is_asserted_with_a_DataColumn_it_fails()
{
// 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 When_object_of_type_unequal_to_DataRelation_is_asserted_with_a_DataRelation_it_fails()
{
// 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 When_data_relation_is_null_and_isnt_expected_to_be_equivalence_test_fails()
{
// 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 When_data_relation_is_expected_to_be_null_and_isnt_the_test_fails()
{
// 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*");
}
}
}
41 changes: 41 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs
Expand Up @@ -335,6 +335,47 @@ 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 When_object_of_type_unequal_to_DataRow_is_asserted_with_a_DataRow_it_fails()
{
// 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 When_subject_of_type_DataRowCollection_is_expected_and_is_not_it_fails()
{
// Arrange
var subject = new
{
DataRowCollection = "foo"
};

// Act
Action act = () => subject.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 When_object_of_type_unequal_to_DataSet_is_asserted_with_a_DataSet_it_fails()
{
// 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 When_object_of_type_unequal_to_DataTable_is_asserted_with_a_DataTable_it_fails()
{
// 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

0 comments on commit 8e2634d

Please sign in to comment.