diff --git a/Src/FluentAssertions/AssertionExtensions.cs b/Src/FluentAssertions/AssertionExtensions.cs index aa0b65309a..6755fc0467 100644 --- a/Src/FluentAssertions/AssertionExtensions.cs +++ b/Src/FluentAssertions/AssertionExtensions.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Linq; using System.Linq.Expressions; using System.Net.Http; using System.Reflection; @@ -385,6 +386,36 @@ public static StringCollectionAssertions Should(this IEnumerable @this) return new GenericDictionaryAssertions(actualValue); } + /// + /// Returns an assertions object that provides methods for asserting the state of a . + /// + [Pure] + public static GenericCollectionAssertions Should(this DataTableCollection actualValue) + { + return new GenericCollectionAssertions( + ReadOnlyNonGenericCollectionWrapper.Create(actualValue)); + } + + /// + /// Returns an assertions object that provides methods for asserting the state of a . + /// + [Pure] + public static GenericCollectionAssertions Should(this DataColumnCollection actualValue) + { + return new GenericCollectionAssertions( + ReadOnlyNonGenericCollectionWrapper.Create(actualValue)); + } + + /// + /// Returns an assertions object that provides methods for asserting the state of a . + /// + [Pure] + public static GenericCollectionAssertions Should(this DataRowCollection actualValue) + { + return new GenericCollectionAssertions( + ReadOnlyNonGenericCollectionWrapper.Create(actualValue)); + } + /// /// Returns a object that can be used to assert the /// current . diff --git a/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs b/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs new file mode 100644 index 0000000000..fc6fa22a81 --- /dev/null +++ b/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace FluentAssertions.Common +{ + internal static class ReadOnlyNonGenericCollectionWrapper + { + public static ReadOnlyNonGenericCollectionWrapper Create(DataTableCollection collection) + { + return + (collection != null) + ? new ReadOnlyNonGenericCollectionWrapper(collection) + : null; + } + + public static ReadOnlyNonGenericCollectionWrapper Create(DataColumnCollection collection) + { + return + (collection != null) + ? new ReadOnlyNonGenericCollectionWrapper(collection) + : null; + } + + public static ReadOnlyNonGenericCollectionWrapper Create(DataRowCollection collection) + { + return + (collection != null) + ? new ReadOnlyNonGenericCollectionWrapper(collection) + : null; + } + } + + internal class ReadOnlyNonGenericCollectionWrapper : ICollection + where TCollection : ICollection + { + public TCollection UnderlyingCollection { get; } + + public ReadOnlyNonGenericCollectionWrapper(TCollection collection) + { + Guard.ThrowIfArgumentIsNull(collection, nameof(collection)); + + UnderlyingCollection = collection; + } + + public int Count => UnderlyingCollection.Count; + + public bool IsReadOnly => true; + + public IEnumerator GetEnumerator() => UnderlyingCollection.Cast().GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => UnderlyingCollection.GetEnumerator(); + + public bool Contains(TItem item) => UnderlyingCollection.Cast().Contains(item); + + public void CopyTo(TItem[] array, int arrayIndex) => UnderlyingCollection.CopyTo(array, arrayIndex); + + /* + + Mutation is not supported, but these methods must be implemented to satisfy ICollection: + * Add + * Clear + * Remove + + */ + + public void Add(TItem item) => throw new NotSupportedException(); + + public void Clear() => throw new NotSupportedException(); + + public bool Remove(TItem item) => throw new NotSupportedException(); + } +} diff --git a/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs new file mode 100644 index 0000000000..8cc8362408 --- /dev/null +++ b/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Globalization; +using System.Linq; + +using FluentAssertions.Collections; +using FluentAssertions.Common; +using FluentAssertions.Execution; + +namespace FluentAssertions +{ + public static class DataColumnCollectionAssertionExtensions + { + /// + /// Asserts that an object reference refers to the exact same object as another object reference. + /// + /// The expected object + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> BeSameAs( + this GenericCollectionAssertions assertion, DataColumnCollection expected, string because = "", + params object[] becauseArgs) + { + Guard.ThrowIfArgumentIsNull( + expected, nameof(expected), "Cannot verify same reference against a collection (use BeNull instead?)."); + + if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + { + var actualSubject = wrapper.UnderlyingCollection; + + Execute.Assertion + .UsingLineBreaks + .ForCondition(ReferenceEquals(actualSubject, expected)) + .BecauseOf(because, becauseArgs) + .FailWith( + "Expected {context:column collection} to refer to {0}{reason}, but found {1} (different underlying object).", + expected, actualSubject); + } + else + { + Execute.Assertion + .BecauseOf(because, becauseArgs) + .FailWith( + "Invalid expectation: Expected {context:column collection} to refer to an instance of " + + "DataColumnCollection{reason}, but found {0}.", + assertion.Subject); + } + + return new AndConstraint>(assertion); + } + + /// + /// Asserts that an object reference refers to a different object than another object reference refers to. + /// + /// The unexpected object + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> NotBeSameAs( + this GenericCollectionAssertions assertion, DataColumnCollection unexpected, string because = "", + params object[] becauseArgs) + { + Guard.ThrowIfArgumentIsNull( + unexpected, nameof(unexpected), "Cannot verify same reference against a collection (use NotBeNull instead?)."); + + if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + { + var actualSubject = wrapper.UnderlyingCollection; + + Execute.Assertion + .UsingLineBreaks + .ForCondition(!ReferenceEquals(actualSubject, unexpected)) + .BecauseOf(because, becauseArgs) + .FailWith("Did not expect {context:column collection} to refer to {0}{reason}.", unexpected); + } + else + { + Execute.Assertion + .BecauseOf(because, becauseArgs) + .FailWith( + "Invalid expectation: Expected {context:column collection} to refer to a different instance of " + + "DataColumnCollection{reason}, but found {0}.", + assertion.Subject); + } + + return new AndConstraint>(assertion); + } + + /// + /// Assert that the current collection has the same number of elements as . + /// + /// The other collection with the same expected number of elements + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> HaveSameCount( + this GenericCollectionAssertions assertion, DataColumnCollection otherCollection, string because = "", + params object[] becauseArgs) + { + Guard.ThrowIfArgumentIsNull( + otherCollection, nameof(otherCollection), "Cannot verify count against a collection."); + + Execute.Assertion + .BecauseOf(because, becauseArgs) + .WithExpectation("Expected {context:collection} to have ") + .Given(() => assertion.Subject) + .ForCondition(subject => subject is not null) + .FailWith("the same count as {0}{reason}, but found .", otherCollection) + .Then + .Given((subject) => (actual: subject.Count(), expected: otherCollection.Count)) + .ForCondition(count => count.actual == count.expected) + .FailWith("{0} column(s){reason}, but found {1}.", count => count.expected, count => count.actual) + .Then + .ClearExpectation(); + + return new AndConstraint>(assertion); + } + + /// + /// Assert that the current collection of s does not have the same number of columns as + /// . + /// + /// The other with the unexpected number of + /// elements + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> NotHaveSameCount( + this GenericCollectionAssertions assertion, DataColumnCollection otherCollection, string because = "", + params object[] becauseArgs) + { + Guard.ThrowIfArgumentIsNull( + otherCollection, nameof(otherCollection), "Cannot verify count against a collection."); + + Execute.Assertion + .BecauseOf(because, becauseArgs) + .WithExpectation("Expected {context:collection} to not have ") + .Given(() => assertion.Subject) + .ForCondition(subject => subject is not null) + .FailWith("the same count as {0}{reason}, but found .", otherCollection) + .Then + .Given((subject) => (actual: subject.Count(), expected: otherCollection.Count)) + .ForCondition(count => count.actual != count.expected) + .FailWith("{0} column(s){reason}, but found {1}.", count => count.expected, count => count.actual) + .Then + .ClearExpectation(); + + return new AndConstraint>(assertion); + } + } +} diff --git a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs new file mode 100644 index 0000000000..ea5e745ff3 --- /dev/null +++ b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +using FluentAssertions.Collections; +using FluentAssertions.Common; +using FluentAssertions.Data; +using FluentAssertions.Equivalency; +using FluentAssertions.Execution; + +namespace FluentAssertions +{ + public static class DataRowCollectionAssertionExtensions + { + /// + /// Asserts that an object reference refers to the exact same object as another object reference. + /// + /// The expected object + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> BeSameAs( + this GenericCollectionAssertions assertion, DataRowCollection expected, string because = "", + params object[] becauseArgs) + { + if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + { + var actualSubject = wrapper.UnderlyingCollection; + + Execute.Assertion + .UsingLineBreaks + .ForCondition(ReferenceEquals(actualSubject, expected)) + .BecauseOf(because, becauseArgs) + .FailWith( + "Expected {context:row collection} to refer to {0}{reason}, but found {1} (different underlying object).", + expected, actualSubject); + } + else + { + Execute.Assertion + .BecauseOf(because, becauseArgs) + .FailWith( + "Invalid expectation: Expected {context:column collection} to refer to an instance of " + + "DataRowCollection{reason}, but found {0}.", + assertion.Subject); + } + + return new AndConstraint>(assertion); + } + + /// + /// Asserts that an object reference refers to a different object than another object reference refers to. + /// + /// The unexpected object + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> NotBeSameAs( + this GenericCollectionAssertions assertion, DataRowCollection unexpected, string because = "", + params object[] becauseArgs) + { + if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + { + var actualSubject = wrapper.UnderlyingCollection; + + Execute.Assertion + .UsingLineBreaks + .ForCondition(!ReferenceEquals(actualSubject, unexpected)) + .BecauseOf(because, becauseArgs) + .FailWith("Did not expect {context:row collection} to refer to {0}{reason}.", unexpected); + } + else + { + Execute.Assertion + .BecauseOf(because, becauseArgs) + .FailWith( + "Invalid expectation: Expected {context:column collection} to refer to a different instance of " + + "DataRowCollection{reason}, but found {0}.", + assertion.Subject); + } + + return new AndConstraint>(assertion); + } + + /// + /// Assert that the current collection of s has the same number of rows as + /// . + /// + /// The other collection with the same expected number of elements + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> HaveSameCount( + this GenericCollectionAssertions assertion, DataRowCollection otherCollection, string because = "", + params object[] becauseArgs) + { + Guard.ThrowIfArgumentIsNull( + otherCollection, nameof(otherCollection), "Cannot verify count against a collection."); + + Execute.Assertion + .BecauseOf(because, becauseArgs) + .WithExpectation("Expected {context:collection} to have ") + .Given(() => assertion.Subject) + .ForCondition(subject => subject is not null) + .FailWith("the same count as {0}{reason}, but found .", otherCollection) + .Then + .Given((subject) => (actual: subject.Count(), expected: otherCollection.Count)) + .ForCondition(count => count.actual == count.expected) + .FailWith("{0} row(s){reason}, but found {1}.", count => count.expected, count => count.actual) + .Then + .ClearExpectation(); + + return new AndConstraint>(assertion); + } + + /// + /// Assert that the current collection of s does not have the same number of rows as + /// . + /// + /// The other with the unexpected number of elements + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> NotHaveSameCount( + this GenericCollectionAssertions assertion, DataRowCollection otherCollection, string because = "", + params object[] becauseArgs) + { + Guard.ThrowIfArgumentIsNull( + otherCollection, nameof(otherCollection), "Cannot verify count against a collection."); + + Execute.Assertion + .BecauseOf(because, becauseArgs) + .WithExpectation("Expected {context:collection} to not have ") + .Given(() => assertion.Subject) + .ForCondition(subject => subject is not null) + .FailWith("the same count as {0}{reason}, but found .", otherCollection) + .Then + .Given((subject) => (actual: subject.Count(), expected: otherCollection.Count)) + .ForCondition(count => count.actual != count.expected) + .FailWith("{0} row(s){reason}, but found {1}.", count => count.expected, count => count.actual) + .Then + .ClearExpectation(); + + return new AndConstraint>(assertion); + } + } +} diff --git a/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs new file mode 100644 index 0000000000..76cdf9ea64 --- /dev/null +++ b/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs @@ -0,0 +1,199 @@ +using System; +using System.Data; +using System.Linq; + +using FluentAssertions.Collections; +using FluentAssertions.Common; +using FluentAssertions.Execution; + +namespace FluentAssertions +{ + public static class DataTableCollectionAssertionExtensions + { + /// + /// Asserts that an object reference refers to the exact same object as another object reference. + /// + /// The expected object + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> BeSameAs( + this GenericCollectionAssertions assertion, DataTableCollection expected, string because = "", + params object[] becauseArgs) + { + if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + { + var actualSubject = wrapper.UnderlyingCollection; + + Execute.Assertion + .UsingLineBreaks + .ForCondition(ReferenceEquals(actualSubject, expected)) + .BecauseOf(because, becauseArgs) + .FailWith( + "Expected {context:table collection} to refer to {0}{reason}, but found {1} (different underlying object).", + expected, actualSubject); + } + else + { + Execute.Assertion + .BecauseOf(because, becauseArgs) + .FailWith( + "Invalid expectation: Expected {context:column collection} to refer to an instance of " + + "DataTableCollection{reason}, but found {0}.", + assertion.Subject); + } + + return new AndConstraint>(assertion); + } + + /// + /// Asserts that an object reference refers to a different object than another object reference refers to. + /// + /// The unexpected object + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> NotBeSameAs( + this GenericCollectionAssertions assertion, DataTableCollection unexpected, string because = "", + params object[] becauseArgs) + { + if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + { + var actualSubject = wrapper.UnderlyingCollection; + + Execute.Assertion + .UsingLineBreaks + .ForCondition(!ReferenceEquals(actualSubject, unexpected)) + .BecauseOf(because, becauseArgs) + .FailWith("Did not expect {context:table collection} to refer to {0}{reason}.", unexpected); + } + else + { + Execute.Assertion + .BecauseOf(because, becauseArgs) + .FailWith( + "Invalid expectation: Expected {context:column collection} to refer to a different instance of " + + "DataTableCollection{reason}, but found {0}.", + assertion.Subject); + } + + return new AndConstraint>(assertion); + } + + /// + /// Assert that the current collection of s has the same number of tables as + /// . + /// + /// The other with the same expected number of tables + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> HaveSameCount( + this GenericCollectionAssertions assertion, DataSet otherDataSet, string because = "", + params object[] becauseArgs) + { + return assertion.HaveSameCount(otherDataSet.Tables, because, becauseArgs); + } + + /// + /// Assert that the current collection of s does not have the same number of tables as + /// . + /// + /// The other with the unexpected number of tables + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> NotHaveSameCount( + this GenericCollectionAssertions assertion, DataSet otherDataSet, string because = "", + params object[] becauseArgs) + { + return assertion.NotHaveSameCount(otherDataSet.Tables, because, becauseArgs); + } + + /// + /// Assert that the current collection of s has the same number of tables as + /// . + /// + /// The other with the same expected number of tables + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> HaveSameCount( + this GenericCollectionAssertions assertion, DataTableCollection otherCollection, string because = "", + params object[] becauseArgs) + { + Guard.ThrowIfArgumentIsNull( + otherCollection, nameof(otherCollection), "Cannot verify count against a collection."); + + Execute.Assertion + .BecauseOf(because, becauseArgs) + .WithExpectation("Expected {context:collection} to have ") + .Given(() => assertion.Subject) + .ForCondition(subject => subject is not null) + .FailWith("the same count as {0}{reason}, but found .", otherCollection) + .Then + .Given((subject) => (actual: subject.Count(), expected: otherCollection.Count)) + .ForCondition(count => count.actual == count.expected) + .FailWith("{0} table(s){reason}, but found {1}.", count => count.expected, count => count.actual) + .Then + .ClearExpectation(); + + return new AndConstraint>(assertion); + } + + /// + /// Assert that the current collection of s does not have the same number of tables as + /// . + /// + /// The other with the unexpected number of tables + /// + /// A formatted phrase as is supported by explaining why the assertion + /// is needed. If the phrase does not start with the word because, it is prepended automatically. + /// + /// + /// Zero or more objects to format using the placeholders in . + /// + public static AndConstraint> NotHaveSameCount( + this GenericCollectionAssertions assertion, DataTableCollection otherCollection, string because = "", + params object[] becauseArgs) + { + Guard.ThrowIfArgumentIsNull( + otherCollection, nameof(otherCollection), "Cannot verify count against a collection."); + + Execute.Assertion + .BecauseOf(because, becauseArgs) + .WithExpectation("Expected {context:collection} to not have ") + .Given(() => assertion.Subject) + .ForCondition(subject => subject is not null) + .FailWith("the same count as {0}{reason}, but found .", otherCollection) + .Then + .Given((subject) => (actual: subject.Count(), expected: otherCollection.Count)) + .ForCondition(count => count.actual != count.expected) + .FailWith("{0} table(s){reason}, but found {1}.", count => count.expected, count => count.actual) + .Then + .ClearExpectation(); + + return new AndConstraint>(assertion); + } + } +} diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt index 4682ecdc00..3ac19edafa 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt @@ -58,6 +58,9 @@ namespace FluentAssertions public static FluentAssertions.Specialized.ActionAssertions Should(this System.Action action) { } public static FluentAssertions.Collections.StringCollectionAssertions Should(this System.Collections.Generic.IEnumerable @this) { } public static FluentAssertions.Data.DataColumnAssertions Should(this System.Data.DataColumn actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataColumnCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataRowCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataTableCollection actualValue) { } public static FluentAssertions.Primitives.DateTimeAssertions Should(this System.DateTime actualValue) { } public static FluentAssertions.Primitives.NullableDateTimeAssertions Should(this System.DateTime? actualValue) { } public static FluentAssertions.Primitives.DateTimeOffsetAssertions Should(this System.DateTimeOffset actualValue) { } @@ -187,11 +190,25 @@ namespace FluentAssertions { public CustomAssertionAttribute() { } } + public static class DataColumnCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataRowAssertionExtensions { public static FluentAssertions.Data.DataRowAssertions Should(this TDataRow actualValue) where TDataRow : System.Data.DataRow { } } + public static class DataRowCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataSetAssertionExtensions { public static FluentAssertions.Data.DataSetAssertions Should(this TDataSet actualValue) @@ -202,6 +219,15 @@ namespace FluentAssertions public static FluentAssertions.Data.DataTableAssertions Should(this TDataTable actualValue) where TDataTable : System.Data.DataTable { } } + public static class DataTableCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class EnumAssertionsExtensions { public static FluentAssertions.Primitives.EnumAssertions Should(this TEnum @enum) diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt index 9fa5350cd3..36cdeff676 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt @@ -58,6 +58,9 @@ namespace FluentAssertions public static FluentAssertions.Specialized.ActionAssertions Should(this System.Action action) { } public static FluentAssertions.Collections.StringCollectionAssertions Should(this System.Collections.Generic.IEnumerable @this) { } public static FluentAssertions.Data.DataColumnAssertions Should(this System.Data.DataColumn actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataColumnCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataRowCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataTableCollection actualValue) { } public static FluentAssertions.Primitives.DateOnlyAssertions Should(this System.DateOnly actualValue) { } public static FluentAssertions.Primitives.NullableDateOnlyAssertions Should(this System.DateOnly? actualValue) { } public static FluentAssertions.Primitives.DateTimeAssertions Should(this System.DateTime actualValue) { } @@ -199,11 +202,25 @@ namespace FluentAssertions { public CustomAssertionAttribute() { } } + public static class DataColumnCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataRowAssertionExtensions { public static FluentAssertions.Data.DataRowAssertions Should(this TDataRow actualValue) where TDataRow : System.Data.DataRow { } } + public static class DataRowCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataSetAssertionExtensions { public static FluentAssertions.Data.DataSetAssertions Should(this TDataSet actualValue) @@ -214,6 +231,15 @@ namespace FluentAssertions public static FluentAssertions.Data.DataTableAssertions Should(this TDataTable actualValue) where TDataTable : System.Data.DataTable { } } + public static class DataTableCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class EnumAssertionsExtensions { public static FluentAssertions.Primitives.EnumAssertions Should(this TEnum @enum) diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt index 16751afb56..7de57cf1c1 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt @@ -58,6 +58,9 @@ namespace FluentAssertions public static FluentAssertions.Specialized.ActionAssertions Should(this System.Action action) { } public static FluentAssertions.Collections.StringCollectionAssertions Should(this System.Collections.Generic.IEnumerable @this) { } public static FluentAssertions.Data.DataColumnAssertions Should(this System.Data.DataColumn actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataColumnCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataRowCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataTableCollection actualValue) { } public static FluentAssertions.Primitives.DateTimeAssertions Should(this System.DateTime actualValue) { } public static FluentAssertions.Primitives.NullableDateTimeAssertions Should(this System.DateTime? actualValue) { } public static FluentAssertions.Primitives.DateTimeOffsetAssertions Should(this System.DateTimeOffset actualValue) { } @@ -187,11 +190,25 @@ namespace FluentAssertions { public CustomAssertionAttribute() { } } + public static class DataColumnCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataRowAssertionExtensions { public static FluentAssertions.Data.DataRowAssertions Should(this TDataRow actualValue) where TDataRow : System.Data.DataRow { } } + public static class DataRowCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataSetAssertionExtensions { public static FluentAssertions.Data.DataSetAssertions Should(this TDataSet actualValue) @@ -202,6 +219,15 @@ namespace FluentAssertions public static FluentAssertions.Data.DataTableAssertions Should(this TDataTable actualValue) where TDataTable : System.Data.DataTable { } } + public static class DataTableCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class EnumAssertionsExtensions { public static FluentAssertions.Primitives.EnumAssertions Should(this TEnum @enum) diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt index f9e4753c6e..9cff0a8291 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt @@ -58,6 +58,9 @@ namespace FluentAssertions public static FluentAssertions.Specialized.ActionAssertions Should(this System.Action action) { } public static FluentAssertions.Collections.StringCollectionAssertions Should(this System.Collections.Generic.IEnumerable @this) { } public static FluentAssertions.Data.DataColumnAssertions Should(this System.Data.DataColumn actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataColumnCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataRowCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataTableCollection actualValue) { } public static FluentAssertions.Primitives.DateTimeAssertions Should(this System.DateTime actualValue) { } public static FluentAssertions.Primitives.NullableDateTimeAssertions Should(this System.DateTime? actualValue) { } public static FluentAssertions.Primitives.DateTimeOffsetAssertions Should(this System.DateTimeOffset actualValue) { } @@ -187,11 +190,25 @@ namespace FluentAssertions { public CustomAssertionAttribute() { } } + public static class DataColumnCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataRowAssertionExtensions { public static FluentAssertions.Data.DataRowAssertions Should(this TDataRow actualValue) where TDataRow : System.Data.DataRow { } } + public static class DataRowCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataSetAssertionExtensions { public static FluentAssertions.Data.DataSetAssertions Should(this TDataSet actualValue) @@ -202,6 +219,15 @@ namespace FluentAssertions public static FluentAssertions.Data.DataTableAssertions Should(this TDataTable actualValue) where TDataTable : System.Data.DataTable { } } + public static class DataTableCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class EnumAssertionsExtensions { public static FluentAssertions.Primitives.EnumAssertions Should(this TEnum @enum) diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt index ec7b7c008f..3391e7ae6c 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt @@ -57,6 +57,9 @@ namespace FluentAssertions public static FluentAssertions.Specialized.ActionAssertions Should(this System.Action action) { } public static FluentAssertions.Collections.StringCollectionAssertions Should(this System.Collections.Generic.IEnumerable @this) { } public static FluentAssertions.Data.DataColumnAssertions Should(this System.Data.DataColumn actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataColumnCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataRowCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataTableCollection actualValue) { } public static FluentAssertions.Primitives.DateTimeAssertions Should(this System.DateTime actualValue) { } public static FluentAssertions.Primitives.NullableDateTimeAssertions Should(this System.DateTime? actualValue) { } public static FluentAssertions.Primitives.DateTimeOffsetAssertions Should(this System.DateTimeOffset actualValue) { } @@ -186,11 +189,25 @@ namespace FluentAssertions { public CustomAssertionAttribute() { } } + public static class DataColumnCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataRowAssertionExtensions { public static FluentAssertions.Data.DataRowAssertions Should(this TDataRow actualValue) where TDataRow : System.Data.DataRow { } } + public static class DataRowCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataSetAssertionExtensions { public static FluentAssertions.Data.DataSetAssertions Should(this TDataSet actualValue) @@ -201,6 +218,15 @@ namespace FluentAssertions public static FluentAssertions.Data.DataTableAssertions Should(this TDataTable actualValue) where TDataTable : System.Data.DataTable { } } + public static class DataTableCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class EnumAssertionsExtensions { public static FluentAssertions.Primitives.EnumAssertions Should(this TEnum @enum) diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt index 25938a8a06..e118ff6c79 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt @@ -58,6 +58,9 @@ namespace FluentAssertions public static FluentAssertions.Specialized.ActionAssertions Should(this System.Action action) { } public static FluentAssertions.Collections.StringCollectionAssertions Should(this System.Collections.Generic.IEnumerable @this) { } public static FluentAssertions.Data.DataColumnAssertions Should(this System.Data.DataColumn actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataColumnCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataRowCollection actualValue) { } + public static FluentAssertions.Collections.GenericCollectionAssertions Should(this System.Data.DataTableCollection actualValue) { } public static FluentAssertions.Primitives.DateTimeAssertions Should(this System.DateTime actualValue) { } public static FluentAssertions.Primitives.NullableDateTimeAssertions Should(this System.DateTime? actualValue) { } public static FluentAssertions.Primitives.DateTimeOffsetAssertions Should(this System.DateTimeOffset actualValue) { } @@ -187,11 +190,25 @@ namespace FluentAssertions { public CustomAssertionAttribute() { } } + public static class DataColumnCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataColumnCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataRowAssertionExtensions { public static FluentAssertions.Data.DataRowAssertions Should(this TDataRow actualValue) where TDataRow : System.Data.DataRow { } } + public static class DataRowCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataRowCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class DataSetAssertionExtensions { public static FluentAssertions.Data.DataSetAssertions Should(this TDataSet actualValue) @@ -202,6 +219,15 @@ namespace FluentAssertions public static FluentAssertions.Data.DataTableAssertions Should(this TDataTable actualValue) where TDataTable : System.Data.DataTable { } } + public static class DataTableCollectionAssertionExtensions + { + public static FluentAssertions.AndConstraint> BeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection expected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> HaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotBeSameAs(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection unexpected, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataSet otherDataSet, string because = "", params object[] becauseArgs) { } + public static FluentAssertions.AndConstraint> NotHaveSameCount(this FluentAssertions.Collections.GenericCollectionAssertions assertion, System.Data.DataTableCollection otherCollection, string because = "", params object[] becauseArgs) { } + } public static class EnumAssertionsExtensions { public static FluentAssertions.Primitives.EnumAssertions Should(this TEnum @enum) diff --git a/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionSpecs.cs new file mode 100644 index 0000000000..1fd9b4f1c9 --- /dev/null +++ b/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionSpecs.cs @@ -0,0 +1,441 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using FluentAssertions.Execution; + +using Xunit; +using Xunit.Sdk; + +namespace FluentAssertions.Specs.Collections.Data +{ + public static class DataColumnCollectionAssertionSpecs + { + public class BeSameAs + { + [Fact] + public void When_references_are_the_same_it_should_succeed() + { + // Arrange + var dataTable = new DataTable("Test"); + + var columnCollection1 = dataTable.Columns; + var columnCollection2 = columnCollection1; + + // Act & Assert + columnCollection1.Should().BeSameAs(columnCollection2); + } + + [Fact] + public void When_references_are_different_it_should_fail() + { + // Arrange + var dataTable1 = new DataTable("Test1"); + var dataTable2 = new DataTable("Test2"); + + var columnCollection1 = dataTable1.Columns; + var columnCollection2 = dataTable2.Columns; + + // Act + Action action = + () => columnCollection1.Should().BeSameAs(columnCollection2); + + // Assert + action.Should().Throw().WithMessage( + "Expected columnCollection1 to refer to *, but found * (different underlying object)."); + } + + [Fact] + public void When_generic_collection_is_tested_against_typed_collection_it_should_fail() + { + // Arrange + var dataTable = new DataTable("Test"); + + var columnCollection = dataTable.Columns; + + var genericCollection = columnCollection.Cast(); + + // Act + Action action = + () => genericCollection.Should().BeSameAs(columnCollection, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Invalid expectation: Expected genericCollection to refer to an instance of DataColumnCollection " + + "because we care, but found *."); + } + } + + public class NotBeSameAs + { + [Fact] + public void When_references_are_the_same_it_should_fail() + { + // Arrange + var dataTable = new DataTable("Test"); + + var columnCollection1 = dataTable.Columns; + var columnCollection2 = columnCollection1; + + // Act + Action action = + () => columnCollection1.Should().NotBeSameAs(columnCollection2); + + // Assert + action.Should().Throw().WithMessage("Did not expect columnCollection1 to refer to *."); + } + + [Fact] + public void When_references_are_different_it_should_succeed() + { + // Arrange + var dataTable1 = new DataTable("Test1"); + var dataTable2 = new DataTable("Test2"); + + var columnCollection1 = dataTable1.Columns; + var columnCollection2 = dataTable2.Columns; + + // Act & Assert + columnCollection1.Should().NotBeSameAs(columnCollection2); + } + + [Fact] + public void When_generic_collection_is_tested_against_typed_collection_it_should_fail() + { + // Arrange + var dataTable = new DataTable("Test"); + + var columnCollection = dataTable.Columns; + + var genericCollection = columnCollection.Cast(); + + // Act + Action action = + () => genericCollection.Should().NotBeSameAs(columnCollection, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Invalid expectation: Expected genericCollection to refer to a different instance of " + + "DataColumnCollection because we care, but found *."); + } + } + + 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() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Columns.Add(new DataColumn("Column0")); + dataTable.Columns.Add(new DataColumn("Column1")); + dataTable.Columns.Add(new DataColumn("Column2")); + + var nullReference = default(DataColumnCollection); + + // Act + Action action = + () => dataTable.Columns.Should().HaveSameCount(nullReference); + + // Assert + action.Should().Throw().WithMessage( + "Cannot verify count against a collection.*"); + } + + public class DataColumnCollectionAssertions + { + [Fact] + public void When_two_collections_have_the_same_number_of_columns_it_should_succeed() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Columns.Add(new DataColumn("Column0")); + firstDataTable.Columns.Add(new DataColumn("Column1")); + firstDataTable.Columns.Add(new DataColumn("Column2")); + + secondDataTable.Columns.Add(new DataColumn("Column10")); + secondDataTable.Columns.Add(new DataColumn("Column11")); + secondDataTable.Columns.Add(new DataColumn("Column12")); + + // Act & Assert + firstDataTable.Columns.Should().HaveSameCount(secondDataTable.Columns); + } + + [Fact] + public void When_two_collections_do_not_have_the_same_number_of_columns_it_should_fail() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Columns.Add(new DataColumn("Column0")); + firstDataTable.Columns.Add(new DataColumn("Column1")); + firstDataTable.Columns.Add(new DataColumn("Column2")); + + secondDataTable.Columns.Add(new DataColumn("Column10")); + secondDataTable.Columns.Add(new DataColumn("Column12")); + + // Act + Action action = + () => firstDataTable.Columns.Should().HaveSameCount(secondDataTable.Columns); + + // Assert + action.Should().Throw().WithMessage( + "Expected firstDataTable.Columns to have 2 column(s), but found 3."); + } + } + + public class GenericCollectionAssertions + { + [Fact] + public void When_collection_is_compared_with_null_it_should_fail() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Columns.Add(new DataColumn("Column0")); + dataTable.Columns.Add(new DataColumn("Column1")); + dataTable.Columns.Add(new DataColumn("Column2")); + + List nullDataColumns = null; + + // Act + Action action = + () => nullDataColumns.Should().HaveSameCount(dataTable.Columns, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected nullDataColumns to have the same count as * because we care, but found ."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_same_number_of_columns_it_should_succeed() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Columns.Add(new DataColumn("Column0")); + firstDataTable.Columns.Add(new DataColumn("Column1")); + firstDataTable.Columns.Add(new DataColumn("Column2")); + + secondDataTable.Columns.Add(new DataColumn("Column10")); + secondDataTable.Columns.Add(new DataColumn("Column11")); + secondDataTable.Columns.Add(new DataColumn("Column12")); + + var genericDataColumnCollection = firstDataTable.Columns.Cast(); + + // Act & Assert + genericDataColumnCollection.Should().HaveSameCount(secondDataTable.Columns); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_different_number_of_columns_it_should_fail() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Columns.Add(new DataColumn("Column0")); + firstDataTable.Columns.Add(new DataColumn("Column1")); + firstDataTable.Columns.Add(new DataColumn("Column2")); + + secondDataTable.Columns.Add(new DataColumn("Column10")); + secondDataTable.Columns.Add(new DataColumn("Column12")); + + var genericDataColumnCollection = firstDataTable.Columns.Cast(); + + // Act + Action action = + () => genericDataColumnCollection.Should().HaveSameCount(secondDataTable.Columns, + because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected genericDataColumnCollection to have 2 column(s) because we care, but found 3."); + } + } + } + + 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() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Columns.Add(new DataColumn("Column0")); + dataTable.Columns.Add(new DataColumn("Column1")); + dataTable.Columns.Add(new DataColumn("Column2")); + + var nullReference = default(DataColumnCollection); + + // Act + Action action = + () => dataTable.Columns.Should().NotHaveSameCount(nullReference); + + // Assert + action.Should().Throw().WithMessage( + "Cannot verify count against a collection.*"); + } + + public class DataColumnCollectionAssertions + { + [Fact] + public void When_two_collections_have_different_number_of_columns_it_should_succeed() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Columns.Add(new DataColumn("Column0")); + firstDataTable.Columns.Add(new DataColumn("Column1")); + firstDataTable.Columns.Add(new DataColumn("Column2")); + + secondDataTable.Columns.Add(new DataColumn("Column10")); + secondDataTable.Columns.Add(new DataColumn("Column12")); + + // Act & Assert + firstDataTable.Columns.Should().NotHaveSameCount(secondDataTable.Columns); + } + + [Fact] + public void When_two_collections_have_the_same_number_of_columns_it_should_fail() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Columns.Add(new DataColumn("Column0")); + firstDataTable.Columns.Add(new DataColumn("Column1")); + firstDataTable.Columns.Add(new DataColumn("Column2")); + + secondDataTable.Columns.Add(new DataColumn("Column10")); + secondDataTable.Columns.Add(new DataColumn("Column11")); + secondDataTable.Columns.Add(new DataColumn("Column12")); + + // Act + Action action = + () => firstDataTable.Columns.Should().NotHaveSameCount(secondDataTable.Columns, + because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected firstDataTable.Columns to not have 3 column(s) because we care, but found 3."); + } + } + + public class GenericCollectionAssertions + { + [Fact] + public void When_collection_is_compared_with_null_it_should_fail() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Columns.Add(new DataColumn("Column0")); + dataTable.Columns.Add(new DataColumn("Column1")); + dataTable.Columns.Add(new DataColumn("Column2")); + + List nullDataColumns = null; + + // Act + Action action = + () => nullDataColumns.Should().NotHaveSameCount(dataTable.Columns, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected nullDataColumns to not have the same count as * because we care, but found ."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_same_number_of_columns_it_should_fail() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Columns.Add(new DataColumn("Column0")); + firstDataTable.Columns.Add(new DataColumn("Column1")); + firstDataTable.Columns.Add(new DataColumn("Column2")); + + secondDataTable.Columns.Add(new DataColumn("Column10")); + secondDataTable.Columns.Add(new DataColumn("Column11")); + secondDataTable.Columns.Add(new DataColumn("Column12")); + + var genericDataColumnCollection = firstDataTable.Columns.Cast(); + + // Act + Action action = + () => genericDataColumnCollection.Should().NotHaveSameCount(secondDataTable.Columns, + because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected genericDataColumnCollection to not have 3 column(s) because we care, but found 3."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_different_number_of_columns_it_should_succeed() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Columns.Add(new DataColumn("Column0")); + firstDataTable.Columns.Add(new DataColumn("Column1")); + firstDataTable.Columns.Add(new DataColumn("Column2")); + + secondDataTable.Columns.Add(new DataColumn("Column10")); + secondDataTable.Columns.Add(new DataColumn("Column12")); + + var genericDataColumnCollection = firstDataTable.Columns.Cast(); + + // Act & Assert + genericDataColumnCollection.Should().NotHaveSameCount(secondDataTable.Columns); + } + } + } + } +} diff --git a/Tests/FluentAssertions.Specs/Collections/Data/DataRowCollectionAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Collections/Data/DataRowCollectionAssertionSpecs.cs new file mode 100644 index 0000000000..fdcde5ea45 --- /dev/null +++ b/Tests/FluentAssertions.Specs/Collections/Data/DataRowCollectionAssertionSpecs.cs @@ -0,0 +1,608 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using FluentAssertions.Execution; + +using Xunit; +using Xunit.Sdk; + +namespace FluentAssertions.Specs.Collections.Data +{ + public static class DataRowCollectionAssertionSpecs + { + public class BeSameAs + { + [Fact] + public void When_references_are_the_same_it_should_succeed() + { + // Arrange + var dataTable = new DataTable("Test"); + + var rowCollection1 = dataTable.Rows; + var rowCollection2 = rowCollection1; + + // Act & Assert + rowCollection1.Should().BeSameAs(rowCollection2); + } + + [Fact] + public void When_references_are_different_it_should_fail() + { + // Arrange + var dataTable1 = new DataTable("Test1"); + var dataTable2 = new DataTable("Test2"); + + var rowCollection1 = dataTable1.Rows; + var rowCollection2 = dataTable2.Rows; + + // Act + Action action = + () => rowCollection1.Should().BeSameAs(rowCollection2); + + // Assert + action.Should().Throw().WithMessage( + "Expected rowCollection1 to refer to *, but found * (different underlying object)."); + } + + [Fact] + public void When_generic_collection_is_tested_against_typed_collection_it_should_fail() + { + // Arrange + var dataTable = new DataTable("Test"); + + var rowCollection = dataTable.Rows; + + var genericCollection = rowCollection.Cast(); + + // Act + Action action = + () => genericCollection.Should().BeSameAs(rowCollection, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Invalid expectation: Expected genericCollection to refer to an instance of DataRowCollection " + + "because we care, but found *."); + } + } + + public class NotBeSameAs + { + [Fact] + public void When_references_are_the_same_object_it_should_fail() + { + // Arrange + var dataTable = new DataTable("Test"); + + var rowCollection1 = dataTable.Rows; + var rowCollection2 = rowCollection1; + + // Act + Action action = + () => rowCollection1.Should().NotBeSameAs(rowCollection2); + + // Assert + action.Should().Throw().WithMessage("Did not expect rowCollection1 to refer to *."); + } + + [Fact] + public void When_references_are_different_it_should_succeed() + { + // Arrange + var dataTable1 = new DataTable("Test1"); + var dataTable2 = new DataTable("Test2"); + + var rowCollection1 = dataTable1.Rows; + var rowCollection2 = dataTable2.Rows; + + // Act & Assert + rowCollection1.Should().NotBeSameAs(rowCollection2); + } + + [Fact] + public void When_generic_collection_is_tested_against_typed_collection_it_should_fail() + { + // Arrange + var dataTable = new DataTable("Test"); + + var rowCollection = dataTable.Rows; + + var genericCollection = rowCollection.Cast(); + + // Act + Action action = + () => genericCollection.Should().NotBeSameAs(rowCollection, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Invalid expectation: Expected genericCollection to refer to a different instance of " + + "DataRowCollection because we care, but found *."); + } + } + + 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() + { + // Arrange + var dataTable = new DataTable(); + + var nullReference = default(DataRowCollection); + + // Act + Action action = + () => dataTable.Rows.Should().HaveSameCount(nullReference); + + // Assert + action.Should().Throw().WithMessage( + "Cannot verify count against a collection.*"); + } + + public class DataRowCollectionAssertions + { + [Fact] + public void When_two_collections_have_the_same_number_of_rows_it_should_succeed() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + + // Act & Assert + firstDataTable.Rows.Should().HaveSameCount(secondDataTable.Rows); + } + + [Fact] + public void When_two_collections_do_not_have_the_same_number_of_rows_it_should_fail() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + + // Act + Action action = + () => firstDataTable.Rows.Should().HaveSameCount(secondDataTable.Rows); + + // Assert + action.Should().Throw().WithMessage( + "Expected firstDataTable.Rows to have 2 row(s), but found 3."); + } + } + + public class GenericCollectionAssertions + { + [Fact] + public void When_collection_is_compared_with_null_it_should_fail() + { + // Arrange + var dataTable = new DataTable(); + + List nullDataRows = null; + + // Act + Action action = + () => nullDataRows.Should().HaveSameCount(dataTable.Rows, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected nullDataRows to have the same count as * because we care, but found ."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_same_number_of_rows_it_should_succeed() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + + var genericDataRowCollection = firstDataTable.Rows.Cast(); + + // Act & Assert + genericDataRowCollection.Should().HaveSameCount(secondDataTable.Rows); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_different_number_of_rows_it_should_fail() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + + var genericDataRowCollection = firstDataTable.Rows.Cast(); + + // Act + Action action = + () => genericDataRowCollection.Should().HaveSameCount(secondDataTable.Rows, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected genericDataRowCollection to have 2 row(s) because we care, but found 3."); + } + } + } + + 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() + { + // Arrange + var dataTable = new DataTable(); + + var nullReference = default(DataRowCollection); + + // Act + Action action = + () => dataTable.Rows.Should().NotHaveSameCount(nullReference); + + // Assert + action.Should().Throw().WithMessage( + "Cannot verify count against a collection.*"); + } + + public class DataRowCollectionAssertions + { + [Fact] + public void When_two_collections_have_different_number_of_rows_it_should_succeed() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + + // Act & Assert + firstDataTable.Rows.Should().NotHaveSameCount(secondDataTable.Rows); + } + + [Fact] + public void When_two_collections_have_the_same_number_rows_it_should_fail() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + + // Act + Action action = + () => firstDataTable.Rows.Should().NotHaveSameCount(secondDataTable.Rows, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected firstDataTable.Rows to not have 3 row(s) because we care, but found 3."); + } + } + + public class GenericCollectionAssertions + { + [Fact] + public void When_collection_is_compared_with_null_it_should_fail() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Rows.Add(); + dataTable.Rows.Add(); + dataTable.Rows.Add(); + + List nullDataRows = null; + + // Act + Action action = + () => nullDataRows.Should().NotHaveSameCount(dataTable.Rows, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected nullDataRows to not have the same count as * because we care, but found ."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_same_number_of_rows_it_should_fail() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + + var genericDataRowCollection = firstDataTable.Rows.Cast(); + + // Act + Action action = + () => genericDataRowCollection.Should().NotHaveSameCount(secondDataTable.Rows, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected genericDataRowCollection to not have 3 row(s) because we care, but found 3."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_different_number_of_rows_it_should_succeed() + { + // Arrange + var firstDataTable = new DataTable(); + var secondDataTable = new DataTable(); + + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + firstDataTable.Rows.Add(); + + secondDataTable.Rows.Add(); + secondDataTable.Rows.Add(); + + var genericDataRowCollection = firstDataTable.Rows.Cast(); + + // Act & Assert + genericDataRowCollection.Should().NotHaveSameCount(secondDataTable.Rows); + } + } + } + + // These tests are present to ensure that we can trust DataRow equivalency in the context of ContainEquivalentOf. + public class ContainEquivalentOf + { + [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().ContainEquivalentOf(expectation, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected * to contain equivalent of * because we care, but found .*"); + } + + [Fact] + public void When_collection_contains_equivalent_row_it_should_succeed() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Columns.Add("RowID", typeof(Guid)); + dataTable.Columns.Add("Description", typeof(string)); + dataTable.Columns.Add("Number", typeof(int)); + dataTable.Columns.Add("Flag", typeof(bool)); + dataTable.Columns.Add("Timestamp", typeof(DateTime)); + + dataTable.Rows.Add(new Guid("6f460c1a-755d-d8e4-ad67-65d5f519dbc8"), "1851925803", 2137491580, true, new DateTime(638898932425580731)); + dataTable.Rows.Add(new Guid("8286d046-9740-a3e4-95cf-ff46699c73c4"), "607156385", 1321446349, true, new DateTime(641752306337096884)); + dataTable.Rows.Add(new Guid("95c69371-b924-6fe3-7c38-98b7dd200bc1"), "1509870614", 505401118, true, new DateTime(623130841631129390)); + + var subjectTable = new DataTable(); + + subjectTable.Columns.Add("RowID", typeof(Guid)); + subjectTable.Columns.Add("Description", typeof(string)); + subjectTable.Columns.Add("Number", typeof(int)); + subjectTable.Columns.Add("Flag", typeof(bool)); + subjectTable.Columns.Add("Timestamp", typeof(DateTime)); + + subjectTable.Rows.Add(new Guid("95c69371-b924-6fe3-7c38-98b7dd200bc1"), "1509870614", 505401118, true, new DateTime(623130841631129390)); + + var subjectRow = subjectTable.Rows[0]; + + // Act & Assert + dataTable.Rows.Should().ContainEquivalentOf(subjectRow); + } + + [Fact] + public void When_collection_does_not_contain_equivalent_row_it_should_fail() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Columns.Add("RowID", typeof(Guid)); + dataTable.Columns.Add("Description", typeof(string)); + dataTable.Columns.Add("Number", typeof(int)); + dataTable.Columns.Add("Flag", typeof(bool)); + dataTable.Columns.Add("Timestamp", typeof(DateTime)); + + dataTable.Rows.Add(new Guid("8286d046-9740-a3e4-95cf-ff46699c73c4"), "607156385", 1321446349, true, new DateTime(641752306337096884)); + dataTable.Rows.Add(new Guid("95c69371-b924-6fe3-7c38-98b7dd200bc1"), "1509870614", 505401118, true, new DateTime(623130841631129390)); + dataTable.Rows.Add(new Guid("a905569d-db07-3ae3-63a0-322750a4a3bd"), "265101196", 1836839534, true, new DateTime(625984215542645543)); + + var subjectTable = new DataTable(); + + subjectTable.Columns.Add("RowID", typeof(Guid)); + subjectTable.Columns.Add("Description", typeof(string)); + subjectTable.Columns.Add("Number", typeof(int)); + subjectTable.Columns.Add("Flag", typeof(bool)); + subjectTable.Columns.Add("Timestamp", typeof(DateTime)); + + subjectTable.Rows.Add(new Guid("bc4519c8-fdeb-06e2-4a08-cc98c4273aba"), "1167815425", 1020794303, true, new DateTime(628837589454161696)); + + var subjectRow = subjectTable.Rows[0]; + + // Act + Action action = + () => dataTable.Rows.Should().ContainEquivalentOf(subjectRow, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected dataTable.Rows * to contain equivalent of System.Data.DataRow* because we care.*"); + } + } + + // These tests are present to ensure that we can trust DataRow equivalency in the context of NotContainEquivalentOf. + public class NotContainEquivalentOf + { + [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().NotContainEquivalentOf(expectation, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected * not to contain equivalent of * because we care, but collection is .*"); + } + + [Fact] + public void When_collection_contains_equivalent_row_it_should_fail() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Columns.Add("RowID", typeof(Guid)); + dataTable.Columns.Add("Description", typeof(string)); + dataTable.Columns.Add("Number", typeof(int)); + dataTable.Columns.Add("Flag", typeof(bool)); + dataTable.Columns.Add("Timestamp", typeof(DateTime)); + + dataTable.Rows.Add(new Guid("8286d046-9740-a3e4-95cf-ff46699c73c4"), "607156385", 1321446349, true, new DateTime(641752306337096884)); + dataTable.Rows.Add(new Guid("95c69371-b924-6fe3-7c38-98b7dd200bc1"), "1509870614", 505401118, true, new DateTime(623130841631129390)); + dataTable.Rows.Add(new Guid("a905569d-db07-3ae3-63a0-322750a4a3bd"), "265101196", 1836839534, true, new DateTime(625984215542645543)); + + var subjectTable = new DataTable(); + + subjectTable.Columns.Add("RowID", typeof(Guid)); + subjectTable.Columns.Add("Description", typeof(string)); + subjectTable.Columns.Add("Number", typeof(int)); + subjectTable.Columns.Add("Flag", typeof(bool)); + subjectTable.Columns.Add("Timestamp", typeof(DateTime)); + + subjectTable.Rows.Add(new Guid("95c69371-b924-6fe3-7c38-98b7dd200bc1"), "1509870614", 505401118, true, new DateTime(623130841631129390)); + + var subjectRow = subjectTable.Rows[0]; + + // Act + Action action = + () => dataTable.Rows.Should().NotContainEquivalentOf(subjectRow, because: "we {0}", "care"); + + // Assert + action.Should().Throw() + .WithMessage("Expected dataTable.Rows * not to contain equivalent of System.Data.DataRow* because we " + + "care, but found one at index 1.*"); + } + + [Fact] + public void When_collection_does_not_contain_equivalent_row_it_should_succeed() + { + // Arrange + var dataTable = new DataTable(); + + dataTable.Columns.Add("RowID", typeof(Guid)); + dataTable.Columns.Add("Description", typeof(string)); + dataTable.Columns.Add("Number", typeof(int)); + dataTable.Columns.Add("Flag", typeof(bool)); + dataTable.Columns.Add("Timestamp", typeof(DateTime)); + + dataTable.Rows.Add(new Guid("8286d046-9740-a3e4-95cf-ff46699c73c4"), "607156385", 1321446349, true, new DateTime(641752306337096884)); + dataTable.Rows.Add(new Guid("95c69371-b924-6fe3-7c38-98b7dd200bc1"), "1509870614", 505401118, true, new DateTime(623130841631129390)); + dataTable.Rows.Add(new Guid("a905569d-db07-3ae3-63a0-322750a4a3bd"), "265101196", 1836839534, true, new DateTime(625984215542645543)); + + var subjectTable = new DataTable(); + + subjectTable.Columns.Add("RowID", typeof(Guid)); + subjectTable.Columns.Add("Description", typeof(string)); + subjectTable.Columns.Add("Number", typeof(int)); + subjectTable.Columns.Add("Flag", typeof(bool)); + subjectTable.Columns.Add("Timestamp", typeof(DateTime)); + + subjectTable.Rows.Add(new Guid("bc4519c8-fdeb-06e2-4a08-cc98c4273aba"), "1167815425", 1020794303, true, new DateTime(628837589454161696)); + + var subjectRow = subjectTable.Rows[0]; + + // Act & Assert + dataTable.Rows.Should().NotContainEquivalentOf(subjectRow); + } + } + } +} diff --git a/Tests/FluentAssertions.Specs/Collections/Data/DataTableCollectionAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Collections/Data/DataTableCollectionAssertionSpecs.cs new file mode 100644 index 0000000000..de934009e0 --- /dev/null +++ b/Tests/FluentAssertions.Specs/Collections/Data/DataTableCollectionAssertionSpecs.cs @@ -0,0 +1,545 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using FluentAssertions.Execution; + +using Xunit; +using Xunit.Sdk; + +namespace FluentAssertions.Specs.Collections.Data +{ + public static class DataTableCollectionAssertionSpecs + { + public class BeSameAs + { + [Fact] + public void When_references_are_the_same_it_should_succeed() + { + // Arrange + var dataSet = new DataSet(); + + dataSet.Tables.Add(new DataTable("Table1")); + + var tableCollection1 = dataSet.Tables; + var tableCollection2 = tableCollection1; + + // Act & Assert + tableCollection1.Should().BeSameAs(tableCollection2); + } + + [Fact] + public void When_references_are_different_it_should_fail() + { + // Arrange + var dataSet1 = new DataSet(); + var dataSet2 = new DataSet(); + + dataSet1.Tables.Add(new DataTable("Table1")); + dataSet2.Tables.Add(new DataTable("Table1")); + + var tableCollection1 = dataSet1.Tables; + var tableCollection2 = dataSet2.Tables; + + // Act + Action action = + () => tableCollection1.Should().BeSameAs(tableCollection2); + + // Assert + action.Should().Throw().WithMessage( + "Expected tableCollection1 to refer to *, but found * (different underlying object)."); + } + + [Fact] + public void When_generic_collection_is_tested_against_typed_collection_it_should_fail() + { + // Arrange + var dataSet = new DataSet(); + + var tableCollection = dataSet.Tables; + + var genericCollection = tableCollection.Cast(); + + // Act + Action action = + () => genericCollection.Should().BeSameAs(tableCollection, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Invalid expectation: Expected genericCollection to refer to an instance of DataTableCollection " + + "because we care, but found *."); + } + } + + public class NotBeSameAs + { + [Fact] + public void When_references_are_the_same_it_should_fail() + { + // Arrange + var dataSet = new DataSet(); + + dataSet.Tables.Add(new DataTable("Table1")); + + var tableCollection1 = dataSet.Tables; + var tableCollection2 = tableCollection1; + + // Act + Action action = + () => tableCollection1.Should().NotBeSameAs(tableCollection2); + + // Assert + action.Should().Throw().WithMessage( + "Did not expect tableCollection1 to refer to *."); + } + + [Fact] + public void When_references_are_different_it_should_succeed() + { + // Arrange + var dataSet1 = new DataSet(); + var dataSet2 = new DataSet(); + + dataSet1.Tables.Add(new DataTable("Table1")); + dataSet2.Tables.Add(new DataTable("Table1")); + + var tableCollection1 = dataSet1.Tables; + var tableCollection2 = dataSet2.Tables; + + // Act & Assert + tableCollection1.Should().NotBeSameAs(tableCollection2); + } + + [Fact] + public void When_generic_collection_is_tested_against_typed_collection_it_should_fail() + { + // Arrange + var dataSet = new DataSet(); + + var tableCollection = dataSet.Tables; + + var genericCollection = tableCollection.Cast(); + + // Act + Action action = + () => genericCollection.Should().NotBeSameAs(tableCollection, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Invalid expectation: Expected genericCollection to refer to a different instance of " + + "DataTableCollection because we care, but found *."); + } + } + + 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() + { + // Arrange + var dataSet = new DataSet(); + + var nullReference = default(DataTableCollection); + + // Act + Action action = + () => dataSet.Tables.Should().HaveSameCount(nullReference); + + // Assert + action.Should().Throw().WithMessage( + "Cannot verify count against a collection.*"); + } + + public class DataSetAssertions + { + [Fact] + public void When_collections_have_the_same_number_of_tables_it_should_succeed() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table11")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Ensure that the table schema isn't important for the count comparison. + secondDataSet.Tables[0].Columns.Add("Column1", typeof(int)); + + // Act & Assert + firstDataSet.Tables.Should().HaveSameCount(secondDataSet, because: "we {0}", "care"); + } + + [Fact] + public void When_collections_do_not_have_the_same_number_of_tables_it_should_fail() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Act + Action action = + () => firstDataSet.Tables.Should().HaveSameCount(secondDataSet, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected firstDataSet.Tables to have 2 table(s) because we care, but found 3."); + } + } + + public class DataTableCollectionAssertions + { + [Fact] + public void When_collections_have_the_same_number_of_tables_it_should_succeed() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table11")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Ensure that the table schema isn't important for the count comparison. + secondDataSet.Tables[0].Columns.Add("Column1", typeof(int)); + + // Act & Assert + firstDataSet.Tables.Should().HaveSameCount(secondDataSet.Tables); + } + + [Fact] + public void When_collections_do_not_have_the_same_number_of_tables_it_should_fail() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Act + Action action = + () => firstDataSet.Tables.Should().HaveSameCount(secondDataSet.Tables); + + // Assert + action.Should().Throw().WithMessage( + "Expected firstDataSet.Tables to have 2 table(s), but found 3."); + } + } + + public class GenericCollectionAssertions + { + [Fact] + public void When_collection_is_compared_with_null_it_should_fail() + { + // Arrange + var dataSet = new DataSet(); + + dataSet.Tables.Add(new DataTable("Table0")); + dataSet.Tables.Add(new DataTable("Table1")); + dataSet.Tables.Add(new DataTable("Table2")); + + List nullDataTables = null; + + // Act + Action action = + () => nullDataTables.Should().HaveSameCount(dataSet.Tables, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected nullDataTables to have the same count as * because we care, but found ."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_same_number_of_tables_it_should_succeed() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table11")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Ensure that the table schema isn't important for the count comparison. + secondDataSet.Tables[0].Columns.Add("Column1", typeof(int)); + + var genericDataTableCollection = firstDataSet.Tables.Cast(); + + // Act & Assert + genericDataTableCollection.Should().HaveSameCount(secondDataSet.Tables); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_different_number_of_tables_it_should_fail() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + var genericDataTableCollection = firstDataSet.Tables.Cast(); + + // Act + Action action = + () => genericDataTableCollection.Should().HaveSameCount(secondDataSet.Tables, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected genericDataTableCollection to have 2 table(s) because we care, but found 3."); + } + } + } + + 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() + { + // Arrange + var dataSet = new DataSet(); + + dataSet.Tables.Add(new DataTable("Table0")); + dataSet.Tables.Add(new DataTable("Table1")); + dataSet.Tables.Add(new DataTable("Table2")); + + var nullReference = default(DataTableCollection); + + // Act + Action action = + () => dataSet.Tables.Should().NotHaveSameCount(nullReference); + + // Assert + action.Should().Throw().WithMessage( + "Cannot verify count against a collection.*"); + } + + public class DataTableCollectionAssertions + { + [Fact] + public void When_two_collections_have_different_number_of_tables_it_should_succeed() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Act & Assert + firstDataSet.Tables.Should().NotHaveSameCount(secondDataSet.Tables); + } + + [Fact] + public void When_two_collections_have_the_same_number_of_tables_it_should_fail() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table11")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Act + Action action = + () => firstDataSet.Tables.Should().NotHaveSameCount(secondDataSet.Tables, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected firstDataSet.Tables to not have 3 table(s) because we care, but found 3."); + } + } + + public class DataSetAssertions + { + [Fact] + public void When_two_collections_have_different_number_of_tables_it_should_succeed() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Act & Assert + firstDataSet.Tables.Should().NotHaveSameCount(secondDataSet, because: "we {0}", "care"); + } + + [Fact] + public void When_two_collections_have_the_same_number_of_tables_it_should_fail() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table11")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + // Act + Action action = + () => firstDataSet.Tables.Should().NotHaveSameCount(secondDataSet, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected firstDataSet.Tables to not have 3 table(s) because we care, but found 3."); + } + } + + public class GenericCollectionAssertions + { + [Fact] + public void When_collection_is_compared_with_null_it_should_fail() + { + // Arrange + var dataSet = new DataSet(); + + dataSet.Tables.Add(new DataTable("Table0")); + dataSet.Tables.Add(new DataTable("Table1")); + dataSet.Tables.Add(new DataTable("Table2")); + + List nullDataTables = null; + + // Act + Action action = + () => nullDataTables.Should().NotHaveSameCount(dataSet.Tables, because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected nullDataTables to not have the same count as * because we care, but found ."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_same_number_of_tables_it_should_fail() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table11")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + var genericDataTableCollection = firstDataSet.Tables.Cast(); + + // Act + Action action = + () => genericDataTableCollection.Should().NotHaveSameCount(secondDataSet.Tables, + because: "we {0}", "care"); + + // Assert + action.Should().Throw().WithMessage( + "Expected genericDataTableCollection to not have 3 table(s) because we care, but found 3."); + } + + [Fact] + public void When_collection_is_compared_with_typed_collection_with_different_number_of_tables_it_should_succeed() + { + // Arrange + var firstDataSet = new DataSet(); + var secondDataSet = new DataSet(); + + firstDataSet.Tables.Add(new DataTable("Table0")); + firstDataSet.Tables.Add(new DataTable("Table1")); + firstDataSet.Tables.Add(new DataTable("Table2")); + + secondDataSet.Tables.Add(new DataTable("Table10")); + secondDataSet.Tables.Add(new DataTable("Table12")); + + var genericDataTableCollection = firstDataSet.Tables.Cast(); + + // Act & Assert + genericDataTableCollection.Should().NotHaveSameCount(secondDataSet.Tables); + } + } + } + } +} diff --git a/docs/_pages/data.md b/docs/_pages/data.md index 0815c27632..3d7fb7c94c 100644 --- a/docs/_pages/data.md +++ b/docs/_pages/data.md @@ -82,6 +82,26 @@ When checking the equivalency of two `DataRow` objects, by default the `RowState In addition, if both the subject and the expectation are in the `DataRowState.Modified` state, then the `DataRowVersion.Original` values are also compared, separately from the `DataRowVersion.Current` values. This can be disabled using the `.ExcludingOriginalData()` equivalency assertion option. +## Collections + +Each `DataSet` has a `DataTableCollection` called `Tables`, and each `DataTable` has a `DataColumnCollection` called `Columns` and a `DataRowCollection` called `Rows`. Some assertions can be performed on these collection types. + +The following assertions are in common to all three collection types: + +* `.Should().BeEmpty()`: Succeeds if the collection contains no items (tables, columns, rows). +* `.Should().NotBeEmpty()`: Succeeds if the collection contains at least one item (table, column, row). +* `.Should().ContainEquivalentOf(x)`: Succeeds if the collection contains an item (table, column, row) that is equivalent to the supplied item. +* `.Should().NotContainEquivalentOf(x)`: Succeeds if the item does not contain any item (table, column, row) that is equivalent to the supplied item. +* `.Should().HaveSameCount(x)`: Succeeds if the collection contains the same number of items as the supplied collection of the same type. +* `.Should().NotHaveSameCount(x)`: Succeeds if the collection does not contain the same number of items as the supplied collection of the same type. +* `.Should().HaveCount(x)`: Succeeds if the collection contains exactly the specified number of items. +* `.Should().HaveCount(predicate)`: Succeeds if the predicate returns true for the number of items in the collection. +* `.Should().NotHaveCount(x)`: Succeeds if the collection contains a different number of items than the supplied count. +* `.Should().HaveCountGreaterThan(x)`: Succeeds if the collection contains more items than the supplied count. +* `.Should().HaveCountGreaterThanOrEqualTo(x)`: Succeeds if the collection contains at least as many items as the supplied count. +* `.Should().HaveCountLessThan(x)`: Succeeds if the collection contains fewer items than the supplied count. +* `.Should().HaveCountLessThanOrEqualTo(x)`: Succeeds if the collection contains at most as many items as the supplied count. + ## Equivalency Assertion Options When checking equivalency, the operation can be fine-tuned by configuring the options provided to an optional configuration callback in the `.BeEquivalentTo` method. diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md index de4a23955d..9c28ca607b 100644 --- a/docs/_pages/releases.md +++ b/docs/_pages/releases.md @@ -27,6 +27,7 @@ sidebar: * Ensure `ExcludingMissingMembers` doesn't undo usage of `WithMapping` in `BeEquivalentTo` - [#1838](https://github.com/fluentassertions/fluentassertions/pull/1838) * Better handling of NaN in various numeric assertions - [#1822](https://github.com/fluentassertions/fluentassertions/pull/1822) & [#1867](https://github.com/fluentassertions/fluentassertions/pull/1867) * `WithMapping` in `BeEquivalentTo` now also works when the root is a collection - [#1858](https://github.com/fluentassertions/fluentassertions/pull/1858) +* Assertions on the collection types in System.Data (`DataSet.Tables`, `DataTable.Columns`, `DataTable.Rows`) have been restored - [#1812](https://github.com/fluentassertions/fluentassertions/pull/1812) ### Fixes (Extensibility)