From 8e2634db1a51b2b1f69a95f4215d15e415002303 Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger Date: Wed, 6 Apr 2022 20:28:59 +0200 Subject: [PATCH 1/7] Add missing tests (according to coveralls) for Data* objects This ref. #1823 --- .../DataColumnSpecs.cs | 22 +++++ .../DataRelationSpecs.cs | 96 +++++++++++++++++++ .../DataRowSpecs.cs | 41 ++++++++ .../DataSetSpecs.cs | 22 +++++ .../DataTableSpecs.cs | 22 +++++ 5 files changed, 203 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..24eb1e2ac7 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs @@ -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() + .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() + .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() + .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..151eb5e8ef 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs @@ -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() + .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() + .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() { 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() { From 4cfe85c383b30b32dedf347bb06df35a091b640e Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger Date: Thu, 7 Apr 2022 22:10:20 +0200 Subject: [PATCH 2/7] Rename tests to more functional names The reason for this change was, to get away from the 'When_x_it_should_be_y' approach in future. --- Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs | 2 +- Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs | 2 +- Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs | 4 ++-- Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs | 2 +- Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs index 5465a0d039..ec25190ebc 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs @@ -705,7 +705,7 @@ public void When_ExtendedProperties_do_not_match_and_property_is_excluded_it_sho } [Fact] - public void When_object_of_type_unequal_to_DataColumn_is_asserted_with_a_DataColumn_it_fails() + public void Data_column_is_not_equivalent_to_another_type() { // Arrange var subject = new diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs index 24eb1e2ac7..0ae1d875dc 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs @@ -288,7 +288,7 @@ public void When_object_of_type_unequal_to_DataRelation_is_asserted_with_a_DataR } [Fact] - public void When_data_relation_is_null_and_isnt_expected_to_be_equivalence_test_fails() + public void Null_is_not_equivalent_to_a_corrent_initialized_object() { // Arrange var dataSet = new DataSet(); diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs index 151eb5e8ef..8d70a28d53 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs @@ -336,7 +336,7 @@ public void When_data_row_data_does_not_match_but_the_column_is_excluded_then_eq } [Fact] - public void When_object_of_type_unequal_to_DataRow_is_asserted_with_a_DataRow_it_fails() + public void Data_row_is_not_equivalent_to_another_type() { // Arrange var table = new DataTable(); @@ -375,7 +375,7 @@ public void When_subject_of_type_DataRowCollection_is_expected_and_is_not_it_fai act.Should().Throw() .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() { diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs index ecb6a46212..dd8c0ade56 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs @@ -616,7 +616,7 @@ public void When_data_set_tables_contain_different_data_equivalence_test_should_ } [Fact] - public void When_object_of_type_unequal_to_DataSet_is_asserted_with_a_DataSet_it_fails() + public void Data_set_is_not_equivalent_to_another_type() { // Arrange var subject = new diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs index 75314f5cb9..89d5689125 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs @@ -722,7 +722,7 @@ public void When_data_table_data_matches_in_different_order_and_the_row_match_mo } [Fact] - public void When_object_of_type_unequal_to_DataTable_is_asserted_with_a_DataTable_it_fails() + public void Data_table_is_not_equivalent_to_another_type() { // Arrange var subject = new From 5e91401cb1d877bf102fdfa94ad6b325d5391899 Mon Sep 17 00:00:00 2001 From: IT-VBFK <49762557+IT-VBFK@users.noreply.github.com> Date: Fri, 8 Apr 2022 09:14:41 +0200 Subject: [PATCH 3/7] Update Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs Co-authored-by: Jonas Nyrup --- Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs index 0ae1d875dc..9bc32a8e16 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs @@ -288,7 +288,7 @@ public void When_object_of_type_unequal_to_DataRelation_is_asserted_with_a_DataR } [Fact] - public void Null_is_not_equivalent_to_a_corrent_initialized_object() + public void Null_is_not_equivalent_to_a_data_relation() { // Arrange var dataSet = new DataSet(); From 84d1389828718cf05f66dc8caa3b640381e7ec9b Mon Sep 17 00:00:00 2001 From: IT-VBFK <49762557+IT-VBFK@users.noreply.github.com> Date: Fri, 8 Apr 2022 09:15:00 +0200 Subject: [PATCH 4/7] Update Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs Co-authored-by: Jonas Nyrup --- Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs index 9bc32a8e16..27371ce282 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs @@ -320,7 +320,7 @@ public void Null_is_not_equivalent_to_a_data_relation() } [Fact] - public void When_data_relation_is_expected_to_be_null_and_isnt_the_test_fails() + public void Data_relation_is_not_equivalent_to_null() { // Arrange var dataSet = new DataSet(); From be335fff3fdd89379b408e4f060603b01e02ec3a Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger Date: Fri, 8 Apr 2022 09:48:24 +0200 Subject: [PATCH 5/7] Update Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs --- Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs index 27371ce282..17435edb74 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs @@ -256,7 +256,7 @@ public void When_ChildColumns_do_not_match_and_property_is_excluded_it_should_su } [Fact] - public void When_object_of_type_unequal_to_DataRelation_is_asserted_with_a_DataRelation_it_fails() + public void Data_relation_is_not_equivalent_to_another_type() { // Arrange var dataSet = new DataSet(); From 2066fc5c533624dbc56e2113190185e3260bd55b Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger Date: Fri, 8 Apr 2022 09:48:43 +0200 Subject: [PATCH 6/7] Fix test name --- Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs index 8d70a28d53..a7d5d61a48 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs @@ -360,7 +360,7 @@ public void Data_row_is_not_equivalent_to_another_type() } [Fact] - public void When_subject_of_type_DataRowCollection_is_expected_and_is_not_it_fails() + public void Any_type_is_not_equivalent_to_data_row_colletion() { // Arrange var subject = new From 9c845e505baf2599e7d18e92dccd99560f487ff7 Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger Date: Fri, 8 Apr 2022 09:59:26 +0200 Subject: [PATCH 7/7] Fix test --- .../DataRowSpecs.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs index a7d5d61a48..a7c26d3188 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs @@ -362,14 +362,11 @@ public void Data_row_is_not_equivalent_to_another_type() [Fact] public void Any_type_is_not_equivalent_to_data_row_colletion() { - // Arrange - var subject = new - { - DataRowCollection = "foo" - }; - + // Arrange + var o = new object(); + // Act - Action act = () => subject.Should().BeEquivalentTo((DataRowCollection)null); + Action act = () => o.Should().BeEquivalentTo((DataRowCollection)null); // Assert act.Should().Throw()