From db60b3815cc511bca573ac260b2ab86ec130b3f4 Mon Sep 17 00:00:00 2001 From: Jonathan Gilbert Date: Mon, 28 Feb 2022 09:20:24 -0600 Subject: [PATCH] Added tests that cover the situation where the subject is null to DataTableCollectionAssertionExtensionsSpecs.cs, DataColumnCollectionAssertionExtensionsSpecs.cs and DataRowCollectionAssertionExtensionSpecs.cs. Corrected indentation error in DataRowCollectionAssertionExtensions.cs. --- .../DataRowCollectionAssertionExtensions.cs | 2 +- ...olumnCollectionAssertionExtensionsSpecs.cs | 34 +++++++++++++++++++ ...taRowCollectionAssertionExtensionsSpecs.cs | 34 +++++++++++++++++++ ...TableCollectionAssertionExtensionsSpecs.cs | 34 +++++++++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) diff --git a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs index 2be07c9ebb..6151629b6d 100644 --- a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs +++ b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs @@ -151,5 +151,5 @@ public static class DataRowCollectionAssertionExtensions return new AndConstraint>(assertion); } - } + } } diff --git a/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionExtensionsSpecs.cs b/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionExtensionsSpecs.cs index 8eb780e502..28e805f657 100644 --- a/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionExtensionsSpecs.cs +++ b/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionExtensionsSpecs.cs @@ -122,6 +122,23 @@ public void When_references_are_different_it_should_succeed() public class HaveSameCount { + [Fact] + public void When_subject_is_null_it_should_fail() + { + // Arrange + var subject = default(DataColumnCollection); + + var expectation = new DataTable().Columns; + + // Act + Action action = + () => subject.Should().HaveSameCount(expectation, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected * to have the same count as * because we care, but found .*"); + } + [Fact] public void When_expectation_is_null_it_should_fail() { @@ -262,6 +279,23 @@ public void When_collection_is_compared_with_typed_collection_with_different_num public class NotHaveSameCount { + [Fact] + public void When_subject_is_null_it_should_fail() + { + // Arrange + var subject = default(DataColumnCollection); + + var expectation = new DataTable().Columns; + + // Act + Action action = + () => subject.Should().NotHaveSameCount(expectation, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected * to not have the same count as * because we care, but found .*"); + } + [Fact] public void When_expectation_is_null_it_should_fail() { diff --git a/Tests/FluentAssertions.Specs/Collections/Data/DataRowCollectionAssertionExtensionsSpecs.cs b/Tests/FluentAssertions.Specs/Collections/Data/DataRowCollectionAssertionExtensionsSpecs.cs index fc9fc72889..e5e7bb7738 100644 --- a/Tests/FluentAssertions.Specs/Collections/Data/DataRowCollectionAssertionExtensionsSpecs.cs +++ b/Tests/FluentAssertions.Specs/Collections/Data/DataRowCollectionAssertionExtensionsSpecs.cs @@ -163,6 +163,23 @@ public void When_references_are_different_it_should_succeed() public class HaveSameCount { + [Fact] + public void When_subject_is_null_it_should_fail() + { + // Arrange + var subject = default(DataRowCollection); + + var expectation = new DataTable().Rows; + + // Act + Action action = + () => subject.Should().HaveSameCount(expectation, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected * to have the same count as * because we care, but found .*"); + } + [Fact] public void When_expectation_is_null_it_should_fail() { @@ -302,6 +319,23 @@ public void When_collection_is_compared_with_typed_collection_with_different_num public class NotHaveSameCount { + [Fact] + public void When_subject_is_null_it_should_fail() + { + // Arrange + var subject = default(DataRowCollection); + + var expectation = new DataTable().Rows; + + // Act + Action action = + () => subject.Should().NotHaveSameCount(expectation, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected * to not have the same count as * because we care, but found .*"); + } + [Fact] public void When_expectation_is_null_it_should_fail() { diff --git a/Tests/FluentAssertions.Specs/Collections/Data/DataTableCollectionAssertionExtensionsSpecs.cs b/Tests/FluentAssertions.Specs/Collections/Data/DataTableCollectionAssertionExtensionsSpecs.cs index 51eb757d4f..2fcf27ec21 100644 --- a/Tests/FluentAssertions.Specs/Collections/Data/DataTableCollectionAssertionExtensionsSpecs.cs +++ b/Tests/FluentAssertions.Specs/Collections/Data/DataTableCollectionAssertionExtensionsSpecs.cs @@ -138,6 +138,23 @@ public void When_references_are_different_it_should_succeed() public class HaveSameCount { + [Fact] + public void When_subject_is_null_it_should_fail() + { + // Arrange + var subject = default(DataTableCollection); + + var expectation = new DataSet().Tables; + + // Act + Action action = + () => subject.Should().HaveSameCount(expectation, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected * to have the same count as * because we care, but found .*"); + } + [Fact] public void When_expectation_is_null_it_should_fail() { @@ -277,6 +294,23 @@ public void When_collection_is_compared_with_typed_collection_with_different_num public class NotHaveSameCount { + [Fact] + public void When_subject_is_null_it_should_fail() + { + // Arrange + var subject = default(DataTableCollection); + + var expectation = new DataSet().Tables; + + // Act + Action action = + () => subject.Should().NotHaveSameCount(expectation, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected * to not have the same count as * because we care, but found .*"); + } + [Fact] public void When_expectation_is_null_it_should_fail() {