From 9fe45778c378f7eb158bc8b76d43da6d23547566 Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger Date: Wed, 6 Apr 2022 20:28:59 +0200 Subject: [PATCH] Add missing tests (according to coveralls) for Data* objects This ref. #1823 --- .../DataColumnSpecs.cs | 22 +++++ .../DataRelationSpecs.cs | 91 +++++++++++++++++++ .../DataRowSpecs.cs | 24 +++++ .../DataSetSpecs.cs | 22 +++++ .../DataTableSpecs.cs | 22 +++++ 5 files changed, 181 insertions(+) diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs index f4c3e0025f..5465a0d039 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs @@ -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() + .WithMessage("Expected*System.Data.DataColumn*found System.String*"); + } } } diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs index 71c79a7f1e..6693fcd5d5 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs @@ -254,5 +254,96 @@ 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() + .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 expected = new + { + DataRelation = new DataRelation("bar", col1, col2) + }; + + // Act + Action act = () => ((DataRelation)null).Should().BeEquivalentTo(expected); + + // Assert + act.Should().Throw() + .WithMessage("Expected *to be*, 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() + .WithMessage("Expected *to be null, but found*"); + } } } diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs index a8b2e6a98c..2df5c5a415 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs @@ -335,6 +335,30 @@ 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() + .WithMessage("Expected*System.Data.DataRow*found System.String*"); + } + [Fact] public void When_data_row_has_column_then_asserting_that_it_has_that_column_should_succeed() { diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs index 12bbbd0504..ecb6a46212 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs @@ -615,6 +615,28 @@ public void When_data_set_tables_contain_different_data_equivalence_test_should_ action.Should().Throw().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() + .WithMessage("Expected*System.Data.DataSet*found System.String*"); + } + [Fact] public void When_data_set_table_count_has_expected_value_equivalence_test_should_succeed() { diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs index 025528d40b..75314f5cb9 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs @@ -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() + .WithMessage("Expected*System.Data.DataTable*found System.String*"); + } + [Fact] public void When_data_table_has_expected_row_count_it_should_succeed() {