diff --git a/Src/FluentAssertions/AssertionExtensions.cs b/Src/FluentAssertions/AssertionExtensions.cs index d16c01d5d7..5a0c9d831b 100644 --- a/Src/FluentAssertions/AssertionExtensions.cs +++ b/Src/FluentAssertions/AssertionExtensions.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Data; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; @@ -12,7 +11,6 @@ using System.Xml.Linq; using FluentAssertions.Collections; using FluentAssertions.Common; -using FluentAssertions.Data; using FluentAssertions.Numeric; using FluentAssertions.Primitives; using FluentAssertions.Reflection; @@ -388,46 +386,6 @@ 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 . - /// - [Pure] - public static DataColumnAssertions Should(this DataColumn actualValue) - { - return new DataColumnAssertions(actualValue); - } - /// /// Returns an object that can be used to assert the /// current . diff --git a/Src/FluentAssertions/AssertionOptions.cs b/Src/FluentAssertions/AssertionOptions.cs index c40eff298e..3ce1f64f0e 100644 --- a/Src/FluentAssertions/AssertionOptions.cs +++ b/Src/FluentAssertions/AssertionOptions.cs @@ -17,19 +17,14 @@ static AssertionOptions() EquivalencyPlan = new EquivalencyPlan(); } + /// + /// Creates a clone of the default options and allows the caller to modify them. + /// public static EquivalencyAssertionOptions CloneDefaults() { return new EquivalencyAssertionOptions(defaults); } - internal static TOptions CloneDefaults(Func predicate) - where TOptions : EquivalencyAssertionOptions - { - Guard.ThrowIfArgumentIsNull(predicate); - - return predicate(defaults); - } - /// /// Allows configuring the defaults used during a structural equivalency assertion. /// diff --git a/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs b/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs deleted file mode 100644 index 878eacda7f..0000000000 --- a/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs +++ /dev/null @@ -1,69 +0,0 @@ -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, ICollectionWrapper - where TCollection : ICollection -{ - public TCollection UnderlyingCollection { get; } - - /// - /// Initializes a new instance of the class. - /// - /// is . - public ReadOnlyNonGenericCollectionWrapper(TCollection collection) - { - Guard.ThrowIfArgumentIsNull(collection); - - UnderlyingCollection = collection; - } - - public int Count => UnderlyingCollection.Count; - - bool ICollection.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); - - void ICollection.Add(TItem item) => throw new NotSupportedException(); - - void ICollection.Clear() => throw new NotSupportedException(); - - bool ICollection.Remove(TItem item) => throw new NotSupportedException(); -} diff --git a/Src/FluentAssertions/Data/DataColumnAssertions.cs b/Src/FluentAssertions/Data/DataColumnAssertions.cs deleted file mode 100644 index 9adec7bea8..0000000000 --- a/Src/FluentAssertions/Data/DataColumnAssertions.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using System.Data; -using System.Diagnostics; -using FluentAssertions.Common; -using FluentAssertions.Equivalency; -using FluentAssertions.Execution; -using FluentAssertions.Primitives; - -namespace FluentAssertions.Data; - -/// -/// Provides convenient assertion methods on a that can be -/// used to assert equivalency. -/// -[DebuggerNonUserCode] -public class DataColumnAssertions : ReferenceTypeAssertions -{ - public DataColumnAssertions(DataColumn dataColumn) - : base(dataColumn) - { - } - - /// - /// Asserts that an instance of is equivalent to another. - /// - /// - /// Data columns are equivalent when the following members have the same values: - /// - /// - /// AllowDBNull - /// AutoIncrement - /// AutoIncrementSeed - /// AutoIncrementStep - /// Caption - /// ColumnName - /// DataType - /// DateTimeMode - /// DefaultValue - /// Expression - /// ExtendedProperties - /// MaxLength - /// Namespace - /// Prefix - /// ReadOnly - /// Unique - /// - /// - /// A with the expected configuration. - /// - /// 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 AndConstraint BeEquivalentTo(DataColumn expectation, string because = "", - params object[] becauseArgs) - { - return BeEquivalentTo( - expectation, - options => options, - because, - becauseArgs); - } - - /// - /// Asserts that an instance of is equivalent to another. - /// - /// - /// Data columns are equivalent when the following members have the same values: - /// - /// - /// AllowDBNull - /// AutoIncrement - /// AutoIncrementSeed - /// AutoIncrementStep - /// Caption - /// ColumnName - /// DataType - /// DateTimeMode - /// DefaultValue - /// Expression - /// ExtendedProperties - /// MaxLength - /// Namespace - /// Prefix - /// ReadOnly - /// Unique - /// - /// - /// - /// Testing of any property can be overridden using the callback. Exclude specific properties using - /// . - /// - /// - /// If or a related function is - /// used and the exclusion matches the subject , then the equivalency test will never - /// fail. - /// - /// - /// A with the expected configuration. - /// - /// A reference to the configuration object that can be used - /// to influence the way the object graphs are compared. You can also provide an alternative instance of the - /// class. The global defaults are determined by the - /// class. - /// - /// - /// 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 . - /// - /// is . - public AndConstraint BeEquivalentTo(DataColumn expectation, - Func, IDataEquivalencyAssertionOptions> config, - string because = "", params object[] becauseArgs) - { - Guard.ThrowIfArgumentIsNull(config); - - IDataEquivalencyAssertionOptions options = - config(AssertionOptions.CloneDefaults>(e => - new DataEquivalencyAssertionOptions(e))); - - var context = - new EquivalencyValidationContext(Node.From(() => AssertionScope.Current.CallerIdentity), options) - { - Reason = new Reason(because, becauseArgs), - TraceWriter = options.TraceWriter - }; - - var comparands = new Comparands - { - Subject = Subject, - Expectation = expectation, - CompileTimeType = typeof(DataColumn) - }; - - new EquivalencyValidator().AssertEquality(comparands, context); - - return new AndConstraint(this); - } - - protected override string Identifier => "DataColumn"; -} diff --git a/Src/FluentAssertions/Data/DataEquivalencyAssertionOptions.cs b/Src/FluentAssertions/Data/DataEquivalencyAssertionOptions.cs deleted file mode 100644 index b49c7d75ec..0000000000 --- a/Src/FluentAssertions/Data/DataEquivalencyAssertionOptions.cs +++ /dev/null @@ -1,267 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq.Expressions; -using System.Reflection; -using FluentAssertions.Equivalency; - -namespace FluentAssertions.Data; - -internal class DataEquivalencyAssertionOptions : EquivalencyAssertionOptions, IDataEquivalencyAssertionOptions -{ - private readonly HashSet excludeTableNames = new(); - private readonly HashSet excludeColumnNames = new(); - private readonly Dictionary> excludeColumnNamesByTableName = new(); - - public bool AllowMismatchedTypes { get; private set; } - - public bool IgnoreUnmatchedColumns { get; private set; } - - public bool ExcludeOriginalData { get; private set; } - - public RowMatchMode RowMatchMode { get; private set; } - - public ISet ExcludeTableNames => excludeTableNames; - - public ISet ExcludeColumnNames => excludeColumnNames; - - public DataEquivalencyAssertionOptions(EquivalencyAssertionOptions defaults) - : base(defaults) - { - } - - public IDataEquivalencyAssertionOptions AllowingMismatchedTypes() - { - AllowMismatchedTypes = true; - return this; - } - - public IDataEquivalencyAssertionOptions IgnoringUnmatchedColumns() - { - IgnoreUnmatchedColumns = true; - return this; - } - - public IDataEquivalencyAssertionOptions UsingRowMatchMode(RowMatchMode rowMatchMode) - { - RowMatchMode = rowMatchMode; - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingOriginalData() - { - ExcludeOriginalData = true; - return this; - } - - public new IDataEquivalencyAssertionOptions Excluding(Expression> expression) - { - base.Excluding(expression); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression) - { - ExcludeMemberOfRelatedTypeByGeneratedPredicate(expression); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression) - { - ExcludeMemberOfRelatedTypeByGeneratedPredicate(expression); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression) - { - ExcludeMemberOfRelatedTypeByGeneratedPredicate(expression); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression) - { - ExcludeMemberOfRelatedTypeByGeneratedPredicate(expression); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression) - { - ExcludeMemberOfSubtypeOfRelatedTypeByGeneratedPredicate(expression); - ExcludeMemberOfSubtypeOfRelatedTypeByGeneratedPredicate(expression); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression) - { - ExcludeMemberOfRelatedTypeByGeneratedPredicate(expression); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression) - { - ExcludeMemberOfRelatedTypeByGeneratedPredicate(expression); - return this; - } - - private void ExcludeMemberOfRelatedTypeByGeneratedPredicate( - Expression> expression) - { - Expression> predicate = BuildMemberSelectionPredicate( - typeof(TDeclaringType), - GetMemberAccessTargetMember(expression.Body)); - - Excluding(predicate); - } - - private void ExcludeMemberOfSubtypeOfRelatedTypeByGeneratedPredicate( - Expression> expression) - where TInheritingType : TDeclaringType - { - Expression> predicate = BuildMemberSelectionPredicate( - typeof(TInheritingType), - GetMemberAccessTargetMember(expression.Body)); - - Excluding(predicate); - } - - private static MemberInfo GetMemberAccessTargetMember(Expression expression) - { - if (expression is UnaryExpression unaryExpression - && unaryExpression.NodeType == ExpressionType.Convert) - { - // If the expression is a value type, then accessing it will involve an - // implicit boxing conversion to type object that we need to ignore. - expression = unaryExpression.Operand; - } - - if (expression is MemberExpression memberExpression) - { - return memberExpression.Member; - } - - throw new ArgumentException("Expression must be a simple member access", nameof(expression)); - } - - private static Expression> BuildMemberSelectionPredicate(Type relatedSubjectType, - MemberInfo referencedMember) - { - ParameterExpression predicateMemberInfoArgument = Expression.Parameter(typeof(IMemberInfo)); - - BinaryExpression typeComparison = Expression.Equal( - Expression.MakeMemberAccess( - predicateMemberInfoArgument, - typeof(IMemberInfo).GetProperty(nameof(IMemberInfo.DeclaringType))), - Expression.Constant(relatedSubjectType)); - - BinaryExpression memberNameComparison = Expression.Equal( - Expression.MakeMemberAccess( - predicateMemberInfoArgument, - typeof(IMemberInfo).GetProperty(nameof(IMemberInfo.Name))), - Expression.Constant(referencedMember.Name)); - - BinaryExpression predicateBody = Expression.AndAlso( - typeComparison, - memberNameComparison); - - return Expression.Lambda>( - predicateBody, - predicateMemberInfoArgument); - } - - public new IDataEquivalencyAssertionOptions Excluding(Expression> predicate) - { - base.Excluding(predicate); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingTable(string tableName) - { - return ExcludingTables(tableName); - } - - public IDataEquivalencyAssertionOptions ExcludingTables(params string[] tableNames) - { - return ExcludingTables((IEnumerable)tableNames); - } - - public IDataEquivalencyAssertionOptions ExcludingTables(IEnumerable tableNames) - { - excludeTableNames.UnionWith(tableNames); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingColumnInAllTables(string columnName) - { - return ExcludingColumnsInAllTables(columnName); - } - - public IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(params string[] columnNames) - { - return ExcludingColumnsInAllTables((IEnumerable)columnNames); - } - - public IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(IEnumerable columnNames) - { - excludeColumnNames.UnionWith(columnNames); - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingColumn(DataColumn column) - { - return ExcludingColumn(column.Table.TableName, column.ColumnName); - } - - public IDataEquivalencyAssertionOptions ExcludingColumns(params DataColumn[] columns) - { - return ExcludingColumns((IEnumerable)columns); - } - - public IDataEquivalencyAssertionOptions ExcludingColumns(IEnumerable columns) - { - foreach (DataColumn column in columns) - { - ExcludingColumn(column); - } - - return this; - } - - public IDataEquivalencyAssertionOptions ExcludingColumn(string tableName, string columnName) - { - return ExcludingColumns(tableName, columnName); - } - - public IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, params string[] columnNames) - { - return ExcludingColumns(tableName, (IEnumerable)columnNames); - } - - public IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, IEnumerable columnNames) - { - if (!excludeColumnNamesByTableName.TryGetValue(tableName, out HashSet excludeColumnNames)) - { - excludeColumnNames = new HashSet(); - excludeColumnNamesByTableName[tableName] = excludeColumnNames; - } - - excludeColumnNames.UnionWith(columnNames); - - return this; - } - - public bool ShouldExcludeColumn(DataColumn column) - { - if (excludeColumnNames.Contains(column.ColumnName)) - { - return true; - } - - if (excludeColumnNamesByTableName.TryGetValue(column.Table.TableName, out HashSet excludeColumnsForTable) - && excludeColumnsForTable.Contains(column.ColumnName)) - { - return true; - } - - return false; - } -} diff --git a/Src/FluentAssertions/Data/DataRowAssertions.cs b/Src/FluentAssertions/Data/DataRowAssertions.cs deleted file mode 100644 index 6f65842c99..0000000000 --- a/Src/FluentAssertions/Data/DataRowAssertions.cs +++ /dev/null @@ -1,217 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics; -using System.Linq; -using FluentAssertions.Common; -using FluentAssertions.Equivalency; -using FluentAssertions.Execution; -using FluentAssertions.Primitives; - -namespace FluentAssertions.Data; - -/// -/// Provides convenient assertion methods on a that can be -/// used to assert equivalency and the presence of columns. -/// -[DebuggerNonUserCode] -public class DataRowAssertions : ReferenceTypeAssertions> - where TDataRow : DataRow -{ - public DataRowAssertions(TDataRow dataRow) - : base(dataRow) - { - } - - /// - /// Asserts that an instance of has a column with the expected column name. - /// - /// The value that is expected in . - /// - /// 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 AndWhichConstraint, DataColumn> HaveColumn(string expectedColumnName, string because = "", - params object[] becauseArgs) - { - var subjectColumn = default(DataColumn); - - if (Subject is null) - { - Execute.Assertion - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataRow} to contain a column named {0}{reason}, but found .", - expectedColumnName); - } - else if (!Subject.Table.Columns.Contains(expectedColumnName)) - { - Execute.Assertion - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataRow} to contain a column named {0}{reason}, but it does not.", - expectedColumnName); - } - else - { - subjectColumn = Subject.Table.Columns[expectedColumnName]; - } - - return new AndWhichConstraint, DataColumn>(this, subjectColumn); - } - - /// - /// Asserts that an instance of has columns with all of the supplied expected column names. - /// - /// An array of values expected in . - public AndConstraint> HaveColumns(params string[] expectedColumnNames) - { - return HaveColumns((IEnumerable)expectedColumnNames); - } - - /// - /// Asserts that an instance of has columns with all of the supplied expected column names. - /// - /// An of string values expected in . - /// - /// 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 AndConstraint> HaveColumns(IEnumerable expectedColumnNames, string because = "", - params object[] becauseArgs) - { - bool success = Execute.Assertion - .ForCondition(Subject is not null) - .BecauseOf(because, becauseArgs) - .FailWith( - "Expected {context:DataRow} to be in a table containing {0} column(s) with specific names{reason}, but found .", - () => expectedColumnNames.Count()); - - if (success) - { - foreach (var expectedColumnName in expectedColumnNames) - { - Execute.Assertion - .ForCondition(Subject.Table.Columns.Contains(expectedColumnName)) - .BecauseOf(because, becauseArgs) - .FailWith("Expected table containing {context:DataRow} to contain a column named {0}{reason}, but it does not.", - expectedColumnName); - } - } - - return new AndConstraint>(this); - } - - /// - /// Asserts that an instance of is equivalent to another. - /// - /// - /// Data rows are equivalent when they contain identical field data for the row they represent, and - /// the following members have the same values: - /// - /// - /// HasErrors - /// RowState - /// - /// - /// The objects must be of the same type; if two objects - /// are equivalent in all ways, except that one is part of a typed and is of a subclass - /// of , then by default, they will not be considered equivalent. This can be overridden - /// by using the overload that takes . - /// - /// A with the expected configuration. - /// - /// 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 AndConstraint> BeEquivalentTo(DataRow expectation, string because = "", - params object[] becauseArgs) - { - return BeEquivalentTo( - expectation, - options => options, - because, - becauseArgs); - } - - /// - /// Asserts that an instance of is equivalent to another. - /// - /// - /// Data rows are equivalent when they contain identical field data for the row they represent, and - /// the following members have the same values: - /// - /// - /// HasErrors - /// RowState - /// - /// - /// - /// The objects must be of the same type; if two objects - /// are equivalent in all ways, except that one is part of a typed and is of a subclass - /// of , then by default, they will not be considered equivalent. - /// - /// - /// This, as well as testing of any property can be overridden using the callback. - /// By calling , two - /// objects of differing types can be considered equivalent. Exclude specific properties using - /// . - /// Exclude columns of the data table (which also excludes the related field data in - /// objects) using or a related function. - /// - /// - /// - /// You can use - /// and related functions to exclude properties on other related System.Data types. - /// A with the expected configuration. - /// - /// A reference to the configuration object that can be used - /// to influence the way the object graphs are compared. You can also provide an alternative instance of the - /// class. The global defaults are determined by the - /// class. - /// - /// - /// 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 . - /// - /// is . - public AndConstraint> BeEquivalentTo(DataRow expectation, - Func, IDataEquivalencyAssertionOptions> config, string because = "", - params object[] becauseArgs) - { - Guard.ThrowIfArgumentIsNull(config); - - IDataEquivalencyAssertionOptions options = - config(AssertionOptions.CloneDefaults>(e => - new DataEquivalencyAssertionOptions(e))); - - var context = new EquivalencyValidationContext(Node.From(() => AssertionScope.Current.CallerIdentity), options) - { - Reason = new Reason(because, becauseArgs), - TraceWriter = options.TraceWriter - }; - - var comparands = new Comparands - { - Subject = Subject, - Expectation = expectation, - CompileTimeType = typeof(TDataRow), - }; - - new EquivalencyValidator().AssertEquality(comparands, context); - - return new AndConstraint>(this); - } - - protected override string Identifier => "DataRow"; -} diff --git a/Src/FluentAssertions/Data/DataSetAssertions.cs b/Src/FluentAssertions/Data/DataSetAssertions.cs deleted file mode 100644 index 2cf8559437..0000000000 --- a/Src/FluentAssertions/Data/DataSetAssertions.cs +++ /dev/null @@ -1,272 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics; -using System.Linq; -using FluentAssertions.Common; -using FluentAssertions.Equivalency; -using FluentAssertions.Execution; -using FluentAssertions.Primitives; - -namespace FluentAssertions.Data; - -/// -/// Provides convenient assertion methods on a that can be -/// used to assert equivalency and the presence of tables. -/// -[DebuggerNonUserCode] -public class DataSetAssertions : ReferenceTypeAssertions> - where TDataSet : DataSet -{ - public DataSetAssertions(TDataSet dataSet) - : base(dataSet) - { - } - - /// - /// Asserts that an instance of contains exactly the expected number of tables in its collection. - /// - /// The expected number of rows. - /// - /// 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 AndConstraint> HaveTableCount(int expected, string because = "", - params object[] becauseArgs) - { - bool success = Execute.Assertion - .ForCondition(Subject is not null) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataSet} to contain exactly {0} table(s){reason}, but found .", expected); - - if (success) - { - int actualCount = Subject.Tables.Count; - - Execute.Assertion - .ForCondition(actualCount == expected) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataSet} to contain exactly {0} table(s){reason}, but found {1}.", expected, - actualCount); - } - - return new AndConstraint>(this); - } - - /// - /// Asserts that an instance of contains a table with the expected name. - /// - /// The value that is expected in . - /// - /// 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 AndWhichConstraint, DataTable> HaveTable(string expectedTableName, string because = "", - params object[] becauseArgs) - { - var subjectTable = default(DataTable); - - if (Subject is null) - { - Execute.Assertion - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataSet} to contain a table named {0}{reason}, but found .", - expectedTableName); - } - else if (!Subject.Tables.Contains(expectedTableName)) - { - Execute.Assertion - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataSet} to contain a table named {0}{reason}, but it does not.", expectedTableName); - } - else - { - subjectTable = Subject.Tables[expectedTableName]; - } - - return new AndWhichConstraint, DataTable>(this, subjectTable); - } - - /// - /// Asserts that an instance of has tables with all of the supplied expected column names. - /// - /// An array of values expected in . - public AndConstraint> HaveTables(params string[] expectedTableNames) - { - return HaveTables((IEnumerable)expectedTableNames); - } - - /// - /// Asserts that an instance of has tables with all of the supplied expected table names. - /// - /// An of string values expected in . - /// - /// 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 AndConstraint> HaveTables(IEnumerable expectedTableNames, string because = "", - params object[] becauseArgs) - { - bool success = Execute.Assertion - .ForCondition(Subject is not null) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataSet} to contain {0} table(s) with specific names{reason}, but found .", - () => expectedTableNames.Count()); - - if (success) - { - foreach (var expectedTableName in expectedTableNames) - { - Execute.Assertion - .ForCondition(Subject.Tables.Contains(expectedTableName)) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataSet} to contain a table named {0}{reason}, but it does not.", expectedTableName); - } - } - - return new AndConstraint>(this); - } - - /// - /// Asserts that an instance of is equivalent to another. - /// - /// - /// Data sets are equivalent when their and - /// collections are equivalent and the following members have the same values: - /// - /// - /// DataSetName - /// CaseSensitive - /// EnforceConstraints - /// HasErrors - /// Locale - /// Namespace - /// Prefix - /// RemotingFormat - /// SchemaSerializationMode - /// - /// - /// The objects must be of the same type; if two objects - /// are equivalent in all ways, except that one is a custom subclass of (e.g. to provide - /// typed accessors for values contained by the ), then by default, - /// they will not be considered equivalent. This can be overridden by using the overload that takes - /// . - /// - /// A with the expected configuration. - /// - /// 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 AndConstraint> BeEquivalentTo(DataSet expectation, string because = "", - params object[] becauseArgs) - { - return BeEquivalentTo( - expectation, - options => options, - because, - becauseArgs); - } - - /// - /// Asserts that an instance of is equivalent to another. - /// - /// - /// Data sets are equivalent when their and - /// collections are equivalent and the following members have the same values: - /// - /// - /// DataSetName - /// CaseSensitive - /// EnforceConstraints - /// HasErrors - /// Locale - /// Namespace - /// Prefix - /// RemotingFormat - /// SchemaSerializationMode - /// - /// - /// - /// The objects must be of the same type; if two objects - /// are equivalent in all ways, except that one is a custom subclass of (e.g. to provide - /// typed accessors for values contained by the ), then by default, - /// they will not be considered equivalent. - /// - /// - /// This, as well as testing of any property can be overridden using the callback. - /// By calling , two - /// objects of differing types can be considered equivalent. This setting applies to all types recursively tested - /// as part of the . - /// - /// - /// Exclude specific properties using . - /// Exclude specific tables within the data set using - /// or a related function. You can also indicate that columns should be excluded within the - /// objects recursively tested as part of the using - /// or a related function. The method - /// can be used to exclude columns across all objects in the that share - /// the same name. - /// - /// - /// You can use - /// and related functions to exclude properties on other related System.Data types. - /// - /// - /// A with the expected configuration. - /// - /// A reference to the configuration object that can be used - /// to influence the way the object graphs are compared. You can also provide an alternative instance of the - /// class. The global defaults are determined by the - /// class. - /// - /// - /// 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 . - /// - /// is . - public AndConstraint> BeEquivalentTo(DataSet expectation, - Func, IDataEquivalencyAssertionOptions> config, string because = "", - params object[] becauseArgs) - { - Guard.ThrowIfArgumentIsNull(config); - - IDataEquivalencyAssertionOptions options = - config(AssertionOptions.CloneDefaults>(e => - new DataEquivalencyAssertionOptions(e))); - - var comparands = new Comparands - { - Subject = Subject, - Expectation = expectation, - CompileTimeType = typeof(TDataSet) - }; - - var context = new EquivalencyValidationContext(Node.From(() => AssertionScope.Current.CallerIdentity), options) - { - Reason = new Reason(because, becauseArgs), - TraceWriter = options.TraceWriter, - }; - - var equivalencyValidator = new EquivalencyValidator(); - equivalencyValidator.AssertEquality(comparands, context); - - return new AndConstraint>(this); - } - - protected override string Identifier => "DataSet"; -} diff --git a/Src/FluentAssertions/Data/DataTableAssertions.cs b/Src/FluentAssertions/Data/DataTableAssertions.cs deleted file mode 100644 index 2fe7427d2e..0000000000 --- a/Src/FluentAssertions/Data/DataTableAssertions.cs +++ /dev/null @@ -1,284 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics; -using System.Linq; -using FluentAssertions.Common; -using FluentAssertions.Equivalency; -using FluentAssertions.Execution; -using FluentAssertions.Primitives; - -namespace FluentAssertions.Data; - -/// -/// Provides convenient assertion methods on a that can be -/// used to assert equivalency and the presence of rows and columns. -/// -[DebuggerNonUserCode] -public class DataTableAssertions : ReferenceTypeAssertions> - where TDataTable : DataTable -{ - public DataTableAssertions(TDataTable dataTable) - : base(dataTable) - { - } - - /// - /// Asserts that an instance of contains exactly the expected number of rows in its collection. - /// - /// The expected number of rows. - /// - /// 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 AndConstraint> HaveRowCount(int expected, string because = "", - params object[] becauseArgs) - { - bool success = Execute.Assertion - .ForCondition(Subject is not null) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataTable} to contain exactly {0} row(s){reason}, but found .", expected); - - if (success) - { - int actualCount = Subject.Rows.Count; - - Execute.Assertion - .ForCondition(actualCount == expected) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataTable} to contain exactly {0} row(s){reason}, but found {1}.", expected, - actualCount); - } - - return new AndConstraint>(this); - } - - /// - /// Asserts that an instance of has a column with the expected column name. - /// - /// The value that is expected in . - /// - /// 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 AndWhichConstraint, DataColumn> HaveColumn(string expectedColumnName, - string because = "", params object[] becauseArgs) - { - var subjectColumn = default(DataColumn); - - if (Subject is null) - { - Execute.Assertion - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataTable} to contain a column named {0}{reason}, but found .", - expectedColumnName); - } - else if (!Subject.Columns.Contains(expectedColumnName)) - { - Execute.Assertion - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataTable} to contain a column named {0}{reason}, but it does not.", - expectedColumnName); - } - else - { - subjectColumn = Subject.Columns[expectedColumnName]; - } - - return new AndWhichConstraint, DataColumn>(this, subjectColumn); - } - - /// - /// Asserts that an instance of has columns with all of the supplied expected column names. - /// - /// An array of values expected in . - public AndConstraint> HaveColumns(params string[] expectedColumnNames) - { - return HaveColumns((IEnumerable)expectedColumnNames); - } - - /// - /// Asserts that an instance of has columns with all of the supplied expected column names. - /// - /// An of string values expected in . - /// - /// 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 AndConstraint> HaveColumns(IEnumerable expectedColumnNames, - string because = "", params object[] becauseArgs) - { - bool success = Execute.Assertion - .ForCondition(Subject is not null) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataTable} to contain {0} column(s) with specific names{reason}, but found .", - () => expectedColumnNames.Count()); - - if (success) - { - foreach (var expectedColumnName in expectedColumnNames) - { - Execute.Assertion - .ForCondition(Subject.Columns.Contains(expectedColumnName)) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:DataTable} to contain a column named {0}{reason}, but it does not.", - expectedColumnName); - } - } - - return new AndConstraint>(this); - } - - /// - /// Asserts that an instance of is equivalent to another. - /// - /// - /// Data tables are equivalent when the following members have the same values: - /// - /// - /// TableName - /// CaseSensitive - /// DisplayExpression - /// HasErrors - /// Locale - /// Namespace - /// Prefix - /// RemotingFormat - /// - /// - /// In addition, the following collections must contain equivalent data: - /// - /// - /// ChildRelations - /// Columns - /// Constraints - /// ExtendedProperties - /// ParentRelations - /// PrimaryKey - /// Rows - /// - /// - /// The objects must be of the same type; if two objects - /// are equivalent in all ways, except that one is a typed that is a subclass - /// of , then by default, they will not be considered equivalent. This can be overridden by - /// using the overload that takes . - /// - /// A with the expected configuration. - /// - /// 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 AndConstraint> BeEquivalentTo(DataTable expectation, string because = "", - params object[] becauseArgs) - { - return BeEquivalentTo( - expectation, - options => options, - because, - becauseArgs); - } - - /// - /// Asserts that an instance of is equivalent to another. - /// - /// - /// Data tables are equivalent when the following members have the same values: - /// - /// - /// TableName - /// CaseSensitive - /// DisplayExpression - /// HasErrors - /// Locale - /// Namespace - /// Prefix - /// RemotingFormat - /// - /// - /// In addition, the following collections must contain equivalent data: - /// - /// - /// ChildRelations - /// Columns - /// Constraints - /// ExtendedProperties - /// ParentRelations - /// PrimaryKey - /// Rows - /// - /// - /// The objects must be of the same type; if two objects - /// are equivalent in all ways, except that one is a typed that is a subclass - /// of , then by default, they will not be considered equivalent. - /// - /// - /// This, as well as testing of any property can be overridden using the callback. - /// By calling , two - /// objects of differing types can be considered equivalent. Exclude specific properties using - /// . - /// Exclude columns of the data table using - /// or a related function -- this excludes both the objects in - /// and associated field data in objects within the . - /// - /// - /// You can use - /// and related functions to exclude properties on other related System.Data types. - /// - /// - /// A with the expected configuration. - /// - /// A reference to the configuration object that can be used - /// to influence the way the object graphs are compared. You can also provide an alternative instance of the - /// class. The global defaults are determined by the - /// class. - /// - /// - /// 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 . - /// - /// is . - public AndConstraint> BeEquivalentTo(DataTable expectation, - Func, IDataEquivalencyAssertionOptions> config, - string because = "", params object[] becauseArgs) - { - Guard.ThrowIfArgumentIsNull(config); - - IDataEquivalencyAssertionOptions options = - config(AssertionOptions.CloneDefaults>(e => - new DataEquivalencyAssertionOptions(e))); - - var context = new EquivalencyValidationContext(Node.From(() => AssertionScope.Current.CallerIdentity), options) - { - Reason = new Reason(because, becauseArgs), - TraceWriter = options.TraceWriter - }; - - var comparands = new Comparands - { - Subject = Subject, - Expectation = expectation, - CompileTimeType = typeof(TDataTable), - }; - - new EquivalencyValidator().AssertEquality(comparands, context); - - return new AndConstraint>(this); - } - - protected override string Identifier => "DataTable"; -} diff --git a/Src/FluentAssertions/Data/IDataEquivalencyAssertionOptions.cs b/Src/FluentAssertions/Data/IDataEquivalencyAssertionOptions.cs deleted file mode 100644 index 41ebb4625d..0000000000 --- a/Src/FluentAssertions/Data/IDataEquivalencyAssertionOptions.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq.Expressions; -using FluentAssertions.Equivalency; - -namespace FluentAssertions.Data; - -/// -/// Provides access to configuration for equivalency assertions on System.Data types (, -/// , , , , -/// ). -/// -/// The System.Data type being tested for equivalency. -public interface IDataEquivalencyAssertionOptions : IEquivalencyAssertionOptions -{ - /// - /// Specifies that the subject and the expectation should not be considered non-equivalent if their exact data types do not match. - /// - IDataEquivalencyAssertionOptions AllowingMismatchedTypes(); - - /// - /// Specifies that when comparing , columns that are unmatched between the subject and the expectation should be ignored. - /// - IDataEquivalencyAssertionOptions IgnoringUnmatchedColumns(); - - /// - /// Specifies the that should be used when comparing . By default, rows are matched by their index in the collection. But, if the has a set, it is possible to use to indicate that rows should be matched by their primary key values, irrespective of their index within the collection. - /// - /// The to use when comparing between the subject and the expectation. - IDataEquivalencyAssertionOptions UsingRowMatchMode(RowMatchMode rowMatchMode); - - /// - /// Specifies that when comparing objects that are in the state, only the current field values should be compared. Original field values are excluded from comparison. This only affects comparisons where both the subject and the expectation are in the modified state. - /// - IDataEquivalencyAssertionOptions ExcludingOriginalData(); - - /// - /// Excludes members of the objects under test from comparison by means of a predicate that selects members based on objects describing them. - /// - /// A functor that returns true if the parameter refers to a member that should be excluded. - IDataEquivalencyAssertionOptions Excluding(Expression> predicate); - - /// - /// Excludes a member of the objects under test from comparison by means of an that refers to the member in question. - /// - /// An that accesses the member to be excluded. - IDataEquivalencyAssertionOptions Excluding(Expression> expression); - - /// - /// Excludes an entire table from comparison. When comparing objects, if a table is present by the supplied name, it is not considered for the purpose of determining equivalency. This configuration option has no effect when comparing other types of object, including . - /// - /// The value for for which tables within a should be ignored. - IDataEquivalencyAssertionOptions ExcludingTable(string tableName); - - /// - /// Excludes tables from comparison using names in an set. When comparing objects, if a table is present by one of the supplied names, it is not considered for the purpose of determining equivalency. This configuration option has no effect when comparing other types of object, including . - /// - /// An of values for for which tables within a should be ignored. - IDataEquivalencyAssertionOptions ExcludingTables(IEnumerable tableNames); - - /// - /// Excludes tables from comparison using an array of table names. When comparing objects, if a table is present by one of the supplied names, it is not considered for the purpose of determining equivalency. This configuration option has no effect when comparing other types of object, including . - /// - /// An array of values for for which tables within a should be ignored. - IDataEquivalencyAssertionOptions ExcludingTables(params string[] tableNames); - - /// - /// Excludes a column from comparison by . The column to be excluded is matched by the name of its associated and its own . - /// - /// A object that specifies which column should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumn(DataColumn column); - - /// - /// Excludes a column from comparison by the name of its associated and its own . - /// - /// The value for for which columns should be ignored. - /// The value for for which columns should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumn(string tableName, string columnName); - - /// - /// Exclude an enumerable set of columns from comparison by . For each item in the enumeration, the column to be excluded is matched by the name of its associated and its own . - /// - /// An object that specifies which column(s) should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumns(IEnumerable columns); - - /// - /// Excludes an array of columns from comparison by . For each element in the array, the column to be excluded is matched by the name of its associated and its own . - /// - /// An array of objects that specify which columns should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumns(params DataColumn[] columns); - - /// - /// Excludes an enumerable set of columns from comparison by name, within tables with a specified name./>. - /// - /// The value for for which columns should be ignored. - /// An of values that specify the values for which columns should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, IEnumerable columnNames); - - /// - /// Excludes an array of columns from comparison by name, within tables with a specified name./>. - /// - /// The value for for which columns should be ignored. - /// An array of values that specify the values for which columns should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, params string[] columnNames); - - /// - /// Excludes columns from comparison by comparing only the . If columns exist by the same name in multiple objects within a , they are all excluded from comparison. - /// - /// The value for for which columns should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumnInAllTables(string columnName); - - /// - /// Excludes columns from comparison by comparing only the . If columns exist by the same name in multiple objects within a , they are all excluded from comparison. - /// - /// An of values that specify the values for which columns should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(IEnumerable columnNames); - - /// - /// Excludes columns from comparison by comparing only the . If columns exist by the same name in multiple objects within a , they are all excluded from comparison. - /// - /// An array of values that specify the values for which columns should be ignored. - /// - /// When comparing objects (e.g. within ), excluded columns are ignored completely. When comparing objects, the data associated with excluded columns is ignored. - /// - IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(params string[] columnNames); - - /// - /// Excludes properties of from comparison by means of an that refers to the member in question. - /// - /// An that accesses the member to be excluded. - IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression); - - /// - /// Excludes properties of from comparison by means of an that refers to the member in question. - /// - /// An that accesses the member to be excluded. - IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression); - - /// - /// Excludes properties of from comparison by means of an that refers to the member in question. - /// - /// An that accesses the member to be excluded. - IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression); - - /// - /// Excludes properties of from comparison by means of an that refers to the member in question. - /// - /// An that accesses the member to be excluded. - IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression); - - /// - /// Excludes properties of from comparison by means of an that refers to the member in question. - /// - /// An that accesses the member to be excluded. - IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression); - - /// - /// Excludes properties of from comparison by means of an that refers to the member in question. - /// - /// An that accesses the member to be excluded. - IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression); - - /// - /// Excludes properties of from comparison by means of an that refers to the member in question. - /// - /// An that accesses the member to be excluded. - IDataEquivalencyAssertionOptions ExcludingRelated(Expression> expression); -} diff --git a/Src/FluentAssertions/Data/RowMatchMode.cs b/Src/FluentAssertions/Data/RowMatchMode.cs deleted file mode 100644 index c36d737b32..0000000000 --- a/Src/FluentAssertions/Data/RowMatchMode.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Data; - -namespace FluentAssertions.Data; - -/// -/// Indicates how objects from different objects should be matched -/// up for equivalency comparisons. -/// -public enum RowMatchMode -{ - /// - /// Indicates that objects should be matched up by their index within the - /// collection. This is the default. - /// - Index, - - /// - /// Indicates that objects should be matched up by the values they have for - /// the table's . For this to work, the rows must be from - /// objects with exactly equivalent - /// configuration. - /// - PrimaryKey, -} diff --git a/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs deleted file mode 100644 index d830033eb8..0000000000 --- a/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using System.Data; -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 object that is being extended. - /// 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 . - /// - /// is . - 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 ICollectionWrapper 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 object that is being extended. - /// 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 . - /// - /// is . - 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 ICollectionWrapper 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 object that is being extended. - /// 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 . - /// - /// is . - 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 object that is being extended. - /// 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 . - /// - /// is . - 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/DataRowAssertionExtensions.cs b/Src/FluentAssertions/DataRowAssertionExtensions.cs deleted file mode 100644 index b48db92509..0000000000 --- a/Src/FluentAssertions/DataRowAssertionExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Data; -using System.Diagnostics; -using FluentAssertions.Data; -using JetBrains.Annotations; - -namespace FluentAssertions; - -/// -/// Contains an extension method for custom assertions in unit tests related to DataRow objects. -/// -[DebuggerNonUserCode] -public static class DataRowAssertionExtensions -{ - /// - /// Returns a object that can be used to assert the - /// current . - /// - [Pure] - public static DataRowAssertions Should(this TDataRow actualValue) - where TDataRow : DataRow - { - return new DataRowAssertions(actualValue); - } -} diff --git a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs deleted file mode 100644 index 3e5f04df8e..0000000000 --- a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs +++ /dev/null @@ -1,161 +0,0 @@ -using System; -using System.Data; -using System.Linq; -using FluentAssertions.Collections; -using FluentAssertions.Common; -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 ICollectionWrapper 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 ICollectionWrapper 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 . - /// - /// is . - 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 . - /// - /// is . - 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/DataSetAssertionExtensions.cs b/Src/FluentAssertions/DataSetAssertionExtensions.cs deleted file mode 100644 index e993ddf88b..0000000000 --- a/Src/FluentAssertions/DataSetAssertionExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Data; -using System.Diagnostics; -using FluentAssertions.Data; -using JetBrains.Annotations; - -namespace FluentAssertions; - -/// -/// Contains an extension method for custom assertions in unit tests related to DataSet objects. -/// -[DebuggerNonUserCode] -public static class DataSetAssertionExtensions -{ - /// - /// Returns a object that can be used to assert the - /// current . - /// - [Pure] - public static DataSetAssertions Should(this TDataSet actualValue) - where TDataSet : DataSet - { - return new DataSetAssertions(actualValue); - } -} diff --git a/Src/FluentAssertions/DataTableAssertionExtensions.cs b/Src/FluentAssertions/DataTableAssertionExtensions.cs deleted file mode 100644 index ee7ea0e191..0000000000 --- a/Src/FluentAssertions/DataTableAssertionExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Data; -using System.Diagnostics; -using FluentAssertions.Data; -using JetBrains.Annotations; - -namespace FluentAssertions; - -/// -/// Contains an extension method for custom assertions in unit tests related to DataTable objects. -/// -[DebuggerNonUserCode] -public static class DataTableAssertionExtensions -{ - /// - /// Returns a object that can be used to assert the - /// current . - /// - [Pure] - public static DataTableAssertions Should(this TDataTable actualValue) - where TDataTable : DataTable - { - return new DataTableAssertions(actualValue); - } -} diff --git a/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs deleted file mode 100644 index f9c0f7c1b2..0000000000 --- a/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs +++ /dev/null @@ -1,199 +0,0 @@ -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 ICollectionWrapper 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 ICollectionWrapper 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 . - /// - /// is . - 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 . - /// - /// is . - 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/Src/FluentAssertions/Equivalency/Steps/ConstraintCollectionEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/ConstraintCollectionEquivalencyStep.cs deleted file mode 100644 index 991692215b..0000000000 --- a/Src/FluentAssertions/Equivalency/Steps/ConstraintCollectionEquivalencyStep.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Collections.Generic; -using System.Data; -using System.Linq; -using FluentAssertions.Execution; - -namespace FluentAssertions.Equivalency.Steps; - -public class ConstraintCollectionEquivalencyStep : EquivalencyStep -{ - protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) - { - if (comparands.Subject is not ConstraintCollection) - { - AssertionScope.Current - .FailWith("Expected a value of type ConstraintCollection at {context:Constraints}, but found {0}", - comparands.Subject.GetType()); - } - else - { - var subject = (ConstraintCollection)comparands.Subject; - var expectation = (ConstraintCollection)comparands.Expectation; - - var subjectConstraints = subject.Cast().ToDictionary(constraint => constraint.ConstraintName); - var expectationConstraints = expectation.Cast().ToDictionary(constraint => constraint.ConstraintName); - - IEnumerable constraintNames = subjectConstraints.Keys.Union(expectationConstraints.Keys); - - foreach (var constraintName in constraintNames) - { - AssertionScope.Current - .ForCondition(subjectConstraints.TryGetValue(constraintName, out Constraint subjectConstraint)) - .FailWith("Expected constraint named {0} in {context:Constraints collection}{reason}, but did not find one", - constraintName); - - AssertionScope.Current - .ForCondition(expectationConstraints.TryGetValue(constraintName, out Constraint expectationConstraint)) - .FailWith("Found unexpected constraint named {0} in {context:Constraints collection}", constraintName); - - if (subjectConstraint is not null && expectationConstraint is not null) - { - Comparands newComparands = new() - { - Subject = subjectConstraint, - Expectation = expectationConstraint, - CompileTimeType = typeof(Constraint) - }; - - IEquivalencyValidationContext nestedContext = context.AsCollectionItem(constraintName); - nestedValidator.RecursivelyAssertEquality(newComparands, nestedContext); - } - } - } - - return EquivalencyResult.AssertionCompleted; - } -} diff --git a/Src/FluentAssertions/Equivalency/Steps/ConstraintEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/ConstraintEquivalencyStep.cs deleted file mode 100644 index 4eb8c9ce1b..0000000000 --- a/Src/FluentAssertions/Equivalency/Steps/ConstraintEquivalencyStep.cs +++ /dev/null @@ -1,286 +0,0 @@ -using System.Collections.Generic; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Text; -using FluentAssertions.Execution; -using FluentAssertions.Formatting; - -namespace FluentAssertions.Equivalency.Steps; - -public class ConstraintEquivalencyStep : EquivalencyStep -{ - protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) - { - if (comparands.Subject is not Constraint) - { - AssertionScope.Current - .FailWith("Expected {context:constraint} to be a value of type Constraint, but found {0}", - comparands.Subject.GetType()); - } - else - { - var subject = (Constraint)comparands.Subject; - var expectation = (Constraint)comparands.Expectation; - - var selectedMembers = GetMembersFromExpectation(comparands, context.CurrentNode, context.Options) - .ToDictionary(member => member.Name); - - CompareCommonProperties(context, nestedValidator, context.Options, subject, expectation, selectedMembers); - - bool matchingType = subject.GetType() == expectation.GetType(); - - AssertionScope.Current - .ForCondition(matchingType) - .FailWith("Expected {context:constraint} to be of type {0}, but found {1}", expectation.GetType(), - subject.GetType()); - - if (matchingType) - { - if (subject is UniqueConstraint subjectUniqueConstraint - && expectation is UniqueConstraint expectationUniqueConstraint) - { - CompareConstraints(nestedValidator, context, subjectUniqueConstraint, expectationUniqueConstraint, - selectedMembers); - } - else if (subject is ForeignKeyConstraint subjectForeignKeyConstraint - && expectation is ForeignKeyConstraint expectationForeignKeyConstraint) - { - CompareConstraints(nestedValidator, context, subjectForeignKeyConstraint, expectationForeignKeyConstraint, - selectedMembers); - } - else - { - AssertionScope.Current - .FailWith("Don't know how to handle {constraint:a Constraint} of type {0}", subject.GetType()); - } - } - } - - return EquivalencyResult.AssertionCompleted; - } - - private static void CompareCommonProperties(IEquivalencyValidationContext context, IEquivalencyValidator parent, - IEquivalencyAssertionOptions options, Constraint subject, Constraint expectation, - Dictionary selectedMembers) - { - if (selectedMembers.ContainsKey("ConstraintName")) - { - AssertionScope.Current - .ForCondition(subject.ConstraintName == expectation.ConstraintName) - .FailWith("Expected {context:constraint} to have a ConstraintName of {0}{reason}, but found {1}", - expectation.ConstraintName, subject.ConstraintName); - } - - if (selectedMembers.ContainsKey("Table")) - { - AssertionScope.Current - .ForCondition(subject.Table.TableName == expectation.Table.TableName) - .FailWith( - "Expected {context:constraint} to be associated with a Table with TableName of {0}{reason}, but found {1}", - expectation.Table.TableName, subject.Table.TableName); - } - - if (selectedMembers.TryGetValue("ExtendedProperties", out IMember expectationMember)) - { - IMember matchingMember = FindMatchFor(expectationMember, context.CurrentNode, subject, options); - - if (matchingMember is not null) - { - var nestedComparands = new Comparands - { - Subject = matchingMember.GetValue(subject), - Expectation = expectationMember.GetValue(expectation), - CompileTimeType = expectationMember.Type - }; - - parent.RecursivelyAssertEquality(nestedComparands, context.AsNestedMember(expectationMember)); - } - } - } - - private static void CompareConstraints(IEquivalencyValidator parent, IEquivalencyValidationContext context, - UniqueConstraint subject, UniqueConstraint expectation, Dictionary selectedMembers) - { - AssertionScope.Current - .ForCondition(subject.ConstraintName == expectation.ConstraintName) - .FailWith("Expected {context:constraint} to be named {0}{reason}, but found {1}", expectation.ConstraintName, - subject.ConstraintName); - - var nestedMember = new Property( - typeof(Constraint).GetProperty(nameof(subject.ExtendedProperties)), - context.CurrentNode); - - var nestedComparands = new Comparands - { - Subject = nestedMember.GetValue(subject), - Expectation = nestedMember.GetValue(expectation), - CompileTimeType = nestedMember.Type - }; - - parent.RecursivelyAssertEquality(nestedComparands, context.AsNestedMember(nestedMember)); - - if (selectedMembers.ContainsKey(nameof(expectation.IsPrimaryKey))) - { - AssertionScope.Current - .ForCondition(subject.IsPrimaryKey == expectation.IsPrimaryKey) - .FailWith("Expected {context:constraint} to be a {0} constraint{reason}, but found a {1} constraint", - expectation.IsPrimaryKey ? "Primary Key" : "Foreign Key", - subject.IsPrimaryKey ? "Primary Key" : "Foreign Key"); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Columns))) - { - CompareConstraintColumns(subject.Columns, expectation.Columns); - } - } - - [SuppressMessage("Design", "MA0051:Method is too long", Justification = "Needs to be refactored")] - private static void CompareConstraints(IEquivalencyValidator parent, IEquivalencyValidationContext context, - ForeignKeyConstraint subject, ForeignKeyConstraint expectation, Dictionary selectedMembers) - { - AssertionScope.Current - .ForCondition(subject.ConstraintName == expectation.ConstraintName) - .FailWith("Expected {context:constraint} to be named {0}{reason}, but found {1}", expectation.ConstraintName, - subject.ConstraintName); - - var nestedMember = new Property( - typeof(Constraint).GetProperty(nameof(subject.ExtendedProperties)), - context.CurrentNode); - - var nestedComparands = new Comparands - { - Subject = nestedMember.GetValue(subject), - Expectation = nestedMember.GetValue(expectation), - CompileTimeType = nestedMember.Type - }; - - parent.RecursivelyAssertEquality(nestedComparands, context.AsNestedMember(nestedMember)); - - if (selectedMembers.ContainsKey(nameof(expectation.RelatedTable))) - { - AssertionScope.Current - .ForCondition(subject.RelatedTable.TableName == expectation.RelatedTable.TableName) - .FailWith("Expected {context:constraint} to have a related table named {0}{reason}, but found {1}", - expectation.RelatedTable.TableName, subject.RelatedTable.TableName); - } - - if (selectedMembers.ContainsKey(nameof(expectation.AcceptRejectRule))) - { - AssertionScope.Current - .ForCondition(subject.AcceptRejectRule == expectation.AcceptRejectRule) - .FailWith( - "Expected {context:constraint} to have AcceptRejectRule.{0}{reason}, but found AcceptRejectRule.{1}", - expectation.AcceptRejectRule, subject.AcceptRejectRule); - } - - if (selectedMembers.ContainsKey(nameof(expectation.DeleteRule))) - { - AssertionScope.Current - .ForCondition(subject.DeleteRule == expectation.DeleteRule) - .FailWith("Expected {context:constraint} to have DeleteRule Rule.{0}{reason}, but found Rule.{1}", - expectation.DeleteRule, subject.DeleteRule); - } - - if (selectedMembers.ContainsKey(nameof(expectation.UpdateRule))) - { - AssertionScope.Current - .ForCondition(subject.UpdateRule == expectation.UpdateRule) - .FailWith("Expected {context:constraint} to have UpdateRule Rule.{0}{reason}, but found Rule.{1}", - expectation.UpdateRule, subject.UpdateRule); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Columns))) - { - CompareConstraintColumns(subject.Columns, expectation.Columns); - } - - if (selectedMembers.ContainsKey(nameof(expectation.RelatedColumns))) - { - CompareConstraintColumns(subject.RelatedColumns, expectation.RelatedColumns); - } - } - - private static void CompareConstraintColumns(DataColumn[] subjectColumns, DataColumn[] expectationColumns) - { - var subjectColumnNames = new HashSet(subjectColumns.Select(col => col.ColumnName)); - var expectationColumnNames = new HashSet(expectationColumns.Select(col => col.ColumnName)); - - var missingColumnNames = expectationColumnNames.Except(subjectColumnNames).ToList(); - var extraColumnNames = subjectColumnNames.Except(expectationColumnNames).ToList(); - - var failureMessage = new StringBuilder(); - - if (missingColumnNames.Count > 0) - { - failureMessage.Append("Expected {context:constraint} to include "); - - if (missingColumnNames.Count == 1) - { - failureMessage.Append("column ").Append(missingColumnNames.Single()); - } - else - { - failureMessage.Append("columns ").Append(missingColumnNames.JoinUsingWritingStyle()); - } - - failureMessage - .Append("{reason}, but constraint does not include ") - .Append(missingColumnNames.Count == 1 - ? "that column. " - : "these columns. "); - } - - if (extraColumnNames.Count > 0) - { - failureMessage.Append("Did not expect {context:constraint} to include "); - - if (extraColumnNames.Count == 1) - { - failureMessage.Append("column ").Append(extraColumnNames.Single()); - } - else - { - failureMessage.Append("columns ").Append(extraColumnNames.JoinUsingWritingStyle()); - } - - failureMessage.Append("{reason}, but it does."); - } - - bool successful = failureMessage.Length == 0; - - AssertionScope.Current - .ForCondition(successful) - .FailWith(failureMessage.ToString()); - } - - private static IMember FindMatchFor(IMember selectedMemberInfo, INode currentNode, object subject, - IEquivalencyAssertionOptions config) - { - IEnumerable query = - from rule in config.MatchingRules - let match = rule.Match(selectedMemberInfo, subject, currentNode, config) - where match is not null - select match; - - return query.FirstOrDefault(); - } - - private static IEnumerable GetMembersFromExpectation(Comparands comparands, INode currentNode, - IEquivalencyAssertionOptions options) - { - IEnumerable members = Enumerable.Empty(); - - foreach (IMemberSelectionRule rule in options.SelectionRules) - { - // Within a ConstraintCollection, different types of Constraint are kept polymorphically. - // As such, the concept of "compile-time type" isn't meaningful, and we override this - // with the discovered type of the constraint at runtime. - members = rule.SelectMembers(currentNode, members, - new MemberSelectionContext(comparands.RuntimeType, comparands.RuntimeType, options)); - } - - return members; - } -} diff --git a/Src/FluentAssertions/Equivalency/Steps/DataColumnEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/DataColumnEquivalencyStep.cs deleted file mode 100644 index 0d0e80d72e..0000000000 --- a/Src/FluentAssertions/Equivalency/Steps/DataColumnEquivalencyStep.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System.Collections.Generic; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using FluentAssertions.Data; -using FluentAssertions.Execution; - -namespace FluentAssertions.Equivalency.Steps; - -public class DataColumnEquivalencyStep : EquivalencyStep -{ - [SuppressMessage("Style", "IDE0019:Use pattern matching", Justification = "The code is easier to read without it.")] - protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) - { - var subject = comparands.Subject as DataColumn; - var expectation = comparands.Expectation as DataColumn; - - if (expectation is null) - { - if (subject is not null) - { - AssertionScope.Current.FailWith("Expected {context:DataColumn} value to be null, but found {0}", subject); - } - } - else if (subject is null) - { - if (comparands.Subject is null) - { - AssertionScope.Current.FailWith("Expected {context:DataColumn} to be non-null, but found null"); - } - else - { - AssertionScope.Current.FailWith("Expected {context:DataColumn} to be of type {0}, but found {1} instead", - expectation.GetType(), comparands.Subject.GetType()); - } - } - else - { - CompareSubjectAndExpectationOfTypeDataColumn(comparands, context, nestedValidator, subject); - } - - return EquivalencyResult.AssertionCompleted; - } - - private static void CompareSubjectAndExpectationOfTypeDataColumn(Comparands comparands, - IEquivalencyValidationContext context, IEquivalencyValidator parent, DataColumn subject) - { - bool compareColumn = true; - - var dataSetConfig = context.Options as DataEquivalencyAssertionOptions; - var dataTableConfig = context.Options as DataEquivalencyAssertionOptions; - var dataColumnConfig = context.Options as DataEquivalencyAssertionOptions; - - if (dataSetConfig?.ShouldExcludeColumn(subject) == true - || dataTableConfig?.ShouldExcludeColumn(subject) == true - || dataColumnConfig?.ShouldExcludeColumn(subject) == true) - { - compareColumn = false; - } - - if (compareColumn) - { - foreach (IMember expectationMember in GetMembersFromExpectation(context.CurrentNode, comparands, context.Options)) - { - if (expectationMember.Name != nameof(subject.Table)) - { - CompareMember(expectationMember, comparands, parent, context); - } - } - } - } - - private static void CompareMember(IMember expectationMember, Comparands comparands, IEquivalencyValidator parent, - IEquivalencyValidationContext context) - { - IMember matchingMember = FindMatchFor(expectationMember, comparands.Subject, context); - - if (matchingMember is not null) - { - var nestedComparands = new Comparands - { - Subject = matchingMember.GetValue(comparands.Subject), - Expectation = expectationMember.GetValue(comparands.Expectation), - CompileTimeType = expectationMember.Type - }; - - if (context.AsNestedMember(expectationMember) is not null) - { - parent.RecursivelyAssertEquality(nestedComparands, context.AsNestedMember(expectationMember)); - } - } - } - - private static IMember FindMatchFor(IMember selectedMemberInfo, object subject, IEquivalencyValidationContext context) - { - IEnumerable query = - from rule in context.Options.MatchingRules - let match = rule.Match(selectedMemberInfo, subject, context.CurrentNode, context.Options) - where match is not null - select match; - - return query.FirstOrDefault(); - } - - // NOTE: This list of candidate members is duplicated in the XML documentation for the - // DataColumn.BeEquivalentTo extension method in DataColumnAssertions.cs. If this ever - // needs to change, keep them in sync. - private static readonly HashSet CandidateMembers = new() - { - nameof(DataColumn.AllowDBNull), - nameof(DataColumn.AutoIncrement), - nameof(DataColumn.AutoIncrementSeed), - nameof(DataColumn.AutoIncrementStep), - nameof(DataColumn.Caption), - nameof(DataColumn.ColumnName), - nameof(DataColumn.DataType), - nameof(DataColumn.DateTimeMode), - nameof(DataColumn.DefaultValue), - nameof(DataColumn.Expression), - nameof(DataColumn.ExtendedProperties), - nameof(DataColumn.MaxLength), - nameof(DataColumn.Namespace), - nameof(DataColumn.Prefix), - nameof(DataColumn.ReadOnly), - nameof(DataColumn.Unique), - }; - - private static IEnumerable GetMembersFromExpectation(INode currentNode, Comparands comparands, - IEquivalencyAssertionOptions config) - { - IEnumerable members = Enumerable.Empty(); - - foreach (IMemberSelectionRule rule in config.SelectionRules) - { - members = rule.SelectMembers(currentNode, members, - new MemberSelectionContext(comparands.CompileTimeType, comparands.RuntimeType, config)); - } - - return members.Where(member => CandidateMembers.Contains(member.Name)); - } -} diff --git a/Src/FluentAssertions/Equivalency/Steps/DataRelationEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/DataRelationEquivalencyStep.cs deleted file mode 100644 index 0ec9c92051..0000000000 --- a/Src/FluentAssertions/Equivalency/Steps/DataRelationEquivalencyStep.cs +++ /dev/null @@ -1,244 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using FluentAssertions.Execution; - -namespace FluentAssertions.Equivalency.Steps; - -public class DataRelationEquivalencyStep : EquivalencyStep -{ - [SuppressMessage("Style", "IDE0019:Use pattern matching", Justification = "The code is easier to read without it.")] - protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) - { - var subject = comparands.Subject as DataRelation; - var expectation = comparands.Expectation as DataRelation; - - if (expectation is null) - { - if (subject is not null) - { - AssertionScope.Current.FailWith("Expected {context:DataRelation} to be null, but found {0}", subject); - } - } - else if (subject is null) - { - if (comparands.Subject is null) - { - AssertionScope.Current.FailWith("Expected {context:DataRelation} value to be non-null, but found null"); - } - else - { - AssertionScope.Current.FailWith("Expected {context:DataRelation} of type {0}, but found {1} instead", - expectation.GetType(), comparands.Subject.GetType()); - } - } - else - { - var selectedMembers = GetMembersFromExpectation(context.CurrentNode, comparands, context.Options) - .ToDictionary(member => member.Name); - - CompareScalarProperties(subject, expectation, selectedMembers); - - CompareCollections(context, comparands, nestedValidator, context.Options, selectedMembers); - - CompareRelationConstraints(context, nestedValidator, subject, expectation, selectedMembers); - } - - return EquivalencyResult.AssertionCompleted; - } - - private static void CompareScalarProperties(DataRelation subject, DataRelation expectation, - Dictionary selectedMembers) - { - if (selectedMembers.ContainsKey(nameof(expectation.RelationName))) - { - AssertionScope.Current - .ForCondition(subject.RelationName == expectation.RelationName) - .FailWith("Expected {context:DataRelation} to have RelationName of {0}{reason}, but found {1}", - expectation.RelationName, subject.RelationName); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Nested))) - { - AssertionScope.Current - .ForCondition(subject.Nested == expectation.Nested) - .FailWith("Expected {context:DataRelation} to have Nested value of {0}{reason}, but found {1}", - expectation.Nested, subject.Nested); - } - - // Special case: Compare name only - if (selectedMembers.ContainsKey(nameof(expectation.DataSet))) - { - AssertionScope.Current - .ForCondition(subject.DataSet?.DataSetName == expectation.DataSet?.DataSetName) - .FailWith("Expected containing DataSet of {context:DataRelation} to be {0}{reason}, but found {1}", - expectation.DataSet?.DataSetName ?? "", - subject.DataSet?.DataSetName ?? ""); - } - } - - private static void CompareCollections(IEquivalencyValidationContext context, Comparands comparands, - IEquivalencyValidator parent, - IEquivalencyAssertionOptions config, Dictionary selectedMembers) - { - if (selectedMembers.TryGetValue(nameof(DataRelation.ExtendedProperties), out IMember expectationMember)) - { - IMember matchingMember = FindMatchFor(expectationMember, context.CurrentNode, comparands.Subject, config); - - if (matchingMember is not null) - { - var nestedComparands = new Comparands - { - Subject = matchingMember.GetValue(comparands.Subject), - Expectation = expectationMember.GetValue(comparands.Expectation), - CompileTimeType = expectationMember.Type - }; - - parent.RecursivelyAssertEquality(nestedComparands, context.AsNestedMember(expectationMember)); - } - } - } - - private static void CompareRelationConstraints(IEquivalencyValidationContext context, IEquivalencyValidator parent, - DataRelation subject, DataRelation expectation, - Dictionary selectedMembers) - { - CompareDataRelationConstraints( - parent, context, subject, expectation, selectedMembers, - "Child", - selectedMembers.ContainsKey(nameof(DataRelation.ChildTable)), - selectedMembers.ContainsKey(nameof(DataRelation.ChildColumns)), - selectedMembers.ContainsKey(nameof(DataRelation.ChildKeyConstraint)), - r => r.ChildColumns, - r => r.ChildTable); - - CompareDataRelationConstraints( - parent, context, subject, expectation, selectedMembers, - "Parent", - selectedMembers.ContainsKey(nameof(DataRelation.ParentTable)), - selectedMembers.ContainsKey(nameof(DataRelation.ParentColumns)), - selectedMembers.ContainsKey(nameof(DataRelation.ParentKeyConstraint)), - r => r.ParentColumns, - r => r.ParentTable); - } - - private static void CompareDataRelationConstraints( - IEquivalencyValidator parent, IEquivalencyValidationContext context, - DataRelation subject, DataRelation expectation, Dictionary selectedMembers, - string relationDirection, - bool compareTable, bool compareColumns, bool compareKeyConstraint, - Func getColumns, - Func getOtherTable) - { - if (compareColumns) - { - CompareDataRelationColumns(subject, expectation, getColumns); - } - - if (compareTable) - { - CompareDataRelationTable(subject, expectation, getOtherTable); - } - - if (compareKeyConstraint) - { - CompareDataRelationKeyConstraint(subject, expectation, parent, context, selectedMembers, relationDirection); - } - } - - private static void CompareDataRelationColumns(DataRelation subject, DataRelation expectation, - Func getColumns) - { - DataColumn[] subjectColumns = getColumns(subject); - DataColumn[] expectationColumns = getColumns(expectation); - - // These column references are in different tables in different data sets that _should_ be equivalent - // to one another. - bool success = AssertionScope.Current - .ForCondition(subjectColumns.Length == expectationColumns.Length) - .FailWith("Expected {context:DataRelation} to reference {0} column(s){reason}, but found {subjectColumns.Length}", - expectationColumns.Length, subjectColumns.Length); - - if (success) - { - for (int i = 0; i < expectationColumns.Length; i++) - { - DataColumn subjectColumn = subjectColumns[i]; - DataColumn expectationColumn = expectationColumns[i]; - - bool columnsAreEquivalent = - subjectColumn.Table.TableName == expectationColumn.Table.TableName && - subjectColumn.ColumnName == expectationColumn.ColumnName; - - AssertionScope.Current - .ForCondition(columnsAreEquivalent) - .FailWith( - "Expected {context:DataRelation} to reference column {0} in table {1}{reason}, but found a reference to {2} in table {3} instead", - expectationColumn.ColumnName, - expectationColumn.Table.TableName, - subjectColumn.ColumnName, - subjectColumn.Table.TableName); - } - } - } - - private static void CompareDataRelationTable(DataRelation subject, DataRelation expectation, - Func getOtherTable) - { - DataTable subjectTable = getOtherTable(subject); - DataTable expectationTable = getOtherTable(expectation); - - AssertionScope.Current - .ForCondition(subjectTable.TableName == expectationTable.TableName) - .FailWith("Expected {context:DataRelation} to reference a table named {0}{reason}, but found {1} instead", - expectationTable.TableName, subjectTable.TableName); - } - - private static void CompareDataRelationKeyConstraint(DataRelation subject, DataRelation expectation, - IEquivalencyValidator parent, IEquivalencyValidationContext context, Dictionary selectedMembers, - string relationDirection) - { - if (selectedMembers.TryGetValue(relationDirection + "KeyConstraint", out IMember expectationMember)) - { - IMember subjectMember = FindMatchFor(expectationMember, context.CurrentNode, subject, context.Options); - - var newComparands = new Comparands - { - Subject = subjectMember.GetValue(subject), - Expectation = expectationMember.GetValue(expectation), - CompileTimeType = expectationMember.Type - }; - - parent.RecursivelyAssertEquality(newComparands, context.AsNestedMember(expectationMember)); - } - } - - private static IMember FindMatchFor(IMember selectedMemberInfo, INode currentNode, object subject, - IEquivalencyAssertionOptions config) - { - IEnumerable query = - from rule in config.MatchingRules - let match = rule.Match(selectedMemberInfo, subject, currentNode, config) - where match is not null - select match; - - return query.FirstOrDefault(); - } - - private static IEnumerable GetMembersFromExpectation(INode currentNode, Comparands comparands, - IEquivalencyAssertionOptions config) - { - IEnumerable members = Enumerable.Empty(); - - foreach (IMemberSelectionRule rule in config.SelectionRules) - { - members = rule.SelectMembers(currentNode, members, - new MemberSelectionContext(comparands.CompileTimeType, comparands.RuntimeType, config)); - } - - return members; - } -} diff --git a/Src/FluentAssertions/Equivalency/Steps/DataRowCollectionEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/DataRowCollectionEquivalencyStep.cs deleted file mode 100644 index 62d434b11d..0000000000 --- a/Src/FluentAssertions/Equivalency/Steps/DataRowCollectionEquivalencyStep.cs +++ /dev/null @@ -1,244 +0,0 @@ -using System; -using System.Data; -using System.Linq; -using FluentAssertions.Data; -using FluentAssertions.Execution; - -namespace FluentAssertions.Equivalency.Steps; - -public class DataRowCollectionEquivalencyStep : EquivalencyStep -{ - protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) - { - if (comparands.Subject is not DataRowCollection) - { - AssertionScope.Current - .FailWith("Expected {context:value} to be of type DataRowCollection, but found {0}", - comparands.Subject.GetType()); - } - else - { - RowMatchMode rowMatchMode = context.Options switch - { - DataEquivalencyAssertionOptions dataSetConfig => dataSetConfig.RowMatchMode, - DataEquivalencyAssertionOptions dataTableConfig => dataTableConfig.RowMatchMode, - _ => RowMatchMode.Index - }; - - var subject = (DataRowCollection)comparands.Subject; - var expectation = (DataRowCollection)comparands.Expectation; - - bool success = AssertionScope.Current - .ForCondition(subject.Count == expectation.Count) - .FailWith("Expected {context:DataRowCollection} to contain {0} row(s){reason}, but found {1}", - expectation.Count, subject.Count); - - if (success) - { - switch (rowMatchMode) - { - case RowMatchMode.Index: - MatchRowsByIndexAndCompare(context, nestedValidator, subject, expectation); - break; - - case RowMatchMode.PrimaryKey: - MatchRowsByPrimaryKeyAndCompare(nestedValidator, context, subject, expectation); - break; - - default: - AssertionScope.Current.FailWith( - "Unknown RowMatchMode {0} when trying to compare {context:DataRowCollection}", rowMatchMode); - - break; - } - } - } - - return EquivalencyResult.AssertionCompleted; - } - - private static void MatchRowsByIndexAndCompare(IEquivalencyValidationContext context, IEquivalencyValidator parent, - DataRowCollection subject, DataRowCollection expectation) - { - for (int index = 0; index < expectation.Count; index++) - { - IEquivalencyValidationContext nestedContext = context.AsCollectionItem(index); - parent.RecursivelyAssertEquality(new Comparands(subject[index], expectation[index], typeof(DataRow)), nestedContext); - } - } - - private static void MatchRowsByPrimaryKeyAndCompare(IEquivalencyValidator parent, IEquivalencyValidationContext context, - DataRowCollection subject, DataRowCollection expectation) - { - Type[] subjectPrimaryKeyTypes = null; - Type[] expectationPrimaryKeyTypes = null; - - if (subject.Count > 0) - { - subjectPrimaryKeyTypes = GatherPrimaryKeyColumnTypes(subject[0].Table, "subject"); - } - - if (expectation.Count > 0) - { - expectationPrimaryKeyTypes = GatherPrimaryKeyColumnTypes(expectation[0].Table, "expectation"); - } - - bool matchingTypes = ComparePrimaryKeyTypes(subjectPrimaryKeyTypes, expectationPrimaryKeyTypes); - - if (matchingTypes) - { - GatherRowsByPrimaryKeyAndCompareData(parent, context, subject, expectation); - } - } - - private static Type[] GatherPrimaryKeyColumnTypes(DataTable table, string comparisonTerm) - { - Type[] primaryKeyTypes = null; - - if (table.PrimaryKey is null or { Length: 0 }) - { - AssertionScope.Current - .FailWith( - "Table {0} containing {1} {context:DataRowCollection} does not have a primary key. RowMatchMode.PrimaryKey cannot be applied.", - table.TableName, comparisonTerm); - } - else - { - primaryKeyTypes = new Type[table.PrimaryKey.Length]; - - for (int i = 0; i < table.PrimaryKey.Length; i++) - { - primaryKeyTypes[i] = table.PrimaryKey[i].DataType; - } - } - - return primaryKeyTypes; - } - - private static bool ComparePrimaryKeyTypes(Type[] subjectPrimaryKeyTypes, Type[] expectationPrimaryKeyTypes) - { - bool matchingTypes = false; - - if (subjectPrimaryKeyTypes is not null && expectationPrimaryKeyTypes is not null) - { - matchingTypes = subjectPrimaryKeyTypes.Length == expectationPrimaryKeyTypes.Length; - - for (int i = 0; matchingTypes && i < subjectPrimaryKeyTypes.Length; i++) - { - if (subjectPrimaryKeyTypes[i] != expectationPrimaryKeyTypes[i]) - { - matchingTypes = false; - } - } - - if (!matchingTypes) - { - AssertionScope.Current - .FailWith( - "Subject and expectation primary keys of table containing {context:DataRowCollection} do not have the same schema and cannot be compared. RowMatchMode.PrimaryKey cannot be applied."); - } - } - - return matchingTypes; - } - - private static void GatherRowsByPrimaryKeyAndCompareData(IEquivalencyValidator parent, IEquivalencyValidationContext context, - DataRowCollection subject, DataRowCollection expectation) - { - var expectationRowByKey = expectation.Cast() - .ToDictionary(row => ExtractPrimaryKey(row)); - - foreach (DataRow subjectRow in subject.Cast()) - { - CompoundKey key = ExtractPrimaryKey(subjectRow); - - if (!expectationRowByKey.TryGetValue(key, out DataRow expectationRow)) - { - AssertionScope.Current - .FailWith("Found unexpected row in {context:DataRowCollection} with key {0}", key); - } - else - { - expectationRowByKey.Remove(key); - - IEquivalencyValidationContext nestedContext = context.AsCollectionItem(key.ToString()); - parent.RecursivelyAssertEquality(new Comparands(subjectRow, expectationRow, typeof(DataRow)), nestedContext); - } - } - - if (expectationRowByKey.Count > 0) - { - if (expectationRowByKey.Count > 1) - { - AssertionScope.Current - .FailWith("{0} rows were expected in {context:DataRowCollection} and not found", expectationRowByKey.Count); - } - else - { - AssertionScope.Current - .FailWith( - "Expected to find a row with key {0} in {context:DataRowCollection}{reason}, but no such row was found", - expectationRowByKey.Keys.Single()); - } - } - } - - private sealed class CompoundKey : IEquatable - { - private readonly object[] values; - - public CompoundKey(params object[] values) - { - this.values = values; - } - - public bool Equals(CompoundKey other) - { - if (other is null) - { - return false; - } - - if (values.Length != other.values.Length) - { - return false; - } - - return values.SequenceEqual(other.values); - } - - public override bool Equals(object obj) => Equals(obj as CompoundKey); - - public override int GetHashCode() - { - int hash = 0; - - foreach (var value in values) - { - hash = hash * 389 ^ value.GetHashCode(); - } - - return hash; - } - - public override string ToString() - { - return "{ " + string.Join(", ", values) + " }"; - } - } - - private static CompoundKey ExtractPrimaryKey(DataRow row) - { - DataColumn[] primaryKey = row.Table.PrimaryKey; - - var values = new object[primaryKey.Length]; - - for (int i = 0; i < values.Length; i++) - { - values[i] = row[primaryKey[i]]; - } - - return new CompoundKey(values); - } -} diff --git a/Src/FluentAssertions/Equivalency/Steps/DataRowEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/DataRowEquivalencyStep.cs deleted file mode 100644 index 38240907a8..0000000000 --- a/Src/FluentAssertions/Equivalency/Steps/DataRowEquivalencyStep.cs +++ /dev/null @@ -1,220 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using FluentAssertions.Data; -using FluentAssertions.Execution; - -namespace FluentAssertions.Equivalency.Steps; - -public class DataRowEquivalencyStep : EquivalencyStep -{ - [SuppressMessage("Style", "IDE0019:Use pattern matching", Justification = "The code is easier to read without it.")] - protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) - { - var subject = comparands.Subject as DataRow; - var expectation = comparands.Expectation as DataRow; - - if (expectation is null) - { - if (subject is not null) - { - AssertionScope.Current.FailWith("Expected {context:DataRow} value to be null, but found {0}", subject); - } - } - else if (subject is null) - { - if (comparands.Subject is null) - { - AssertionScope.Current.FailWith("Expected {context:DataRow} to be non-null, but found null"); - } - else - { - AssertionScope.Current.FailWith("Expected {context:DataRow} to be of type {0}, but found {1} instead", - expectation.GetType(), comparands.Subject.GetType()); - } - } - else - { - var dataSetConfig = context.Options as DataEquivalencyAssertionOptions; - var dataTableConfig = context.Options as DataEquivalencyAssertionOptions; - var dataRowConfig = context.Options as DataEquivalencyAssertionOptions; - - if (dataSetConfig?.AllowMismatchedTypes != true - && dataTableConfig?.AllowMismatchedTypes != true - && dataRowConfig?.AllowMismatchedTypes != true) - { - AssertionScope.Current - .ForCondition(subject.GetType() == expectation.GetType()) - .FailWith("Expected {context:DataRow} to be of type {0}{reason}, but found {1}", - expectation.GetType(), subject.GetType()); - } - - SelectedDataRowMembers selectedMembers = - GetMembersFromExpectation(comparands, context.CurrentNode, context.Options); - - CompareScalarProperties(subject, expectation, selectedMembers); - - CompareFieldValues(context, nestedValidator, subject, expectation, dataSetConfig, dataTableConfig, - dataRowConfig); - } - - return EquivalencyResult.AssertionCompleted; - } - - private static void CompareScalarProperties(DataRow subject, DataRow expectation, SelectedDataRowMembers selectedMembers) - { - // Note: The members here are listed in the XML documentation for the DataRow.BeEquivalentTo extension - // method in DataRowAssertions.cs. If this ever needs to change, keep them in sync. - if (selectedMembers.HasErrors) - { - AssertionScope.Current - .ForCondition(subject.HasErrors == expectation.HasErrors) - .FailWith("Expected {context:DataRow} to have HasErrors value of {0}{reason}, but found {1} instead", - expectation.HasErrors, subject.HasErrors); - } - - if (selectedMembers.RowState) - { - AssertionScope.Current - .ForCondition(subject.RowState == expectation.RowState) - .FailWith("Expected {context:DataRow} to have RowState value of {0}{reason}, but found {1} instead", - expectation.RowState, subject.RowState); - } - } - - [SuppressMessage("Maintainability", "AV1561:Signature contains too many parameters", Justification = "Needs to be refactored")] - [SuppressMessage("Design", "MA0051:Method is too long", Justification = "Needs to be refactored")] - private static void CompareFieldValues(IEquivalencyValidationContext context, IEquivalencyValidator parent, - DataRow subject, DataRow expectation, DataEquivalencyAssertionOptions dataSetConfig, - DataEquivalencyAssertionOptions dataTableConfig, DataEquivalencyAssertionOptions dataRowConfig) - { - IEnumerable expectationColumnNames = expectation.Table.Columns.Cast() - .Select(col => col.ColumnName); - - IEnumerable subjectColumnNames = subject.Table.Columns.Cast() - .Select(col => col.ColumnName); - - bool ignoreUnmatchedColumns = - dataSetConfig?.IgnoreUnmatchedColumns == true || - dataTableConfig?.IgnoreUnmatchedColumns == true || - dataRowConfig?.IgnoreUnmatchedColumns == true; - - DataRowVersion subjectVersion = - subject.RowState == DataRowState.Deleted - ? DataRowVersion.Original - : DataRowVersion.Current; - - DataRowVersion expectationVersion = - expectation.RowState == DataRowState.Deleted - ? DataRowVersion.Original - : DataRowVersion.Current; - - bool compareOriginalVersions = - subject.RowState == DataRowState.Modified && expectation.RowState == DataRowState.Modified; - - if (dataSetConfig?.ExcludeOriginalData == true - || dataTableConfig?.ExcludeOriginalData == true - || dataRowConfig?.ExcludeOriginalData == true) - { - compareOriginalVersions = false; - } - - foreach (var columnName in expectationColumnNames.Union(subjectColumnNames)) - { - DataColumn expectationColumn = expectation.Table.Columns[columnName]; - DataColumn subjectColumn = subject.Table.Columns[columnName]; - - if (subjectColumn is not null - && (dataSetConfig?.ShouldExcludeColumn(subjectColumn) == true - || dataTableConfig?.ShouldExcludeColumn(subjectColumn) == true - || dataRowConfig?.ShouldExcludeColumn(subjectColumn) == true)) - { - continue; - } - - if (!ignoreUnmatchedColumns) - { - AssertionScope.Current - .ForCondition(subjectColumn is not null) - .FailWith("Expected {context:DataRow} to have column {0}{reason}, but found none", columnName); - - AssertionScope.Current - .ForCondition(expectationColumn is not null) - .FailWith("Found unexpected column {0} in {context:DataRow}", columnName); - } - - if (subjectColumn is not null && expectationColumn is not null) - { - CompareFieldValue(context, parent, subject, expectation, subjectColumn, subjectVersion, expectationColumn, - expectationVersion); - - if (compareOriginalVersions) - { - CompareFieldValue(context, parent, subject, expectation, subjectColumn, DataRowVersion.Original, - expectationColumn, DataRowVersion.Original); - } - } - } - } - - private static void CompareFieldValue(IEquivalencyValidationContext context, IEquivalencyValidator parent, DataRow subject, - DataRow expectation, DataColumn subjectColumn, DataRowVersion subjectVersion, DataColumn expectationColumn, - DataRowVersion expectationVersion) - { - IEquivalencyValidationContext nestedContext = context.AsCollectionItem( - subjectVersion == DataRowVersion.Current - ? subjectColumn.ColumnName - : $"{subjectColumn.ColumnName}, DataRowVersion.Original"); - - if (nestedContext is not null) - { - parent.RecursivelyAssertEquality( - new Comparands(subject[subjectColumn, subjectVersion], expectation[expectationColumn, expectationVersion], - typeof(object)), - nestedContext); - } - } - - private sealed class SelectedDataRowMembers - { - public bool HasErrors { get; init; } - - public bool RowState { get; init; } - } - - private static readonly ConcurrentDictionary<(Type CompileTimeType, Type RuntimeType, IEquivalencyAssertionOptions Config), - SelectedDataRowMembers> SelectedMembersCache = new(); - - private static SelectedDataRowMembers GetMembersFromExpectation(Comparands comparands, INode currentNode, - IEquivalencyAssertionOptions config) - { - var cacheKey = (comparands.CompileTimeType, comparands.RuntimeType, config); - - if (!SelectedMembersCache.TryGetValue(cacheKey, out SelectedDataRowMembers selectedDataRowMembers)) - { - IEnumerable members = Enumerable.Empty(); - - foreach (IMemberSelectionRule rule in config.SelectionRules) - { - members = rule.SelectMembers(currentNode, members, - new MemberSelectionContext(comparands.CompileTimeType, comparands.RuntimeType, config)); - } - - IMember[] selectedMembers = members.ToArray(); - - selectedDataRowMembers = new SelectedDataRowMembers - { - HasErrors = selectedMembers.Any(m => m.Name == nameof(DataRow.HasErrors)), - RowState = selectedMembers.Any(m => m.Name == nameof(DataRow.RowState)) - }; - - SelectedMembersCache.TryAdd(cacheKey, selectedDataRowMembers); - } - - return selectedDataRowMembers; - } -} diff --git a/Src/FluentAssertions/Equivalency/Steps/DataSetEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/DataSetEquivalencyStep.cs deleted file mode 100644 index ebbf3525b3..0000000000 --- a/Src/FluentAssertions/Equivalency/Steps/DataSetEquivalencyStep.cs +++ /dev/null @@ -1,270 +0,0 @@ -using System.Collections.Generic; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using FluentAssertions.Data; -using FluentAssertions.Execution; - -namespace FluentAssertions.Equivalency.Steps; - -public class DataSetEquivalencyStep : EquivalencyStep -{ - protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) - { - var subject = comparands.Subject as DataSet; - - if (comparands.Expectation is not DataSet expectation) - { - if (subject is not null) - { - AssertionScope.Current.FailWith("Expected {context:DataSet} value to be null, but found {0}", subject); - } - } - else if (subject is null) - { - if (comparands.Subject is null) - { - AssertionScope.Current.FailWith("Expected {context:DataSet} to be non-null, but found null"); - } - else - { - AssertionScope.Current.FailWith("Expected {context:DataSet} to be of type {0}, but found {1} instead", - expectation.GetType(), comparands.Subject.GetType()); - } - } - else - { - var dataConfig = context.Options as DataEquivalencyAssertionOptions; - - if (dataConfig?.AllowMismatchedTypes != true) - { - AssertionScope.Current - .ForCondition(subject.GetType() == expectation.GetType()) - .FailWith("Expected {context:DataSet} to be of type {0}{reason}, but found {1}", expectation.GetType(), - subject.GetType()); - } - - var selectedMembers = GetMembersFromExpectation(comparands, context.CurrentNode, context.Options) - .ToDictionary(member => member.Name); - - CompareScalarProperties(subject, expectation, selectedMembers); - - CompareCollections(context, nestedValidator, context.Options, subject, expectation, dataConfig, selectedMembers); - } - - return EquivalencyResult.AssertionCompleted; - } - - [SuppressMessage("Design", "MA0051:Method is too long")] - private static void CompareScalarProperties(DataSet subject, DataSet expectation, Dictionary selectedMembers) - { - // Note: The members here are listed in the XML documentation for the DataSet.BeEquivalentTo extension - // method in DataSetAssertions.cs. If this ever needs to change, keep them in sync. - if (selectedMembers.ContainsKey(nameof(expectation.DataSetName))) - { - AssertionScope.Current - .ForCondition(subject.DataSetName == expectation.DataSetName) - .FailWith("Expected {context:DataSet} to have DataSetName {0}{reason}, but found {1} instead", - expectation.DataSetName, subject.DataSetName); - } - - if (selectedMembers.ContainsKey(nameof(expectation.CaseSensitive))) - { - AssertionScope.Current - .ForCondition(subject.CaseSensitive == expectation.CaseSensitive) - .FailWith("Expected {context:DataSet} to have CaseSensitive value of {0}{reason}, but found {1} instead", - expectation.CaseSensitive, subject.CaseSensitive); - } - - if (selectedMembers.ContainsKey(nameof(expectation.EnforceConstraints))) - { - AssertionScope.Current - .ForCondition(subject.EnforceConstraints == expectation.EnforceConstraints) - .FailWith("Expected {context:DataSet} to have EnforceConstraints value of {0}{reason}, but found {1} instead", - expectation.EnforceConstraints, subject.EnforceConstraints); - } - - if (selectedMembers.ContainsKey(nameof(expectation.HasErrors))) - { - AssertionScope.Current - .ForCondition(subject.HasErrors == expectation.HasErrors) - .FailWith("Expected {context:DataSet} to have HasErrors value of {0}{reason}, but found {1} instead", - expectation.HasErrors, subject.HasErrors); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Locale))) - { - AssertionScope.Current - .ForCondition(Equals(subject.Locale, expectation.Locale)) - .FailWith("Expected {context:DataSet} to have Locale value of {0}{reason}, but found {1} instead", - expectation.Locale, subject.Locale); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Namespace))) - { - AssertionScope.Current - .ForCondition(subject.Namespace == expectation.Namespace) - .FailWith("Expected {context:DataSet} to have Namespace value of {0}{reason}, but found {1} instead", - expectation.Namespace, subject.Namespace); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Prefix))) - { - AssertionScope.Current - .ForCondition(subject.Prefix == expectation.Prefix) - .FailWith("Expected {context:DataSet} to have Prefix value of {0}{reason}, but found {1} instead", - expectation.Prefix, subject.Prefix); - } - - if (selectedMembers.ContainsKey(nameof(expectation.RemotingFormat))) - { - AssertionScope.Current - .ForCondition(subject.RemotingFormat == expectation.RemotingFormat) - .FailWith("Expected {context:DataSet} to have RemotingFormat value of {0}{reason}, but found {1} instead", - expectation.RemotingFormat, subject.RemotingFormat); - } - - if (selectedMembers.ContainsKey(nameof(expectation.SchemaSerializationMode))) - { - AssertionScope.Current - .ForCondition(subject.SchemaSerializationMode == expectation.SchemaSerializationMode) - .FailWith( - "Expected {context:DataSet} to have SchemaSerializationMode value of {0}{reason}, but found {1} instead", - expectation.SchemaSerializationMode, subject.SchemaSerializationMode); - } - } - - private static void CompareCollections(IEquivalencyValidationContext context, IEquivalencyValidator parent, - IEquivalencyAssertionOptions config, DataSet subject, DataSet expectation, - DataEquivalencyAssertionOptions dataConfig, Dictionary selectedMembers) - { - // Note: The collections here are listed in the XML documentation for the DataSet.BeEquivalentTo extension - // method in DataSetAssertions.cs. If this ever needs to change, keep them in sync. - CompareExtendedProperties(new Comparands(subject, expectation, typeof(DataSet)), context, parent, config, - selectedMembers); - - CompareTables(context, parent, subject, expectation, dataConfig, selectedMembers); - } - - private static void CompareExtendedProperties(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator parent, IEquivalencyAssertionOptions config, Dictionary selectedMembers) - { - foreach (var collectionName in new[] { nameof(DataSet.ExtendedProperties), nameof(DataSet.Relations) }) - { - if (selectedMembers.TryGetValue(collectionName, out IMember expectationMember)) - { - IMember matchingMember = FindMatchFor(expectationMember, comparands.Subject, context.CurrentNode, config); - - if (matchingMember is not null) - { - var nestedComparands = new Comparands - { - Subject = matchingMember.GetValue(comparands.Subject), - Expectation = expectationMember.GetValue(comparands.Expectation), - CompileTimeType = expectationMember.Type - }; - - IEquivalencyValidationContext nestedContext = context.AsNestedMember(expectationMember); - parent.RecursivelyAssertEquality(nestedComparands, nestedContext); - } - } - } - } - - private static void CompareTables(IEquivalencyValidationContext context, IEquivalencyValidator parent, DataSet subject, - DataSet expectation, DataEquivalencyAssertionOptions dataConfig, Dictionary selectedMembers) - { - if (selectedMembers.ContainsKey(nameof(expectation.Tables))) - { - bool success = AssertionScope.Current - .ForCondition(subject.Tables.Count == expectation.Tables.Count) - .FailWith("Expected {context:DataSet} to contain {0}, but found {1} table(s)", expectation.Tables.Count, - subject.Tables.Count); - - if (!success) - { - return; - } - - if (dataConfig is not null) - { - bool excludeCaseSensitive = !selectedMembers.ContainsKey(nameof(DataSet.CaseSensitive)); - bool excludeLocale = !selectedMembers.ContainsKey(nameof(DataSet.Locale)); - - if (excludeCaseSensitive || excludeLocale) - { - dataConfig.Excluding(memberInfo => - memberInfo.DeclaringType == typeof(DataTable) && - ( - (excludeCaseSensitive && memberInfo.Name == nameof(DataTable.CaseSensitive)) - || - (excludeLocale && memberInfo.Name == nameof(DataTable.Locale)))); - } - } - - IEnumerable expectationTableNames = expectation.Tables.Cast() - .Select(table => table.TableName); - - IEnumerable subjectTableNames = subject.Tables.Cast() - .Select(table => table.TableName); - - foreach (string tableName in expectationTableNames.Union(subjectTableNames)) - { - if (dataConfig?.ExcludeTableNames.Contains(tableName) == true) - { - continue; - } - - CompareTable(context, parent, subject, expectation, tableName); - } - } - } - - private static void CompareTable(IEquivalencyValidationContext context, IEquivalencyValidator parent, DataSet subject, - DataSet expectation, string tableName) - { - DataTable expectationTable = expectation.Tables[tableName]; - DataTable subjectTable = subject.Tables[tableName]; - - bool success = AssertionScope.Current - .ForCondition(subjectTable is not null) - .FailWith("Expected {context:DataSet} to contain table {0}{reason}, but did not find it", tableName) - .Then - .ForCondition(expectationTable is not null) - .FailWith("Found unexpected table {0} in DataSet", tableName); - - if (success) - { - IEquivalencyValidationContext nestedContext = context.AsCollectionItem(tableName); - parent.RecursivelyAssertEquality(new Comparands(subjectTable, expectationTable, typeof(DataTable)), nestedContext); - } - } - - private static IMember FindMatchFor(IMember selectedMemberInfo, object subject, INode currentNode, - IEquivalencyAssertionOptions options) - { - IEnumerable query = - from rule in options.MatchingRules - let match = rule.Match(selectedMemberInfo, subject, currentNode, options) - where match is not null - select match; - - return query.FirstOrDefault(); - } - - private static IEnumerable GetMembersFromExpectation(Comparands comparands, - INode contextCurrentNode, - IEquivalencyAssertionOptions options) - { - IEnumerable members = Enumerable.Empty(); - - foreach (IMemberSelectionRule rule in options.SelectionRules) - { - members = rule.SelectMembers(contextCurrentNode, members, - new MemberSelectionContext(comparands.CompileTimeType, comparands.RuntimeType, options)); - } - - return members; - } -} diff --git a/Src/FluentAssertions/Equivalency/Steps/DataTableEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/DataTableEquivalencyStep.cs deleted file mode 100644 index 1fcf94909e..0000000000 --- a/Src/FluentAssertions/Equivalency/Steps/DataTableEquivalencyStep.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System.Collections.Generic; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using FluentAssertions.Data; -using FluentAssertions.Execution; - -namespace FluentAssertions.Equivalency.Steps; - -public class DataTableEquivalencyStep : EquivalencyStep -{ - [SuppressMessage("Style", "IDE0019:Use pattern matching", Justification = "The code is easier to read without it.")] - protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) - { - var subject = comparands.Subject as DataTable; - var expectation = comparands.Expectation as DataTable; - - if (expectation is null) - { - if (subject is not null) - { - AssertionScope.Current.FailWith("Expected {context:DataTable} value to be null, but found {0}", subject); - } - } - else if (subject is null) - { - if (comparands.Subject is null) - { - AssertionScope.Current.FailWith("Expected {context:DataTable} to be non-null, but found null"); - } - else - { - AssertionScope.Current.FailWith("Expected {context:DataTable} to be of type {0}, but found {1} instead", - expectation.GetType(), comparands.Subject.GetType()); - } - } - else - { - var dataSetConfig = context.Options as DataEquivalencyAssertionOptions; - var dataTableConfig = context.Options as DataEquivalencyAssertionOptions; - - if (dataSetConfig?.AllowMismatchedTypes != true - && dataTableConfig?.AllowMismatchedTypes != true) - { - AssertionScope.Current - .ForCondition(subject.GetType() == expectation.GetType()) - .FailWith("Expected {context:DataTable} to be of type {0}{reason}, but found {1}", expectation.GetType(), - subject.GetType()); - } - - var selectedMembers = GetMembersFromExpectation(context.CurrentNode, comparands, context.Options) - .ToDictionary(member => member.Name); - - CompareScalarProperties(subject, expectation, selectedMembers); - - CompareCollections(comparands, context, nestedValidator, context.Options, selectedMembers); - } - - return EquivalencyResult.AssertionCompleted; - } - - [SuppressMessage("Design", "MA0051:Method is too long")] - private static void CompareScalarProperties(DataTable subject, DataTable expectation, - Dictionary selectedMembers) - { - // Note: The members here are listed in the XML documentation for the DataTable.BeEquivalentTo extension - // method in DataTableAssertions.cs. If this ever needs to change, keep them in sync. - if (selectedMembers.ContainsKey(nameof(expectation.TableName))) - { - AssertionScope.Current - .ForCondition(subject.TableName == expectation.TableName) - .FailWith("Expected {context:DataTable} to have TableName {0}{reason}, but found {1} instead", - expectation.TableName, subject.TableName); - } - - if (selectedMembers.ContainsKey(nameof(expectation.CaseSensitive))) - { - AssertionScope.Current - .ForCondition(subject.CaseSensitive == expectation.CaseSensitive) - .FailWith("Expected {context:DataTable} to have CaseSensitive value of {0}{reason}, but found {1} instead", - expectation.CaseSensitive, subject.CaseSensitive); - } - - if (selectedMembers.ContainsKey(nameof(expectation.DisplayExpression))) - { - AssertionScope.Current - .ForCondition(subject.DisplayExpression == expectation.DisplayExpression) - .FailWith("Expected {context:DataTable} to have DisplayExpression value of {0}{reason}, but found {1} instead", - expectation.DisplayExpression, subject.DisplayExpression); - } - - if (selectedMembers.ContainsKey(nameof(expectation.HasErrors))) - { - AssertionScope.Current - .ForCondition(subject.HasErrors == expectation.HasErrors) - .FailWith("Expected {context:DataTable} to have HasErrors value of {0}{reason}, but found {1} instead", - expectation.HasErrors, subject.HasErrors); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Locale))) - { - AssertionScope.Current - .ForCondition(Equals(subject.Locale, expectation.Locale)) - .FailWith("Expected {context:DataTable} to have Locale value of {0}{reason}, but found {1} instead", - expectation.Locale, subject.Locale); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Namespace))) - { - AssertionScope.Current - .ForCondition(subject.Namespace == expectation.Namespace) - .FailWith("Expected {context:DataTable} to have Namespace value of {0}{reason}, but found {1} instead", - expectation.Namespace, subject.Namespace); - } - - if (selectedMembers.ContainsKey(nameof(expectation.Prefix))) - { - AssertionScope.Current - .ForCondition(subject.Prefix == expectation.Prefix) - .FailWith("Expected {context:DataTable} to have Prefix value of {0}{reason}, but found {1} instead", - expectation.Prefix, subject.Prefix); - } - - if (selectedMembers.ContainsKey(nameof(expectation.RemotingFormat))) - { - AssertionScope.Current - .ForCondition(subject.RemotingFormat == expectation.RemotingFormat) - .FailWith("Expected {context:DataTable} to have RemotingFormat value of {0}{reason}, but found {1} instead", - expectation.RemotingFormat, subject.RemotingFormat); - } - } - - private static void CompareCollections(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator parent, IEquivalencyAssertionOptions config, Dictionary selectedMembers) - { - // Note: The collections here are listed in the XML documentation for the DataTable.BeEquivalentTo extension - // method in DataTableAssertions.cs. If this ever needs to change, keep them in sync. - var collectionNames = new[] - { - nameof(DataTable.ChildRelations), - nameof(DataTable.Columns), - nameof(DataTable.Constraints), - nameof(DataTable.ExtendedProperties), - nameof(DataTable.ParentRelations), - nameof(DataTable.PrimaryKey), - nameof(DataTable.Rows), - }; - - foreach (var collectionName in collectionNames) - { - if (selectedMembers.TryGetValue(collectionName, out IMember expectationMember)) - { - IMember matchingMember = FindMatchFor(expectationMember, comparands.Subject, context.CurrentNode, config); - - if (matchingMember is not null) - { - IEquivalencyValidationContext nestedContext = context.AsNestedMember(expectationMember); - - var nestedComparands = new Comparands - { - Subject = matchingMember.GetValue(comparands.Subject), - Expectation = expectationMember.GetValue(comparands.Expectation), - CompileTimeType = expectationMember.Type - }; - - parent.RecursivelyAssertEquality(nestedComparands, nestedContext); - } - } - } - } - - private static IMember FindMatchFor(IMember selectedMemberInfo, object subject, INode currentNode, - IEquivalencyAssertionOptions config) - { - IEnumerable query = - from rule in config.MatchingRules - let match = rule.Match(selectedMemberInfo, subject, currentNode, config) - where match is not null - select match; - - return query.FirstOrDefault(); - } - - private static IEnumerable GetMembersFromExpectation(INode currentNode, Comparands comparands, - IEquivalencyAssertionOptions config) - { - IEnumerable members = Enumerable.Empty(); - - foreach (IMemberSelectionRule rule in config.SelectionRules) - { - members = rule.SelectMembers(currentNode, members, - new MemberSelectionContext(comparands.CompileTimeType, comparands.RuntimeType, config)); - } - - return members; - } -} diff --git a/Src/FluentAssertions/EquivalencyPlan.cs b/Src/FluentAssertions/EquivalencyPlan.cs index cf803c3ab7..e3f176cad2 100644 --- a/Src/FluentAssertions/EquivalencyPlan.cs +++ b/Src/FluentAssertions/EquivalencyPlan.cs @@ -150,17 +150,9 @@ private static List GetDefaultSteps() new AutoConversionStep(), new ReferenceEqualityEquivalencyStep(), new GenericDictionaryEquivalencyStep(), - new DataSetEquivalencyStep(), - new DataTableEquivalencyStep(), - new DataColumnEquivalencyStep(), - new DataRelationEquivalencyStep(), - new DataRowCollectionEquivalencyStep(), - new DataRowEquivalencyStep(), new XDocumentEquivalencyStep(), new XElementEquivalencyStep(), new XAttributeEquivalencyStep(), - new ConstraintCollectionEquivalencyStep(), - new ConstraintEquivalencyStep(), new DictionaryEquivalencyStep(), new MultiDimensionalArrayEquivalencyStep(), new GenericEnumerableEquivalencyStep(), diff --git a/Src/FluentAssertions/FluentAssertions.csproj b/Src/FluentAssertions/FluentAssertions.csproj index 48a22d046e..d8c90190d5 100644 --- a/Src/FluentAssertions/FluentAssertions.csproj +++ b/Src/FluentAssertions/FluentAssertions.csproj @@ -12,7 +12,7 @@ true true - + Dennis Doomen;Jonas Nyrup @@ -31,7 +31,7 @@ See https://fluentassertions.com/releases/ Copyright Dennis Doomen 2010-$([System.DateTime]::Now.ToString(yyyy)) - + <_Parameter1>FluentAssertions.Specs, PublicKey=00240000048000009400000006020000002400005253413100040000010001002d25ff515c85b13ba08f61d466cff5d80a7f28ba197bbf8796085213e7a3406f970d2a4874932fed35db546e89af2da88c194bf1b7f7ac70de7988c78406f7629c547283061282a825616eb7eb48a9514a7570942936020a9bb37dca9ff60b778309900851575614491c6d25018fadb75828f4c7a17bf2d7dc86e7b6eafc5d8f @@ -114,11 +114,10 @@ - - + diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt index 377122900a..df07ccb123 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt @@ -59,10 +59,6 @@ namespace FluentAssertions public static void Should(this FluentAssertions.Types.TypeSelectorAssertions _) { } 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) { } @@ -197,44 +193,6 @@ 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) - where TDataSet : System.Data.DataSet { } - } - public static class DataTableAssertionExtensions - { - 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) @@ -674,84 +632,6 @@ namespace FluentAssertions.Common Scan = 2, } } -namespace FluentAssertions.Data -{ - public class DataColumnAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions - { - public DataColumnAssertions(System.Data.DataColumn dataColumn) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - } - public class DataRowAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataRow : System.Data.DataRow - { - public DataRowAssertions(TDataRow dataRow) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - } - public class DataSetAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataSet : System.Data.DataSet - { - public DataSetAssertions(TDataSet dataSet) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataTable> HaveTable(string expectedTableName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTableCount(int expected, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTables(params string[] expectedTableNames) { } - public FluentAssertions.AndConstraint> HaveTables(System.Collections.Generic.IEnumerable expectedTableNames, string because = "", params object[] becauseArgs) { } - } - public class DataTableAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataTable : System.Data.DataTable - { - public DataTableAssertions(TDataTable dataTable) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveRowCount(int expected, string because = "", params object[] becauseArgs) { } - } - public interface IDataEquivalencyAssertionOptions : FluentAssertions.Equivalency.IEquivalencyAssertionOptions - { - FluentAssertions.Data.IDataEquivalencyAssertionOptions AllowingMismatchedTypes(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> predicate); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(System.Data.DataColumn column); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(string tableName, string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnInAllTables(string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(System.Collections.Generic.IEnumerable columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(params System.Data.DataColumn[] columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingOriginalData(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTable(string tableName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(System.Collections.Generic.IEnumerable tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(params string[] tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions IgnoringUnmatchedColumns(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions UsingRowMatchMode(FluentAssertions.Data.RowMatchMode rowMatchMode); - } - public enum RowMatchMode - { - Index = 0, - PrimaryKey = 1, - } -} namespace FluentAssertions.Equivalency { public class Comparands @@ -1114,46 +994,6 @@ namespace FluentAssertions.Equivalency.Steps public FluentAssertions.Equivalency.EquivalencyResult Handle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } public override string ToString() { } } - public class ConstraintCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class ConstraintEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataColumnEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataColumnEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRelationEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRelationEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataSetEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataSetEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataTableEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataTableEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } public class DictionaryEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep { public DictionaryEquivalencyStep() { } @@ -2801,4 +2641,4 @@ namespace FluentAssertions.Xml public bool CanHandle(object value) { } public void Format(object value, FluentAssertions.Formatting.FormattedObjectGraph formattedGraph, FluentAssertions.Formatting.FormattingContext context, FluentAssertions.Formatting.FormatChild formatChild) { } } -} +} \ No newline at end of file diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt index fa1f44fa66..fa362b74a4 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt @@ -59,10 +59,6 @@ namespace FluentAssertions public static void Should(this FluentAssertions.Types.TypeSelectorAssertions _) { } 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) { } @@ -210,44 +206,6 @@ 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) - where TDataSet : System.Data.DataSet { } - } - public static class DataTableAssertionExtensions - { - 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) @@ -687,84 +645,6 @@ namespace FluentAssertions.Common Scan = 2, } } -namespace FluentAssertions.Data -{ - public class DataColumnAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions - { - public DataColumnAssertions(System.Data.DataColumn dataColumn) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - } - public class DataRowAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataRow : System.Data.DataRow - { - public DataRowAssertions(TDataRow dataRow) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - } - public class DataSetAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataSet : System.Data.DataSet - { - public DataSetAssertions(TDataSet dataSet) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataTable> HaveTable(string expectedTableName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTableCount(int expected, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTables(params string[] expectedTableNames) { } - public FluentAssertions.AndConstraint> HaveTables(System.Collections.Generic.IEnumerable expectedTableNames, string because = "", params object[] becauseArgs) { } - } - public class DataTableAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataTable : System.Data.DataTable - { - public DataTableAssertions(TDataTable dataTable) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveRowCount(int expected, string because = "", params object[] becauseArgs) { } - } - public interface IDataEquivalencyAssertionOptions : FluentAssertions.Equivalency.IEquivalencyAssertionOptions - { - FluentAssertions.Data.IDataEquivalencyAssertionOptions AllowingMismatchedTypes(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> predicate); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(System.Data.DataColumn column); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(string tableName, string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnInAllTables(string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(System.Collections.Generic.IEnumerable columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(params System.Data.DataColumn[] columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingOriginalData(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTable(string tableName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(System.Collections.Generic.IEnumerable tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(params string[] tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions IgnoringUnmatchedColumns(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions UsingRowMatchMode(FluentAssertions.Data.RowMatchMode rowMatchMode); - } - public enum RowMatchMode - { - Index = 0, - PrimaryKey = 1, - } -} namespace FluentAssertions.Equivalency { public class Comparands @@ -1127,46 +1007,6 @@ namespace FluentAssertions.Equivalency.Steps public FluentAssertions.Equivalency.EquivalencyResult Handle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } public override string ToString() { } } - public class ConstraintCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class ConstraintEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataColumnEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataColumnEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRelationEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRelationEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataSetEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataSetEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataTableEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataTableEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } public class DictionaryEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep { public DictionaryEquivalencyStep() { } @@ -2931,4 +2771,4 @@ namespace FluentAssertions.Xml public bool CanHandle(object value) { } public void Format(object value, FluentAssertions.Formatting.FormattedObjectGraph formattedGraph, FluentAssertions.Formatting.FormattingContext context, FluentAssertions.Formatting.FormatChild formatChild) { } } -} +} \ No newline at end of file diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt index 63d5985ea5..4bc84b35de 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt @@ -59,10 +59,6 @@ namespace FluentAssertions public static void Should(this FluentAssertions.Types.TypeSelectorAssertions _) { } 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) { } @@ -197,44 +193,6 @@ 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) - where TDataSet : System.Data.DataSet { } - } - public static class DataTableAssertionExtensions - { - 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) @@ -674,84 +632,6 @@ namespace FluentAssertions.Common Scan = 2, } } -namespace FluentAssertions.Data -{ - public class DataColumnAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions - { - public DataColumnAssertions(System.Data.DataColumn dataColumn) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - } - public class DataRowAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataRow : System.Data.DataRow - { - public DataRowAssertions(TDataRow dataRow) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - } - public class DataSetAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataSet : System.Data.DataSet - { - public DataSetAssertions(TDataSet dataSet) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataTable> HaveTable(string expectedTableName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTableCount(int expected, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTables(params string[] expectedTableNames) { } - public FluentAssertions.AndConstraint> HaveTables(System.Collections.Generic.IEnumerable expectedTableNames, string because = "", params object[] becauseArgs) { } - } - public class DataTableAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataTable : System.Data.DataTable - { - public DataTableAssertions(TDataTable dataTable) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveRowCount(int expected, string because = "", params object[] becauseArgs) { } - } - public interface IDataEquivalencyAssertionOptions : FluentAssertions.Equivalency.IEquivalencyAssertionOptions - { - FluentAssertions.Data.IDataEquivalencyAssertionOptions AllowingMismatchedTypes(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> predicate); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(System.Data.DataColumn column); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(string tableName, string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnInAllTables(string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(System.Collections.Generic.IEnumerable columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(params System.Data.DataColumn[] columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingOriginalData(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTable(string tableName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(System.Collections.Generic.IEnumerable tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(params string[] tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions IgnoringUnmatchedColumns(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions UsingRowMatchMode(FluentAssertions.Data.RowMatchMode rowMatchMode); - } - public enum RowMatchMode - { - Index = 0, - PrimaryKey = 1, - } -} namespace FluentAssertions.Equivalency { public class Comparands @@ -1114,46 +994,6 @@ namespace FluentAssertions.Equivalency.Steps public FluentAssertions.Equivalency.EquivalencyResult Handle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } public override string ToString() { } } - public class ConstraintCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class ConstraintEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataColumnEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataColumnEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRelationEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRelationEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataSetEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataSetEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataTableEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataTableEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } public class DictionaryEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep { public DictionaryEquivalencyStep() { } @@ -2803,4 +2643,4 @@ namespace FluentAssertions.Xml public bool CanHandle(object value) { } public void Format(object value, FluentAssertions.Formatting.FormattedObjectGraph formattedGraph, FluentAssertions.Formatting.FormattingContext context, FluentAssertions.Formatting.FormatChild formatChild) { } } -} +} \ No newline at end of file diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt index 63d5985ea5..4bc84b35de 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt @@ -59,10 +59,6 @@ namespace FluentAssertions public static void Should(this FluentAssertions.Types.TypeSelectorAssertions _) { } 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) { } @@ -197,44 +193,6 @@ 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) - where TDataSet : System.Data.DataSet { } - } - public static class DataTableAssertionExtensions - { - 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) @@ -674,84 +632,6 @@ namespace FluentAssertions.Common Scan = 2, } } -namespace FluentAssertions.Data -{ - public class DataColumnAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions - { - public DataColumnAssertions(System.Data.DataColumn dataColumn) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - } - public class DataRowAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataRow : System.Data.DataRow - { - public DataRowAssertions(TDataRow dataRow) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - } - public class DataSetAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataSet : System.Data.DataSet - { - public DataSetAssertions(TDataSet dataSet) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataTable> HaveTable(string expectedTableName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTableCount(int expected, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTables(params string[] expectedTableNames) { } - public FluentAssertions.AndConstraint> HaveTables(System.Collections.Generic.IEnumerable expectedTableNames, string because = "", params object[] becauseArgs) { } - } - public class DataTableAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataTable : System.Data.DataTable - { - public DataTableAssertions(TDataTable dataTable) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveRowCount(int expected, string because = "", params object[] becauseArgs) { } - } - public interface IDataEquivalencyAssertionOptions : FluentAssertions.Equivalency.IEquivalencyAssertionOptions - { - FluentAssertions.Data.IDataEquivalencyAssertionOptions AllowingMismatchedTypes(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> predicate); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(System.Data.DataColumn column); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(string tableName, string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnInAllTables(string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(System.Collections.Generic.IEnumerable columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(params System.Data.DataColumn[] columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingOriginalData(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTable(string tableName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(System.Collections.Generic.IEnumerable tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(params string[] tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions IgnoringUnmatchedColumns(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions UsingRowMatchMode(FluentAssertions.Data.RowMatchMode rowMatchMode); - } - public enum RowMatchMode - { - Index = 0, - PrimaryKey = 1, - } -} namespace FluentAssertions.Equivalency { public class Comparands @@ -1114,46 +994,6 @@ namespace FluentAssertions.Equivalency.Steps public FluentAssertions.Equivalency.EquivalencyResult Handle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } public override string ToString() { } } - public class ConstraintCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class ConstraintEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataColumnEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataColumnEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRelationEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRelationEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataSetEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataSetEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataTableEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataTableEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } public class DictionaryEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep { public DictionaryEquivalencyStep() { } @@ -2803,4 +2643,4 @@ namespace FluentAssertions.Xml public bool CanHandle(object value) { } public void Format(object value, FluentAssertions.Formatting.FormattedObjectGraph formattedGraph, FluentAssertions.Formatting.FormattingContext context, FluentAssertions.Formatting.FormatChild formatChild) { } } -} +} \ No newline at end of file diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt index 33bdb75873..40554f2caf 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt @@ -58,10 +58,6 @@ namespace FluentAssertions public static void Should(this FluentAssertions.Types.TypeSelectorAssertions _) { } 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) { } @@ -196,44 +192,6 @@ 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) - where TDataSet : System.Data.DataSet { } - } - public static class DataTableAssertionExtensions - { - 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) @@ -667,84 +625,6 @@ namespace FluentAssertions.Common Scan = 2, } } -namespace FluentAssertions.Data -{ - public class DataColumnAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions - { - public DataColumnAssertions(System.Data.DataColumn dataColumn) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - } - public class DataRowAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataRow : System.Data.DataRow - { - public DataRowAssertions(TDataRow dataRow) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - } - public class DataSetAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataSet : System.Data.DataSet - { - public DataSetAssertions(TDataSet dataSet) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataTable> HaveTable(string expectedTableName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTableCount(int expected, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTables(params string[] expectedTableNames) { } - public FluentAssertions.AndConstraint> HaveTables(System.Collections.Generic.IEnumerable expectedTableNames, string because = "", params object[] becauseArgs) { } - } - public class DataTableAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataTable : System.Data.DataTable - { - public DataTableAssertions(TDataTable dataTable) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveRowCount(int expected, string because = "", params object[] becauseArgs) { } - } - public interface IDataEquivalencyAssertionOptions : FluentAssertions.Equivalency.IEquivalencyAssertionOptions - { - FluentAssertions.Data.IDataEquivalencyAssertionOptions AllowingMismatchedTypes(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> predicate); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(System.Data.DataColumn column); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(string tableName, string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnInAllTables(string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(System.Collections.Generic.IEnumerable columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(params System.Data.DataColumn[] columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingOriginalData(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTable(string tableName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(System.Collections.Generic.IEnumerable tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(params string[] tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions IgnoringUnmatchedColumns(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions UsingRowMatchMode(FluentAssertions.Data.RowMatchMode rowMatchMode); - } - public enum RowMatchMode - { - Index = 0, - PrimaryKey = 1, - } -} namespace FluentAssertions.Equivalency { public class Comparands @@ -1107,46 +987,6 @@ namespace FluentAssertions.Equivalency.Steps public FluentAssertions.Equivalency.EquivalencyResult Handle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } public override string ToString() { } } - public class ConstraintCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class ConstraintEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataColumnEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataColumnEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRelationEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRelationEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataSetEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataSetEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataTableEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataTableEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } public class DictionaryEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep { public DictionaryEquivalencyStep() { } @@ -2752,4 +2592,4 @@ namespace FluentAssertions.Xml public bool CanHandle(object value) { } public void Format(object value, FluentAssertions.Formatting.FormattedObjectGraph formattedGraph, FluentAssertions.Formatting.FormattingContext context, FluentAssertions.Formatting.FormatChild formatChild) { } } -} +} \ No newline at end of file diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt index 63d5985ea5..4bc84b35de 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt @@ -59,10 +59,6 @@ namespace FluentAssertions public static void Should(this FluentAssertions.Types.TypeSelectorAssertions _) { } 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) { } @@ -197,44 +193,6 @@ 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) - where TDataSet : System.Data.DataSet { } - } - public static class DataTableAssertionExtensions - { - 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) @@ -674,84 +632,6 @@ namespace FluentAssertions.Common Scan = 2, } } -namespace FluentAssertions.Data -{ - public class DataColumnAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions - { - public DataColumnAssertions(System.Data.DataColumn dataColumn) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint BeEquivalentTo(System.Data.DataColumn expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - } - public class DataRowAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataRow : System.Data.DataRow - { - public DataRowAssertions(TDataRow dataRow) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataRow expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - } - public class DataSetAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataSet : System.Data.DataSet - { - public DataSetAssertions(TDataSet dataSet) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataSet expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataTable> HaveTable(string expectedTableName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTableCount(int expected, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveTables(params string[] expectedTableNames) { } - public FluentAssertions.AndConstraint> HaveTables(System.Collections.Generic.IEnumerable expectedTableNames, string because = "", params object[] becauseArgs) { } - } - public class DataTableAssertions : FluentAssertions.Primitives.ReferenceTypeAssertions> - where TDataTable : System.Data.DataTable - { - public DataTableAssertions(TDataTable dataTable) { } - protected override string Identifier { get; } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> BeEquivalentTo(System.Data.DataTable expectation, System.Func, FluentAssertions.Data.IDataEquivalencyAssertionOptions> config, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndWhichConstraint, System.Data.DataColumn> HaveColumn(string expectedColumnName, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveColumns(params string[] expectedColumnNames) { } - public FluentAssertions.AndConstraint> HaveColumns(System.Collections.Generic.IEnumerable expectedColumnNames, string because = "", params object[] becauseArgs) { } - public FluentAssertions.AndConstraint> HaveRowCount(int expected, string because = "", params object[] becauseArgs) { } - } - public interface IDataEquivalencyAssertionOptions : FluentAssertions.Equivalency.IEquivalencyAssertionOptions - { - FluentAssertions.Data.IDataEquivalencyAssertionOptions AllowingMismatchedTypes(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> predicate); - FluentAssertions.Data.IDataEquivalencyAssertionOptions Excluding(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(System.Data.DataColumn column); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumn(string tableName, string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnInAllTables(string columnName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(System.Collections.Generic.IEnumerable columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(params System.Data.DataColumn[] columns); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumns(string tableName, params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(System.Collections.Generic.IEnumerable columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingColumnsInAllTables(params string[] columnNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingOriginalData(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingRelated(System.Linq.Expressions.Expression> expression); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTable(string tableName); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(System.Collections.Generic.IEnumerable tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions ExcludingTables(params string[] tableNames); - FluentAssertions.Data.IDataEquivalencyAssertionOptions IgnoringUnmatchedColumns(); - FluentAssertions.Data.IDataEquivalencyAssertionOptions UsingRowMatchMode(FluentAssertions.Data.RowMatchMode rowMatchMode); - } - public enum RowMatchMode - { - Index = 0, - PrimaryKey = 1, - } -} namespace FluentAssertions.Equivalency { public class Comparands @@ -1114,46 +994,6 @@ namespace FluentAssertions.Equivalency.Steps public FluentAssertions.Equivalency.EquivalencyResult Handle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } public override string ToString() { } } - public class ConstraintCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class ConstraintEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public ConstraintEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataColumnEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataColumnEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRelationEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRelationEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowCollectionEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowCollectionEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataRowEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataRowEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataSetEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataSetEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } - public class DataTableEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep - { - public DataTableEquivalencyStep() { } - protected override FluentAssertions.Equivalency.EquivalencyResult OnHandle(FluentAssertions.Equivalency.Comparands comparands, FluentAssertions.Equivalency.IEquivalencyValidationContext context, FluentAssertions.Equivalency.IEquivalencyValidator nestedValidator) { } - } public class DictionaryEquivalencyStep : FluentAssertions.Equivalency.EquivalencyStep { public DictionaryEquivalencyStep() { } @@ -2803,4 +2643,4 @@ namespace FluentAssertions.Xml public bool CanHandle(object value) { } public void Format(object value, FluentAssertions.Formatting.FormattedObjectGraph formattedGraph, FluentAssertions.Formatting.FormattingContext context, FluentAssertions.Formatting.FormatChild formatChild) { } } -} +} \ No newline at end of file diff --git a/Tests/Benchmarks/Benchmarks.csproj b/Tests/Benchmarks/Benchmarks.csproj index 6cc9eed47e..bbf0f36168 100644 --- a/Tests/Benchmarks/Benchmarks.csproj +++ b/Tests/Benchmarks/Benchmarks.csproj @@ -14,7 +14,6 @@ - diff --git a/Tests/Benchmarks/LargeDataTableEquivalency.cs b/Tests/Benchmarks/LargeDataTableEquivalency.cs deleted file mode 100644 index ff4b0f9455..0000000000 --- a/Tests/Benchmarks/LargeDataTableEquivalency.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using System.Data; -using System.Linq; -using BenchmarkDotNet.Attributes; -using Bogus; -using FluentAssertions; -using FluentAssertions.Data; - -namespace Benchmarks; - -[MemoryDiagnoser] -public class LargeDataTableEquivalencyBenchmarks -{ - private DataTable dataTable1; - private DataTable dataTable2; - - [Params(10, 100, 1_000, 10_000, 100_000)] - public int RowCount { get; set; } - - [GlobalSetup] - public void GlobalSetup() - { - dataTable1 = CreateDataTable(); - dataTable2 = CreateDataTable(); - - object[] rowData = new object[dataTable1.Columns.Count]; - - var faker = new Faker - { - Random = new Randomizer(localSeed: 1) - }; - - for (int i = 0; i < RowCount; i++) - { - for (int j = 0; j < dataTable1.Columns.Count; j++) - { - Type columnType = dataTable1.Columns[j].DataType; - rowData[j] = GetData(faker, columnType); - } - - dataTable1.Rows.Add(rowData); - dataTable2.Rows.Add(rowData); - } - } - - private static object GetData(Faker faker, Type columnType) - { - return Type.GetTypeCode(columnType) switch - { - TypeCode.Empty or TypeCode.DBNull => null, - TypeCode.Boolean => faker.Random.Bool(), - TypeCode.Char => faker.Lorem.Letter().Single(), - TypeCode.SByte => faker.Random.SByte(), - TypeCode.Byte => faker.Random.Byte(), - TypeCode.Int16 => faker.Random.Short(), - TypeCode.UInt16 => faker.Random.UShort(), - TypeCode.Int32 => faker.Random.Int(), - TypeCode.UInt32 => faker.Random.UInt(), - TypeCode.Int64 => faker.Random.Long(), - TypeCode.UInt64 => faker.Random.ULong(), - TypeCode.Single => faker.Random.Float(), - TypeCode.Double => faker.Random.Double(), - TypeCode.Decimal => faker.Random.Decimal(), - TypeCode.DateTime => faker.Date.Between(DateTime.UtcNow.AddDays(-30), DateTime.UtcNow.AddDays(+30)), - TypeCode.String => faker.Lorem.Lines(1), - _ => GetDefault(faker, columnType), - }; - } - - private static object GetDefault(Faker faker, Type columnType) - { - if (columnType == typeof(TimeSpan)) - { - return faker.Date.Future() - faker.Date.Future(); - } - else if (columnType == typeof(Guid)) - { - return faker.Random.Guid(); - } - - throw new Exception("Unable to populate column of type " + columnType); - } - - private static DataTable CreateDataTable() - { - var table = new DataTable("Test"); - - table.Columns.Add("A", typeof(bool)); - table.Columns.Add("B", typeof(char)); - table.Columns.Add("C", typeof(sbyte)); - table.Columns.Add("D", typeof(byte)); - table.Columns.Add("E", typeof(short)); - table.Columns.Add("F", typeof(ushort)); - table.Columns.Add("G", typeof(int)); - table.Columns.Add("H", typeof(uint)); - table.Columns.Add("I", typeof(long)); - table.Columns.Add("J", typeof(ulong)); - table.Columns.Add("K", typeof(float)); - table.Columns.Add("L", typeof(double)); - table.Columns.Add("M", typeof(decimal)); - table.Columns.Add("N", typeof(DateTime)); - table.Columns.Add("O", typeof(string)); - table.Columns.Add("P", typeof(TimeSpan)); - table.Columns.Add("Q", typeof(Guid)); - - return table; - } - - [Benchmark] - public AndConstraint> BeEquivalentTo() => dataTable1.Should().BeEquivalentTo(dataTable2); -} diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs deleted file mode 100644 index bc6481daeb..0000000000 --- a/Tests/FluentAssertions.Equivalency.Specs/DataColumnSpecs.cs +++ /dev/null @@ -1,785 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using Xunit; -using Xunit.Sdk; - -namespace FluentAssertions.Equivalency.Specs; - -public class DataColumnSpecs : DataSpecs -{ - [Fact] - public void When_DataColumns_are_identical_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act & Assert - dataTable1.RowIDColumn.Should().BeEquivalentTo(dataTable2.RowIDColumn); - } - - [Fact] - public void When_DataColumns_are_both_null_it_should_succeed() - { - // Act & Assert - ((DataColumn)null).Should().BeEquivalentTo(null); - } - - [Fact] - public void When_DataColumn_is_null_and_isnt_expected_to_be_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - // Act - Action action = () => ((DataColumn)null).Should().BeEquivalentTo(dataTable.RowIDColumn); - - // Assert - action.Should().Throw().WithMessage( - "Expected *to be non-null, but found null*"); - } - - [Fact] - public void When_DataColumn_is_expected_to_be_null_and_isnt_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - // Act - Action action = () => dataTable.RowIDColumn.Should().BeEquivalentTo(null); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DataColumn_has_changes_but_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Unique = true; - dataColumn2.Caption = "Test"; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .ExcludingColumn(dataColumn2)); - } - - [Fact] - public void Can_exclude_a_column_from_all_tables() - { - // Arrange - var subjectDataSet = CreateDummyDataSet(); - var expectationDataSet = new TypedDataSetSubclass(subjectDataSet); - - var subject = subjectDataSet.TypedDataTable1.DecimalColumn; - var expectation = expectationDataSet.TypedDataTable1.DecimalColumn; - - expectation.Unique = true; - expectation.Caption = "Test"; - - // Act & Assert - subject.Should().BeEquivalentTo(expectation, options => options - .ExcludingColumnInAllTables(expectation.ColumnName)); - } - - [Fact] - public void When_DataColumn_has_changes_but_is_excluded_as_params_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Unique = true; - dataColumn2.Caption = "Test"; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .ExcludingColumns(dataColumn2)); - } - - [Fact] - public void When_DataColumn_has_changes_but_is_excluded_as_enumerable_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Unique = true; - dataColumn2.Caption = "Test"; - - // Act & Assert - IEnumerable excludedColumns = new[] { dataColumn2 }; - - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .ExcludingColumns(excludedColumns)); - } - - [Fact] - public void When_DataColumn_has_changes_but_is_excluded_it_should_succeed_when_compared_via_DataTable() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.DecimalColumn.Unique = true; - dataTable2.DecimalColumn.Caption = "Test"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .ExcludingColumn(dataTable2.DecimalColumn) - .ExcludingRelated(dataTable => dataTable.Constraints)); - } - - [Fact] - public void When_DataColumn_has_changes_but_is_excluded_it_should_succeed_when_compared_via_DataSet() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.DecimalColumn.Unique = true; - dataTable2.DecimalColumn.Caption = "Test"; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .ExcludingColumn(dataTable2.DecimalColumn) - .ExcludingRelated(dataTable => dataTable.Constraints)); - } - - [Fact] - public void When_ColumnName_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.ColumnName += "different"; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_ColumnName_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.ColumnName += "different"; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.ColumnName) - .Excluding(dataColumn => dataColumn.Caption)); - } - - [Fact] - public void When_AllowDBNull_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.AllowDBNull = !dataColumn2.AllowDBNull; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_AllowDBNull_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.AllowDBNull = !dataColumn2.AllowDBNull; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.AllowDBNull)); - } - - [Fact] - public void When_AutoIncrement_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.AutoIncrement = !dataColumn2.AutoIncrement; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_AutoIncrement_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.AutoIncrement = !dataColumn2.AutoIncrement; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.AutoIncrement)); - } - - [Fact] - public void When_AutoIncrementSeed_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.AutoIncrementSeed++; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_AutoIncrementSeed_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.AutoIncrementSeed++; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.AutoIncrementSeed)); - } - - [Fact] - public void When_AutoIncrementStep_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.AutoIncrementStep++; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_AutoIncrementStep_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.AutoIncrementStep++; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.AutoIncrementStep)); - } - - [Fact] - public void When_Caption_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Caption += "different"; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Caption_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Caption += "different"; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.Caption)); - } - - [Fact] - public void When_DataType_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(includeDummyData: false); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable2.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable2.DecimalColumn; - - dataColumn2.DataType = typeof(double); - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DataType_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(includeDummyData: false); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable2.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable2.DecimalColumn; - - dataColumn2.DataType = typeof(double); - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.DataType)); - } - - [Fact] - public void When_DateTimeMode_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(includeDummyData: false); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable2.DateTimeColumn; - var dataColumn2 = dataSet2.TypedDataTable2.DateTimeColumn; - - dataColumn2.DateTimeMode = - dataColumn2.DateTimeMode == DataSetDateTime.Local - ? DataSetDateTime.Utc - : DataSetDateTime.Local; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DateTimeMode_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(includeDummyData: false); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable2.DateTimeColumn; - var dataColumn2 = dataSet2.TypedDataTable2.DateTimeColumn; - - dataColumn2.DateTimeMode = - dataColumn2.DateTimeMode == DataSetDateTime.Local - ? DataSetDateTime.Utc - : DataSetDateTime.Local; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.DateTimeMode)); - } - - [Fact] - public void When_DefaultValue_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.DefaultValue = 10M; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DefaultValue_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.DefaultValue = 10M; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.DefaultValue)); - } - - [Fact] - public void When_Expression_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Expression = "RowID"; - - // Act - Action action = () => - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.ReadOnly)); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Expression_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Expression = "RowID"; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.Expression) - .Excluding(dataColumn => dataColumn.ReadOnly)); - } - - [Fact] - public void When_MaxLength_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.StringColumn; - var dataColumn2 = dataSet2.TypedDataTable1.StringColumn; - - dataColumn2.MaxLength = 250; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_MaxLength_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.StringColumn; - var dataColumn2 = dataSet2.TypedDataTable1.StringColumn; - - dataColumn2.MaxLength = 250; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.MaxLength)); - } - - [Fact] - public void When_Namespace_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Namespace += "different"; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Namespace_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Namespace += "different"; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.Namespace)); - } - - [Fact] - public void When_Prefix_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Prefix += "different"; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Prefix_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Prefix += "different"; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.Prefix)); - } - - [Fact] - public void When_ReadOnly_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.ReadOnly = !dataColumn2.ReadOnly; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_ReadOnly_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.ReadOnly = !dataColumn2.ReadOnly; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.ReadOnly)); - } - - [Fact] - public void When_Unique_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Unique = !dataColumn2.Unique; - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Unique_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataColumn1 = dataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = dataSet2.TypedDataTable1.DecimalColumn; - - dataColumn2.Unique = !dataColumn2.Unique; - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, options => options - .Excluding(dataColumn => dataColumn.Unique)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_ExtendedProperties_do_not_match_and_property_is_not_excluded_it_should_fail(ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataColumn1 = typedDataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = typedDataSet2.TypedDataTable1.DecimalColumn; - - ApplyChange(dataColumn2.ExtendedProperties, changeType); - - // Act - Action action = () => dataColumn1.Should().BeEquivalentTo(dataColumn2); - - // Assert - action.Should().Throw(); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_ExtendedProperties_do_not_match_and_property_is_excluded_it_should_succeed(ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataColumn1 = typedDataSet1.TypedDataTable1.DecimalColumn; - var dataColumn2 = typedDataSet2.TypedDataTable1.DecimalColumn; - - ApplyChange(dataColumn2.ExtendedProperties, changeType); - - // Act & Assert - dataColumn1.Should().BeEquivalentTo(dataColumn2, - options => options.Excluding(dataColumn => dataColumn.ExtendedProperties)); - } - - [Fact] - public void Data_column_is_not_equivalent_to_another_type() - { - // Arrange - var subject = new - { - DataColumn = "foobar" - }; - - var expected = new - { - DataColumn = new DataColumn() - }; - - // Act - Action act = () => subject.Should().BeEquivalentTo(expected); - - // Assert - act.Should().Throw() - .WithMessage("Expected*System.Data.DataColumn*found System.String*"); - } -} diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs deleted file mode 100644 index 62ee3276dd..0000000000 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRelationSpecs.cs +++ /dev/null @@ -1,353 +0,0 @@ -using System; -using System.Data; -using Xunit; -using Xunit.Sdk; - -namespace FluentAssertions.Equivalency.Specs; - -public class DataRelationSpecs : DataSpecs -{ - [Fact] - public void When_RelationName_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataSet2.Relations[0].RelationName += "different"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_RelationName_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataSet2.Relations[0].RelationName += "different"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo( - dataTable2, - options => options - .ExcludingRelated(dataRelation => dataRelation.RelationName)); - } - - [Fact] - public void When_Nested_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataSet2.Relations[0].Nested = !dataSet2.Relations[0].Nested; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Nested_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataSet2.Relations[0].Nested = !dataSet2.Relations[0].Nested; - - // Act & Assert - dataTable1.Should().BeEquivalentTo( - dataTable2, - options => options - .ExcludingRelated(dataRelation => dataRelation.Nested)); - } - - [Fact] - public void When_DataSet_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataSet2.DataSetName += "different"; - - // Act - Action action = () => - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.DataSet)); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DataSet_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(identicalTables: true); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataSet2.DataSetName += "different"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo( - dataTable2, - options => options - .Excluding(dataTable => dataTable.DataSet) - .ExcludingRelated((DataRelation dataRelation) => dataRelation.DataSet)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_ExtendedProperties_do_not_match_and_property_is_not_excluded_it_should_fail(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.ChildRelations[0].ExtendedProperties, changeType); - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_ExtendedProperties_do_not_match_and_property_is_excluded_it_should_succeed(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.ChildRelations[0].ExtendedProperties, changeType); - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .ExcludingRelated((DataRelation dataRelation) => dataRelation.ExtendedProperties)); - } - - [Fact] - public void When_ParentColumns_do_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - dataSet2.TypedDataTable1.RowIDColumn.ColumnName += "different"; - - // Act - Action action = () => - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.ChildRelations) - .Excluding(dataTable => dataTable.Constraints)); - - // Assert - action.Should().Throw().Which.Message.Should() - .Contain(dataSet2.TypedDataTable1.Columns[0].ColumnName); - } - - [Fact] - public void When_ParentColumns_do_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - dataSet2.TypedDataTable1.RowIDColumn.ColumnName += "different"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.ChildRelations) - .Excluding(dataTable => dataTable.Constraints) - .ExcludingRelated(dataRelation => dataRelation.ParentColumns) - .ExcludingRelated(dataRelation => dataRelation.ParentKeyConstraint) - .ExcludingRelated(dataRelation => dataRelation.ChildKeyConstraint)); - } - - [Fact] - public void When_ChildColumns_do_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataSet2.TypedDataTable2.ForeignRowIDColumn.ColumnName += "different"; - - // Act - Action action = () => - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.ParentRelations) - .Excluding(dataTable => dataTable.Constraints)); - - // Assert - action.Should().Throw().Which.Message.Should() - .Contain(dataSet2.TypedDataTable1.Columns[0].ColumnName); - } - - [Fact] - public void When_ChildColumns_do_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataSet2.TypedDataTable2.ForeignRowIDColumn.ColumnName += "different"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.ParentRelations) - .Excluding(dataTable => dataTable.Constraints) - .ExcludingRelated(dataRelation => dataRelation.ChildColumns) - .ExcludingRelated(dataRelation => dataRelation.ParentKeyConstraint) - .ExcludingRelated(dataRelation => dataRelation.ChildKeyConstraint)); - } - - [Fact] - public void Data_relation_is_not_equivalent_to_another_type() - { - // Arrange - var dataSet = new DataSet(); - var table = new DataTable(); - var col1 = new DataColumn(); - var col2 = new DataColumn(); - - table.Columns.Add(col1); - table.Columns.Add(col2); - - dataSet.Tables.Add(table); - - var subject = new - { - DataRelation = "foobar" - }; - - var expected = new - { - DataRelation = new DataRelation("bar", col1, col2) - }; - - // Act - Action act = () => subject.Should().BeEquivalentTo(expected); - - // Assert - act.Should().Throw() - .WithMessage("Expected*System.Data.DataRelation*found System.String*"); - } - - [Fact] - public void Null_is_not_equivalent_to_a_data_relation() - { - // Arrange - var dataSet = new DataSet(); - var table = new DataTable(); - var col1 = new DataColumn(); - var col2 = new DataColumn(); - - table.Columns.Add(col1); - table.Columns.Add(col2); - - dataSet.Tables.Add(table); - - var subject = new - { - DataRelation = (DataRelation)null - }; - - var expected = new - { - DataRelation = new DataRelation("bar", col1, col2) - }; - - // Act - Action act = () => subject.Should().BeEquivalentTo(expected); - - // Assert - act.Should().Throw() - .WithMessage("Expected *value to be non-null, but found*"); - } - - [Fact] - public void Data_relation_is_not_equivalent_to_null() - { - // Arrange - var dataSet = new DataSet(); - var table = new DataTable(); - var col1 = new DataColumn(); - var col2 = new DataColumn(); - - table.Columns.Add(col1); - table.Columns.Add(col2); - - dataSet.Tables.Add(table); - - var subject = new - { - DataRelation = new DataRelation("bar", col1, col2) - }; - - var expected = new - { - DataRelation = (DataRelation)null - }; - - // Act - Action act = () => subject.Should().BeEquivalentTo(expected); - - // Assert - act.Should().Throw() - .WithMessage("Expected *to be null, but found*"); - } -} diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs deleted file mode 100644 index 6e561ded69..0000000000 --- a/Tests/FluentAssertions.Equivalency.Specs/DataRowSpecs.cs +++ /dev/null @@ -1,530 +0,0 @@ -using System; -using System.Data; -using System.Linq; -using FluentAssertions.Execution; -using Xunit; -using Xunit.Sdk; - -namespace FluentAssertions.Equivalency.Specs; - -public class DataRowSpecs : DataSpecs -{ - [Fact] - public void When_data_rows_are_identical_equivalency_test_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act & Assert - dataTable1[0].Should().BeEquivalentTo(dataTable2[0]); - } - - [Fact] - public void When_data_rows_are_both_null_equivalency_test_should_succeed() - { - // Act & Assert - ((DataRow)null).Should().BeEquivalentTo(null); - } - - [Fact] - public void When_data_row_is_null_and_isnt_expected_to_be_then_equivalency_test_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - // Act - Action action = () => ((DataRow)null).Should().BeEquivalentTo(dataTable[0]); - - // Assert - action.Should().Throw().WithMessage( - "Expected *to be non-null, but found null*"); - } - - [Fact] - public void When_data_row_is_expected_to_be_null_and_isnt_then_equivalency_test_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - // Act - Action action = () => dataTable[0].Should().BeEquivalentTo(null); - - // Assert - action.Should().Throw().WithMessage("Expected dataTable[0] value to be null, but found *"); - } - - [Fact] - public void - When_data_row_subject_is_deleted_and_expectation_is_not_but_the_row_state_is_excluded_equivalency_test_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - var dataRow1 = dataTable1[0]; - var dataRow2 = dataTable2[0]; - - dataRow1.Delete(); - - // Act & Assert - dataRow1.Should().BeEquivalentTo(dataRow2, config => config - .Excluding(row => row.RowState)); - } - - [Fact] - public void - When_data_row_expectation_is_deleted_and_subject_is_not_but_the_row_state_is_excluded_equivalency_test_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - var dataRow1 = dataTable1[0]; - var dataRow2 = dataTable2[0]; - - dataRow2.Delete(); - - // Act & Assert - dataRow1.Should().BeEquivalentTo(dataRow2, config => config - .Excluding(row => row.RowState)); - } - - [Fact] - public void When_data_row_is_deleted_equivalency_test_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - var dataRow1 = dataTable1[0]; - var dataRow2 = dataTable2[0]; - - dataRow1.Delete(); - dataRow2.Delete(); - - // Act & Assert - dataRow1.Should().BeEquivalentTo(dataRow2); - } - - [Fact] - public void When_data_row_is_modified_and_original_data_differs_equivalency_test_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - var dataRow1 = dataTable1[0]; - var dataRow2 = dataTable2[0]; - - dataRow1.Decimal++; - dataTable1.AcceptChanges(); - dataRow1.Decimal--; - - dataRow2.Decimal--; - dataTable2.AcceptChanges(); - dataRow2.Decimal++; - - // Act - Action action = () => dataRow1.Should().BeEquivalentTo(dataRow2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataRow1[Decimal, DataRowVersion.Original] to be *, but found *"); - } - - [Fact] - public void - When_data_row_is_modified_and_original_data_differs_but_original_data_is_excluded_then_equivalency_test_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - var dataRow1 = dataTable1[0]; - var dataRow2 = dataTable2[0]; - - // Set the Decimal property to be the same for both rows, but by doing ++ and -- in - // different orders, the AcceptChanges call will load different values into the - // original data for each row. - dataRow1.Decimal++; - dataTable1.AcceptChanges(); - dataRow1.Decimal--; - - dataRow2.Decimal--; - dataTable2.AcceptChanges(); - dataRow2.Decimal++; - - // Act & Assert - dataRow1.Should().BeEquivalentTo(dataRow2, config => config - .ExcludingOriginalData()); - } - - [Fact] - public void When_data_row_type_does_not_match_and_mismatched_types_are_not_allowed_then_equivalency_test_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(identicalTables: true); - var dataSet2 = new TypedDataSetSubclass(dataSet); - - var dataTable = dataSet.TypedDataTable1; - var dataTableOfMismatchedType = dataSet2.TypedDataTable2; - - dataSet2.Tables.Remove(dataTable.TableName); - dataTableOfMismatchedType.TableName = dataTable.TableName; - - // Act - Action action = () => dataTable[0].Should().BeEquivalentTo(dataTableOfMismatchedType[0]); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable[0] to be of type *TypedDataRow2, but found *TypedDataRow1*"); - } - - [Fact] - public void When_data_row_type_does_not_match_but_mismatched_types_are_allowed_then_equivalency_test_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(identicalTables: true); - var dataSet2 = new TypedDataSetSubclass(dataSet); - - var dataTable = dataSet.TypedDataTable1; - var dataTableOfMismatchedType = dataSet2.TypedDataTable2; - - dataSet2.Tables.Remove(dataTable.TableName); - dataTableOfMismatchedType.TableName = dataTable.TableName; - - // Act & Assert - dataTable[0].Should().BeEquivalentTo(dataTableOfMismatchedType[0], options => options.AllowingMismatchedTypes()); - } - - [Fact] - public void - When_one_data_row_has_errors_and_the_other_does_not_and_the_corresponding_property_is_not_excluded_then_equivalency_test_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataRow1 = dataSet1.TypedDataTable1[0]; - var dataRow2 = dataSet2.TypedDataTable1[0]; - - dataRow2.RowError = "Manually added error"; - - // Act - Action action = () => dataRow1.Should().BeEquivalentTo(dataRow2); - - // Assert - action.Should().Throw().Which.Message.Should().Contain("HasErrors"); - } - - [Fact] - public void - When_one_data_row_has_errors_and_the_other_does_not_but_the_corresponding_property_is_excluded_then_equivalency_test_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataRow1 = dataSet1.TypedDataTable1[0]; - var dataRow2 = dataSet2.TypedDataTable1[0]; - - dataRow2.RowError = "Manually added error"; - - // Act & Assert - dataRow1.Should().BeEquivalentTo(dataRow2, config => config.Excluding(dataRow => dataRow.HasErrors)); - } - - [Fact] - public void - When_the_data_row_state_does_not_match_and_the_corresponding_property_is_not_excluded_equivalency_test_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataRow1 = dataSet1.TypedDataTable1[0]; - var dataRow2 = dataSet2.TypedDataTable1[0]; - - dataRow1.DateTime = DateTime.UtcNow; - dataRow2.DateTime = dataRow1.DateTime; - - dataSet2.AcceptChanges(); - - // Act - Action action = () => dataRow1.Should().BeEquivalentTo(dataRow2); - - // Assert - action.Should().Throw().Which.Message.Should().Contain("RowState"); - } - - [Fact] - public void - When_the_data_row_state_does_not_match_but_the_corresponding_property_is_excluded_equivalency_test_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataRow1 = dataSet1.TypedDataTable1[0]; - var dataRow2 = dataSet2.TypedDataTable1[0]; - - dataRow1.DateTime = DateTime.UtcNow; - dataRow2.DateTime = dataRow1.DateTime; - - dataSet2.AcceptChanges(); - - // Act & Assert - dataRow1.Should().BeEquivalentTo(dataRow2, config => config.Excluding(dataRow => dataRow.RowState)); - } - - [Fact] - public void When_data_row_data_does_not_match_and_the_column_in_question_is_not_excluded_then_equivalency_test_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataRow1 = dataSet1.TypedDataTable1[0]; - var dataRow2 = dataSet2.TypedDataTable1[0]; - - dataRow2.String = Guid.NewGuid().ToString(); - dataSet2.AcceptChanges(); - - // Act - Action action = () => dataRow1.Should().BeEquivalentTo(dataRow2); - - // Assert - action.Should().Throw().Which.Message.Should().Contain(dataRow2.String); - } - - [Fact] - public void When_data_row_data_does_not_match_but_the_column_is_excluded_then_equivalency_test_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataRow1 = dataSet1.TypedDataTable1[0]; - var dataRow2 = dataSet2.TypedDataTable1[0]; - - dataRow2.DateTime = DateTime.UtcNow; - dataSet2.AcceptChanges(); - - // Act & Assert - dataRow1.Should().BeEquivalentTo(dataRow2, config => config.ExcludingColumn(dataSet2.TypedDataTable1.DateTimeColumn)); - } - - [Fact] - public void Data_row_is_not_equivalent_to_another_type() - { - // Arrange - var table = new DataTable(); - var dataRow = table.NewRow(); - - var subject = new - { - DataRow = "foobar" - }; - - var expected = new - { - DataRow = dataRow - }; - - // Act - Action act = () => subject.Should().BeEquivalentTo(expected); - - // Assert - act.Should().Throw() - .WithMessage("Expected*System.Data.DataRow*found System.String*"); - } - - [Fact] - public void Any_type_is_not_equivalent_to_data_row_colletion() - { - // Arrange - var o = new object(); - - // Act - Action act = () => o.Should().BeEquivalentTo((DataRowCollection)null); - - // Assert - act.Should().Throw() - .WithMessage("Expected* to be of type DataRowCollection, but found*"); - } - - [Fact] - public void When_data_row_has_column_then_asserting_that_it_has_that_column_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataRow = dataSet.TypedDataTable1[0]; - - string expectedColumnName = dataSet.TypedDataTable1.Columns.Cast().Last().ColumnName; - - // Act & Assert - dataRow.Should().HaveColumn(expectedColumnName); - } - - [Fact] - public void When_data_row_does_not_have_column_then_asserting_that_it_has_that_column_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataRow = dataSet.TypedDataTable1[0]; - - // Act - Action action = - () => dataRow.Should().HaveColumn("Unicorn"); - - // Assert - action.Should().Throw().WithMessage("Expected dataRow to contain a column named *Unicorn*"); - } - - [Fact] - public void Null_data_row_does_not_have_column() - { - // Arrange - var dataRow = (DataRow)null; - - // Act - Action action = - () => dataRow.Should().HaveColumn("Does not matter"); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataRow to contain a column named *Does not matter*, but found *"); - } - - [Fact] - public void When_data_row_data_has_all_columns_being_asserted_then_it_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataRow = dataSet.TypedDataTable1[0]; - - var subsetOfColumnNames = dataRow.Table.Columns.Cast() - .Take(dataRow.Table.Columns.Count - 2) - .Select(column => column.ColumnName); - - // Act & Assert - dataRow.Should().HaveColumns(subsetOfColumnNames); - } - - [Fact] - public void Data_row_with_all_colums_asserted_and_using_the_array_overload_passes() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataRow = dataSet.TypedDataTable1[0]; - - string[] subsetOfColumnNames = dataRow.Table.Columns.Cast() - .Take(dataRow.Table.Columns.Count - 2) - .Select(column => column.ColumnName) - .ToArray(); - - // Act & Assert - dataRow.Should().HaveColumns(subsetOfColumnNames); - } - - [Fact] - public void Null_data_row_and_using_the_array_overload_fails() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataRow = dataSet.TypedDataTable1[0]; - - var actual = (DataRow)null; - - string[] subsetOfColumnNames = dataRow.Table.Columns.Cast() - .Take(dataRow.Table.Columns.Count - 2) - .Select(column => column.ColumnName) - .ToArray(); - - // Act - Action act = () => - { - using var _ = new AssertionScope(); - actual.Should().HaveColumns(subsetOfColumnNames); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected actual to be in a table containing *column*, but found *"); - } - - [Fact] - public void When_data_row_data_has_only_some_of_the_columns_being_asserted_then_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataRow = dataSet.TypedDataTable1[0]; - - var subsetOfColumnNamesWithUnicorn = dataRow.Table.Columns.Cast() - .Take(dataRow.Table.Columns.Count - 2) - .Select(column => column.ColumnName) - .Concat(new[] { "Unicorn" }); - - // Act - Action action = - () => dataRow.Should().HaveColumns(subsetOfColumnNamesWithUnicorn); - - // Assert - action.Should().Throw() - .WithMessage("Expected table containing dataRow to contain a column named *Unicorn*"); - } - - [Fact] - public void When_data_row_data_has_none_of_the_columns_being_asserted_then_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataRow = dataSet.TypedDataTable1[0]; - - var columnNames = new[] { "Unicorn", "Dragon" }; - - // Act - Action action = - () => dataRow.Should().HaveColumns(columnNames); - - // Assert - action.Should().Throw() - .WithMessage("Expected table containing dataRow to contain a column named *Unicorn*"); - } -} diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs deleted file mode 100644 index 341bd5d509..0000000000 --- a/Tests/FluentAssertions.Equivalency.Specs/DataSetSpecs.cs +++ /dev/null @@ -1,831 +0,0 @@ -using System; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using FluentAssertions.Execution; -using Xunit; -using Xunit.Sdk; - -namespace FluentAssertions.Equivalency.Specs; - -public class DataSetSpecs : DataSpecs -{ - [Fact] - public void When_data_sets_are_identical_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2); - } - - [Fact] - public void When_data_sets_are_both_null_equivalence_test_should_succeed() - { - // Act & Assert - ((DataSet)null).Should().BeEquivalentTo(null); - } - - [Fact] - public void When_data_set_is_null_and_isnt_expected_to_be_equivalence_test_should_fail() - { - // Arrange - var typedDataSet = CreateDummyDataSet(); - - var dataSet = typedDataSet.ToUntypedDataSet(); - - // Act - Action action = () => ((DataSet)null).Should().BeEquivalentTo(dataSet); - - // Assert - action.Should().Throw().WithMessage( - "Expected *to be non-null, but found null*"); - } - - [Fact] - public void When_data_set_is_expected_to_be_null_and_isnt_equivalence_test_should_fail() - { - // Arrange - var typedDataSet = CreateDummyDataSet(); - - var dataSet = typedDataSet.ToUntypedDataSet(); - - // Act - Action action = () => dataSet.Should().BeEquivalentTo(null); - - // Assert - action.Should().Throw().WithMessage("Expected dataSet value to be null, but found *"); - } - - [Fact] - public void When_data_set_type_does_not_match_and_not_allowing_msimatched_types_equivalence_test_should_fail() - { - // Arrange - var typedDataSet = CreateDummyDataSet(); - - var dataSet = typedDataSet.ToUntypedDataSet(); - - var dataSetOfMismatchedType = new TypedDataSetSubclass(typedDataSet); - - // Act - Action action = () => dataSet.Should().BeEquivalentTo(dataSetOfMismatchedType); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataSet to be of type *TypedDataSetSubclass, but found System.Data.DataSet*"); - } - - [Fact] - public void When_data_set_type_does_not_match_but_mismatched_types_are_allowed_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet = CreateDummyDataSet(); - - var dataSet = typedDataSet.ToUntypedDataSet(); - - var dataSetOfMismatchedType = new TypedDataSetSubclass(typedDataSet); - - // Act & Assert - dataSet.Should().BeEquivalentTo(dataSetOfMismatchedType, options => options - .AllowingMismatchedTypes() - .Excluding(dataSet => dataSet.SchemaSerializationMode)); - } - - [Fact] - public void When_data_set_name_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.DataSetName += "different"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw().WithMessage("Expected dataSet1 to have DataSetName *different*"); - } - - [Fact] - public void When_data_set_name_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.DataSetName += "different"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .Excluding(dataSet => dataSet.DataSetName) - .ExcludingRelated((DataRelation dataRelation) => dataRelation.DataSet)); - } - - [Fact] - public void - When_one_data_set_is_configured_to_be_case_sensitive_and_the_other_is_not_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.CaseSensitive = !typedDataSet2.CaseSensitive; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataSet1 to have CaseSensitive value of True, but found False instead*"); - } - - [Fact] - public void - When_one_data_set_is_configured_to_be_case_sensitive_and_the_other_is_not_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.CaseSensitive = !typedDataSet2.CaseSensitive; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.CaseSensitive)); - } - - [Fact] - public void - When_one_data_set_is_configured_to_enforce_constraints_and_the_other_is_not_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.EnforceConstraints = !typedDataSet2.EnforceConstraints; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataSet1 to have EnforceConstraints value of False, but found True instead*"); - } - - [Fact] - public void - When_one_data_set_is_configured_to_enforce_constraints_and_the_other_is_not_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.EnforceConstraints = !typedDataSet2.EnforceConstraints; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.EnforceConstraints)); - } - - [Fact] - public void - When_one_data_set_has_errors_and_the_other_does_not_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.TypedDataTable1.Rows[0].RowError = "Manually added error"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2, config => config.ExcludingTables("TypedDataTable1")); - - // Assert - action.Should().Throw().Which.Message.Should().Contain("HasErrors"); - } - - [Fact] - public void - When_one_data_set_has_errors_and_the_other_does_not_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.TypedDataTable1.Rows[0].RowError = "Manually added error"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, - config => config.Excluding(dataSet => dataSet.HasErrors).ExcludingTables("TypedDataTable1")); - } - - [Fact] - public void - When_data_sets_have_mismatched_locale_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet1.Locale = new CultureInfo("en-US"); - typedDataSet2.Locale = new CultureInfo("fr-CA"); - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataSet1 to have Locale value of fr-CA, but found en-US instead*"); - } - - [Fact] - public void When_data_set_locale_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet1.Locale = new CultureInfo("en-US"); - typedDataSet2.Locale = new CultureInfo("fr-CA"); - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.Locale)); - } - - [Fact] - public void - When_data_set_namespace_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.Namespace += "different"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw().WithMessage("Expected dataSet1 to have Namespace value of *different*"); - } - - [Fact] - public void - When_data_set_namespace_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.Namespace += "different"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .Excluding(dataSet => dataSet.Namespace) - .ExcludingRelated((DataTable dataTable) => dataTable.Namespace) - .ExcludingRelated((DataColumn dataColumn) => dataColumn.Namespace)); - } - - [Fact] - public void When_data_set_prefix_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.Prefix += "different"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw().WithMessage("Expected dataSet1 to have Prefix value of *different*"); - } - - [Fact] - public void When_data_set_prefix_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.Prefix += "different"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.Prefix)); - } - - [Fact] - public void - When_data_set_remoting_format_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.RemotingFormat = - typedDataSet2.RemotingFormat == SerializationFormat.Binary - ? SerializationFormat.Xml - : SerializationFormat.Binary; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw() - .WithMessage( - "Expected dataSet1 to have RemotingFormat value of SerializationFormat.Binary*, but found *Xml* instead*"); - } - - [Fact] - public void - When_data_set_remoting_format_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.RemotingFormat = - typedDataSet2.RemotingFormat == SerializationFormat.Binary - ? SerializationFormat.Xml - : SerializationFormat.Binary; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .Excluding(dataSet => dataSet.RemotingFormat) - .ExcludingRelated(dataTable => dataTable.RemotingFormat)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void - When_data_set_extended_properties_do_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail( - ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - ApplyChange(typedDataSet2.ExtendedProperties, changeType); - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw().WithMessage("Expected *dataSet1.ExtendedProperties* to be *, but *"); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void - When_data_set_extended_properties_do_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed( - ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - ApplyChange(typedDataSet2.ExtendedProperties, changeType); - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.ExtendedProperties)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - [SuppressMessage("Style", "IDE0010:Add missing cases", Justification = "All enum values are accounted for.")] - public void When_data_set_relations_do_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail( - ChangeType changeType) - { - // Arrange - TypedDataSetSubclass typedDataSet1; - TypedDataSetSubclass typedDataSet2; - - if (changeType == ChangeType.Changed) - { - typedDataSet1 = CreateDummyDataSet(); - typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.Relations[0].RelationName += "different"; - } - else - { - var doesNotHaveRelation = CreateDummyDataSet(includeRelation: false); - var hasRelation = new TypedDataSetSubclass(doesNotHaveRelation); - - AddRelation(hasRelation); - - if (changeType == ChangeType.Added) - { - typedDataSet1 = doesNotHaveRelation; - typedDataSet2 = hasRelation; - } - else - { - typedDataSet1 = hasRelation; - typedDataSet2 = doesNotHaveRelation; - } - } - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw().WithMessage("Expected *dataSet1.Relations* to *, but *"); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - [SuppressMessage("Style", "IDE0010:Add missing cases", Justification = "All enum values are accounted for.")] - public void When_data_set_relations_do_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed( - ChangeType changeType) - { - // Arrange - TypedDataSetSubclass typedDataSet1; - TypedDataSetSubclass typedDataSet2; - - if (changeType == ChangeType.Changed) - { - typedDataSet1 = CreateDummyDataSet(); - typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.Relations[0].RelationName += "different"; - } - else - { - var doesNotHaveRelation = CreateDummyDataSet(includeRelation: false); - var hasRelation = new TypedDataSetSubclass(doesNotHaveRelation); - - AddRelation(hasRelation); - - if (changeType == ChangeType.Added) - { - typedDataSet1 = doesNotHaveRelation; - typedDataSet2 = hasRelation; - } - else - { - typedDataSet1 = hasRelation; - typedDataSet2 = doesNotHaveRelation; - } - } - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .Excluding(dataSet => dataSet.Relations) - .ExcludingRelated(dataTable => dataTable.Constraints) - .ExcludingRelated(dataTable => dataTable.ParentRelations) - .ExcludingRelated(dataTable => dataTable.ChildRelations) - .ExcludingRelated(dataColumn => dataColumn.Unique)); - } - - [Fact] - public void When_data_set_tables_are_the_same_but_in_a_different_order_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1, swapTableOrder: true); - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2); - } - - [Fact] - public void When_data_set_table_count_does_not_match_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1, swapTableOrder: true); - - typedDataSet2.Tables.Add(new DataTable("ThirdWheel")); - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw().Which.Message.Should().Contain("to contain " + dataSet2.Tables.Count); - } - - [Fact] - public void When_data_set_table_count_matches_but_tables_are_different_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1, swapTableOrder: true); - - typedDataSet2.TypedDataTable2.TableName = "DifferentTableName"; - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw() - .WithMessage( - "Expected dataSet1.Relations[0].ExtendedProperties* to reference column *ForeignRowID* in table *Different*, but found a reference to *ForeignRowID* in table *TypedDataTable2* instead*"); - } - - [Fact] - public void When_data_set_tables_contain_different_data_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1, swapTableOrder: true); - - typedDataSet2.TypedDataTable2[0].Guid = Guid.NewGuid(); - - var dataSet1 = typedDataSet1.ToUntypedDataSet(); - var dataSet2 = typedDataSet2.ToUntypedDataSet(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw() - .WithMessage( - "Expected dataSet1[TypedDataTable2].Rows[0] to have RowState value of *Modified*, but found *Unchanged* instead*"); - } - - [Fact] - public void Data_set_is_not_equivalent_to_another_type() - { - // Arrange - var subject = new - { - DataSet = "foobar" - }; - - var expected = new - { - DataSet = new DataSet() - }; - - // Act - Action act = () => subject.Should().BeEquivalentTo(expected); - - // Assert - act.Should().Throw() - .WithMessage("Expected*System.Data.DataSet*found System.String*"); - } - - [Fact] - public void When_data_set_table_count_has_expected_value_equivalence_test_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var correctTableCount = dataSet.Tables.Count; - - // Act & Assert - dataSet.Should().HaveTableCount(correctTableCount); - } - - [Fact] - public void Null_data_set_fails() - { - // Arrange - var dataSet = (DataSet)null; - - var correctTableCount = -1; - - // Act - Action act = () => - { - using var _ = new AssertionScope(); - dataSet.Should().HaveTableCount(correctTableCount); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected dataSet to contain exactly*, but found *"); - } - - [Fact] - public void When_data_set_table_count_has_unexpected_value_equivalence_test_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var correctTableCount = dataSet.Tables.Count; - - var incorrectTableCount = correctTableCount + 1; - - // Act - Action action = - () => dataSet.Should().HaveTableCount(incorrectTableCount); - - // Assert - action.Should().Throw().WithMessage("Expected dataSet to contain exactly 3 table(s), but found 2."); - } - - [Fact] - public void When_data_set_contains_expected_table_and_asserting_that_it_has_that_table_it_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var existingTableName = dataSet.Tables[0].TableName; - - // Act & Assert - dataSet.Should().HaveTable(existingTableName); - } - - [Fact] - public void Null_data_set_does_not_contain_expected_table() - { - // Arrange - var dataSet = (DataSet)null; - - var existingTableName = "Does not matter"; - - // Act - Action act = () => dataSet.Should().HaveTable(existingTableName); - - // Assert - act.Should().Throw() - .WithMessage("Expected dataSet to contain a table named*, but found *"); - } - - [Fact] - public void When_data_set_does_not_contain_expected_table_asserting_that_it_has_that_table_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - string nonExistingTableName = "Unicorn"; - - // Act - Action action = - () => dataSet.Should().HaveTable(nonExistingTableName); - - // Assert - action.Should().Throw().WithMessage("Expected dataSet to contain a table named *Unicorn*"); - } - - [Fact] - public void When_data_set_has_all_expected_tables_asserting_that_it_has_them_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var existingTableNames = dataSet.Tables.Cast() - .Select(table => table.TableName); - - // Act & Assert - dataSet.Should().HaveTables(existingTableNames); - } - - [Fact] - public void Null_data_set_has_no_tables_and_fails() - { - // Arrange - var dataSet = CreateDummyDataSet(); - var actual = (DataSet)null; - - var existingTableNames = dataSet.Tables.Cast() - .Select(table => table.TableName); - - // Act - Action act = () => - { - using var _ = new AssertionScope(); - actual.Should().HaveTables(existingTableNames); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected actual to contain*table*with specific name*, but found *"); - } - - [Fact] - public void When_data_set_has_some_of_the_expected_tables_but_not_all_then_asserting_that_it_has_them_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var tableNames = dataSet.Tables.Cast() - .Select(table => table.TableName) - .Concat(new[] { "Unicorn" }); - - // Act - Action action = - () => dataSet.Should().HaveTables(tableNames); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataSet to contain a table named *Unicorn*, but it does not."); - } - - [Fact] - public void When_data_set_has_none_of_the_expected_tables_then_asserting_that_it_has_them_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var nonExistentTableNames = new[] { "Unicorn", "Dragon" }; - - // Act - Action action = - () => dataSet.Should().HaveTables(nonExistentTableNames); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataSet to contain a table named *Unicorn*, but it does not."); - } -} diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataSpecs.cs deleted file mode 100644 index a2d6b77e35..0000000000 --- a/Tests/FluentAssertions.Equivalency.Specs/DataSpecs.cs +++ /dev/null @@ -1,676 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Linq; - -namespace FluentAssertions.Equivalency.Specs; - -/// -/// Class containing specs related to System.Data, including many common declarations and methods. -/// -public class DataSpecs -{ - // Non-static member to avoid getting flagged as a "static holder type". This - // type is inherited by the specialized specs classes it contains. - public int Dummy { get; set; } - - #region Subject Types - - /* - - NB: TypedDataTable1 and TypedDataTable2 intentionally have the same schema. This allows testing of - Should().BeEquivalentTo(options => options.AllowMismatchedTypes). - - */ - - public class TypedDataRow1 : DataRow - { - private readonly TypedDataTable1 ownerTable; - - public TypedDataRow1(DataRowBuilder rowBuilder) - : base(rowBuilder) - { - ownerTable = (TypedDataTable1)Table; - } - - public int RowID - { - get => (int)this[ownerTable.RowIDColumn]; - set => this[ownerTable.RowIDColumn] = value; - } - - public decimal Decimal - { - get => (decimal)this[ownerTable.DecimalColumn]; - set => this[ownerTable.DecimalColumn] = value; - } - - public string String - { - get => (string)this[ownerTable.StringColumn]; - set => this[ownerTable.StringColumn] = value; - } - - public Guid Guid - { - get => (Guid)this[ownerTable.GuidColumn]; - set => this[ownerTable.GuidColumn] = value; - } - - public DateTime DateTime - { - get => (DateTime)this[ownerTable.DateTimeColumn]; - set => this[ownerTable.DateTimeColumn] = value; - } - - public int? ForeignRowID - { - get => IsNull(ownerTable.ForeignRowIDColumn) ? null : (int?)this[ownerTable.ForeignRowIDColumn]; - set => this[ownerTable.ForeignRowIDColumn] = value; - } - } - - [SuppressMessage("Microsoft.StyleCop.CSharp.Naming", "SA1306", - Justification = "DataColumn accessors are named after the columns.")] - [SuppressMessage("Microsoft.StyleCop.CSharp.Naming", "SA1516", - Justification = "DataColumn accessors are grouped in a block of lines.")] - public class TypedDataTable1 : TypedTableBase - { - public TypedDataTable1() - { - TableName = "TypedDataTable1"; - - Columns.Add(new DataColumn("RowID", typeof(int))); - Columns.Add(new DataColumn("Decimal", typeof(decimal))); - Columns.Add(new DataColumn("String", typeof(string))); - Columns.Add(new DataColumn("Guid", typeof(Guid))); - Columns.Add(new DataColumn("DateTime", typeof(DateTime))); - Columns.Add(new DataColumn("ForeignRowID", typeof(int))); - - PrimaryKey = new[] { RowIDColumn }; - - Constraints.Add(new UniqueConstraint(GuidColumn)); - } - - protected override DataRow NewRowFromBuilder(DataRowBuilder builder) - { - return new TypedDataRow1(builder); - } - - public new TypedDataRow1 NewRow() - { - return (TypedDataRow1)base.NewRow(); - } - - public TypedDataRow1 this[int index] - { - get => (TypedDataRow1)Rows[index]; - } - - public DataColumn RowIDColumn => Columns["RowID"]; - public DataColumn DecimalColumn => Columns["Decimal"]; - public DataColumn StringColumn => Columns["String"]; - public DataColumn GuidColumn => Columns["Guid"]; - public DataColumn DateTimeColumn => Columns["DateTime"]; - public DataColumn ForeignRowIDColumn => Columns["ForeignRowID"]; - } - - public class TypedDataRow2 : DataRow - { - private readonly TypedDataTable2 ownerTable; - - public TypedDataRow2(DataRowBuilder rowBuilder) - : base(rowBuilder) - { - ownerTable = (TypedDataTable2)Table; - } - - public int RowID - { - get => (int)this[ownerTable.RowIDColumn]; - set => this[ownerTable.RowIDColumn] = value; - } - - public decimal Decimal - { - get => (decimal)this[ownerTable.DecimalColumn]; - set => this[ownerTable.DecimalColumn] = value; - } - - public string String - { - get => (string)this[ownerTable.StringColumn]; - set => this[ownerTable.StringColumn] = value; - } - - public Guid Guid - { - get => (Guid)this[ownerTable.GuidColumn]; - set => this[ownerTable.GuidColumn] = value; - } - - public DateTime DateTime - { - get => (DateTime)this[ownerTable.DateTimeColumn]; - set => this[ownerTable.DateTimeColumn] = value; - } - - public int? ForeignRowID - { - get => IsNull(ownerTable.ForeignRowIDColumn) ? null : (int?)this[ownerTable.ForeignRowIDColumn]; - set => this[ownerTable.ForeignRowIDColumn] = value; - } - } - - [SuppressMessage("Microsoft.StyleCop.CSharp.Naming", "SA1306", - Justification = "DataColumn accessors are named after the columns.")] - [SuppressMessage("Microsoft.StyleCop.CSharp.Naming", "SA1516", - Justification = "DataColumn accessors are grouped in a block of lines.")] - public class TypedDataTable2 : TypedTableBase - { - public TypedDataTable2() - { - TableName = "TypedDataTable2"; - - Columns.Add(new DataColumn("RowID", typeof(int))); - Columns.Add(new DataColumn("Decimal", typeof(decimal))); - Columns.Add(new DataColumn("String", typeof(string))); - Columns.Add(new DataColumn("Guid", typeof(Guid))); - Columns.Add(new DataColumn("DateTime", typeof(DateTime))); - Columns.Add(new DataColumn("ForeignRowID", typeof(int))); - - PrimaryKey = new[] { RowIDColumn }; - - Constraints.Add(new UniqueConstraint(GuidColumn)); - } - - protected override DataRow NewRowFromBuilder(DataRowBuilder builder) - { - return new TypedDataRow2(builder); - } - - public new TypedDataRow2 NewRow() - { - return (TypedDataRow2)base.NewRow(); - } - - public TypedDataRow2 this[int index] - { - get => (TypedDataRow2)Rows[index]; - } - - public DataColumn RowIDColumn => Columns["RowID"]; - public DataColumn DecimalColumn => Columns["Decimal"]; - public DataColumn StringColumn => Columns["String"]; - public DataColumn GuidColumn => Columns["Guid"]; - public DataColumn DateTimeColumn => Columns["DateTime"]; - public DataColumn ForeignRowIDColumn => Columns["ForeignRowID"]; - } - - [SuppressMessage("Microsoft.StyleCop.CSharp.Naming", "SA1516", - Justification = "DataTable accessors are grouped in a block of lines.")] - public class TypedDataSet : DataSet - { - public override SchemaSerializationMode SchemaSerializationMode { get; set; } - - public TypedDataSet() - : this(swapTableOrder: false) - { - } - - public TypedDataSet(bool swapTableOrder) - { - if (swapTableOrder) - { - Tables.Add(new TypedDataTable2()); - Tables.Add(new TypedDataTable1()); - } - else - { - Tables.Add(new TypedDataTable1()); - Tables.Add(new TypedDataTable2()); - } - } - - public TypedDataTable1 TypedDataTable1 => (TypedDataTable1)Tables["TypedDataTable1"]; - public TypedDataTable2 TypedDataTable2 => (TypedDataTable2)Tables["TypedDataTable2"]; - - public DataSet ToUntypedDataSet() - { - var dataSet = new DataSet(); - - dataSet.DataSetName = DataSetName; - dataSet.CaseSensitive = CaseSensitive; - dataSet.EnforceConstraints = EnforceConstraints; - dataSet.Locale = Locale; - dataSet.Namespace = Namespace; - dataSet.Prefix = Prefix; - dataSet.RemotingFormat = RemotingFormat; - - foreach (var typedTable in Tables.Cast()) - { - var dataTable = new DataTable(); - - dataTable.TableName = typedTable.TableName; - dataTable.DisplayExpression = typedTable.DisplayExpression; - dataTable.MinimumCapacity = typedTable.MinimumCapacity; - dataTable.Namespace = typedTable.Namespace; - dataTable.Prefix = typedTable.Prefix; - dataTable.RemotingFormat = typedTable.RemotingFormat; - - foreach (var column in typedTable.Columns.Cast()) - { - var dataColumn = new DataColumn(); - - dataColumn.ColumnName = column.ColumnName; - dataColumn.AllowDBNull = column.AllowDBNull; - dataColumn.AutoIncrement = column.AutoIncrement; - dataColumn.AutoIncrementSeed = column.AutoIncrementSeed; - dataColumn.AutoIncrementStep = column.AutoIncrementStep; - dataColumn.Caption = column.Caption; - dataColumn.ColumnMapping = column.ColumnMapping; - dataColumn.DataType = column.DataType; - dataColumn.DateTimeMode = column.DateTimeMode; - dataColumn.DefaultValue = column.DefaultValue; - dataColumn.Expression = column.Expression; - dataColumn.MaxLength = column.MaxLength; - dataColumn.Namespace = column.Namespace; - dataColumn.Prefix = column.Prefix; - dataColumn.ReadOnly = column.ReadOnly; - - foreach (var property in column.ExtendedProperties.Cast()) - { - dataColumn.ExtendedProperties.Add(property.Key, property.Value); - } - - dataTable.Columns.Add(dataColumn); - } - - foreach (var row in typedTable.Rows.Cast()) - { - dataTable.ImportRow(row); - } - - dataTable.PrimaryKey = typedTable.PrimaryKey - .Select(col => dataTable.Columns[col.ColumnName]) - .ToArray(); - - foreach (var property in typedTable.ExtendedProperties.Cast()) - { - dataTable.ExtendedProperties.Add(property.Key, property.Value); - } - - foreach (var constraint in typedTable.Constraints.Cast()) - { - if (!Relations.Cast().Any(rel => - rel.ChildKeyConstraint == constraint || - rel.ParentKeyConstraint == constraint)) - { - if (constraint is UniqueConstraint uniqueConstraint) - { - if (!uniqueConstraint.IsPrimaryKey) - { - dataTable.Constraints.Add(new UniqueConstraint( - name: uniqueConstraint.ConstraintName, - column: dataTable.Columns[uniqueConstraint.Columns.Single().ColumnName])); - } - } - else - { - throw new Exception($"Don't know how to clone a constraint of type {constraint.GetType()}"); - } - } - } - - dataSet.Tables.Add(dataTable); - } - - foreach (var property in ExtendedProperties.Cast()) - { - dataSet.ExtendedProperties.Add(property.Key, property.Value); - } - - foreach (var relation in Relations.Cast()) - { - // NB: In the context of the unit test, this is assuming that there is only one column in a relation. - var dataRelation = new DataRelation( - relation.RelationName, - parentColumn: dataSet.Tables[relation.ParentTable.TableName] - .Columns[relation.ParentColumns.Single().ColumnName], - childColumn: dataSet.Tables[relation.ChildTable.TableName] - .Columns[relation.ChildColumns.Single().ColumnName]); - - foreach (var property in relation.ExtendedProperties.Cast()) - { - dataRelation.ExtendedProperties.Add(property.Key, property.Value); - } - - dataSet.Relations.Add(dataRelation); - } - - return dataSet; - } - } - - public class TypedDataSetSubclass : TypedDataSet - { - public TypedDataSetSubclass() - { - } - - public TypedDataSetSubclass(TypedDataSet copyFrom, bool swapTableOrder = false, bool randomizeRowOrder = false) - : base(swapTableOrder) - { - DataSetName = copyFrom.DataSetName; - CaseSensitive = copyFrom.CaseSensitive; - EnforceConstraints = copyFrom.EnforceConstraints; - Locale = copyFrom.Locale; - Namespace = copyFrom.Namespace; - Prefix = copyFrom.Prefix; - RemotingFormat = copyFrom.RemotingFormat; -#pragma warning disable MA0056 - SchemaSerializationMode = copyFrom.SchemaSerializationMode; -#pragma warning restore MA0056 - - CopyTable( - from: copyFrom.TypedDataTable1, - to: TypedDataTable1, - randomizeRowOrder); - - CopyTable( - from: copyFrom.TypedDataTable2, - to: TypedDataTable2, - randomizeRowOrder); - - foreach (var property in copyFrom.ExtendedProperties.Cast()) - { - ExtendedProperties.Add(property.Key, property.Value); - } - - foreach (var copyFromRelation in copyFrom.Relations.Cast()) - { - // NB: In the context of the unit test, this is assuming that there is only one column in a relation. - var relation = new DataRelation( - copyFromRelation.RelationName, - parentColumn: Tables[copyFromRelation.ParentTable.TableName] - .Columns[copyFromRelation.ParentColumns.Single().ColumnName], - childColumn: Tables[copyFromRelation.ChildTable.TableName] - .Columns[copyFromRelation.ChildColumns.Single().ColumnName]); - - foreach (var property in copyFromRelation.ExtendedProperties.Cast()) - { - relation.ExtendedProperties.Add(property.Key, property.Value); - } - - Relations.Add(relation); - } - } - - private void CopyTable(TDataTable from, TDataTable to, bool randomizeRowOrder) - where TDataTable : DataTable, IEnumerable - where TDataRow : DataRow - { - if (randomizeRowOrder) - { - foreach (var row in from.OrderBy(_ => Guid.NewGuid())) - { - to.ImportRow(row); - } - } - else - { - foreach (var row in from) - { - to.ImportRow(row); - } - } - - foreach (var property in from.ExtendedProperties.Cast()) - { - to.ExtendedProperties.Add(property.Key, property.Value); - } - - foreach (var column in to.Columns.Cast()) - { - foreach (var property in from.Columns[column.ColumnName].ExtendedProperties.Cast()) - { - column.ExtendedProperties.Add(property.Key, property.Value); - } - } - } - } - - #endregion - - private static readonly Random Random = new(0); - - internal static TDataSet CreateDummyDataSet(bool identicalTables = false, bool includeDummyData = true, - bool includeRelation = true) - where TDataSet : TypedDataSet, new() - { - var ret = new TDataSet(); - - foreach (var dataColumn in ret.TypedDataTable1.Columns.Cast()) - { - AddExtendedProperties(dataColumn.ExtendedProperties); - } - - if (includeDummyData) - { - InsertDummyRows(ret.TypedDataTable1); - } - - AddExtendedProperties(ret.TypedDataTable1.ExtendedProperties); - - if (identicalTables) - { - foreach (var dataColumn in ret.TypedDataTable2.Columns.Cast()) - { - foreach (var property in ret.TypedDataTable1.ExtendedProperties.Cast()) - { - dataColumn.ExtendedProperties.Add(property.Key, property.Value); - } - } - - foreach (var row in ret.TypedDataTable1.Cast()) - { - ret.TypedDataTable2.ImportRow(row); - } - - foreach (var property in ret.TypedDataTable1.ExtendedProperties.Cast()) - { - ret.TypedDataTable2.ExtendedProperties.Add(property.Key, property.Value); - } - } - else - { - foreach (var dataColumn in ret.TypedDataTable2.Columns.Cast()) - { - AddExtendedProperties(dataColumn.ExtendedProperties); - } - - if (includeDummyData) - { - InsertDummyRows(ret.TypedDataTable2, ret.TypedDataTable1); - } - - if (includeRelation) - { - AddRelation(ret); - } - - AddExtendedProperties(ret.TypedDataTable2.ExtendedProperties); - } - - AddExtendedProperties(ret.ExtendedProperties); - - return ret; - } - - protected static void AddRelation(TypedDataSet dataSet) - { - var relation = new DataRelation("TestRelation", dataSet.TypedDataTable1.RowIDColumn, - dataSet.TypedDataTable2.ForeignRowIDColumn); - - AddExtendedProperties(relation.ExtendedProperties); - - dataSet.Relations.Add(relation); - } - - private static void AddExtendedProperties(PropertyCollection extendedProperties) - { - extendedProperties.Add(Guid.NewGuid(), Guid.NewGuid()); - extendedProperties.Add(Guid.NewGuid(), Guid.NewGuid().ToString()); - extendedProperties.Add(Guid.NewGuid().ToString(), Guid.NewGuid()); - } - - private static void InsertDummyRows(DataTable table, DataTable foreignRows = null) - { - for (int i = 0; i < 10; i++) - { - InsertDummyRow(table, foreignRows?.Rows[i]); - } - - table.AcceptChanges(); - } - - private static void InsertDummyRow(DataTable table, DataRow foreignRow = null) - { - var row = table.NewRow(); - - foreach (var column in table.Columns.Cast()) - { - if (column.ColumnName.StartsWith("Foreign", StringComparison.Ordinal)) - { - row[column] = foreignRow?[column.ColumnName.Substring(7)] ?? DBNull.Value; - } - else - { - row[column] = GetDummyValueOfType(column.DataType); - } - } - - table.Rows.Add(row); - } - - [SuppressMessage("Style", "IDE0010:Add missing cases", - Justification = "TypedDataTable test types have a limited set of columns.")] - private static object GetDummyValueOfType(Type dataType) - { - switch (Type.GetTypeCode(dataType)) - { - case TypeCode.Int32: - return Random.Next(); - case TypeCode.DateTime: - return DateTime.MinValue.AddTicks((Random.Next() & 0x7FFFFFFF) * 1469337835L) - .AddTicks(((Random.Next() & 0x7FFFFFFF) * 1469337835L) / 2147483648); - case TypeCode.Decimal: - return new decimal(Random.NextDouble()); - case TypeCode.String: - return Guid.NewGuid().ToString(); - - default: - if (dataType == typeof(Guid)) - { - return Guid.NewGuid(); - } - - throw new Exception($"Don't know how to generate dummy value of type {dataType}"); - } - } - - public enum ChangeType - { - Added, - Changed, - Removed, - } - - public static IEnumerable AllChangeTypes => - Enum.GetValues(typeof(ChangeType)).Cast().Select(t => new object[] { t }); - - public static IEnumerable AllChangeTypesWithAcceptChangesValues - { - get - { - return - from changeType in Enum.GetValues(typeof(ChangeType)).Cast() - from acceptChanges in new[] { true, false } - select new object[] { changeType, acceptChanges }; - } - } - - [SuppressMessage("Style", "IDE0010:Add missing cases", Justification = "Every enum value is covered")] - protected static void ApplyChange(DataColumnCollection columns, ChangeType changeType) - { - switch (changeType) - { - case ChangeType.Added: - columns.Add("Test", typeof(int)); - break; - case ChangeType.Changed: - columns[1].ColumnName += "different"; - break; - case ChangeType.Removed: - columns.RemoveAt(1); - break; - } - } - - [SuppressMessage("Style", "IDE0010:Add missing cases", Justification = "Every enum value is covered")] - protected static void ApplyChange(PropertyCollection extendedProperties, ChangeType changeType) - { - switch (changeType) - { - case ChangeType.Added: - extendedProperties[Guid.NewGuid()] = Guid.NewGuid(); - break; - case ChangeType.Changed: - extendedProperties[extendedProperties.Keys.Cast().First()] = Guid.NewGuid(); - break; - case ChangeType.Removed: - extendedProperties.Remove(extendedProperties.Keys.Cast().First()); - break; - } - } - - [SuppressMessage("Style", "IDE0010:Add missing cases", Justification = "Every enum value is covered")] - protected static void ApplyChange(ConstraintCollection constraints, DataColumn columnForNewConstraint, ChangeType changeType) - { - switch (changeType) - { - case ChangeType.Added: - constraints.Add( - new UniqueConstraint( - "Test", - columnForNewConstraint)); - - break; - case ChangeType.Changed: - constraints[1].ConstraintName += "different"; - break; - case ChangeType.Removed: - constraints.RemoveAt(1); - break; - } - } - - [SuppressMessage("Style", "IDE0010:Add missing cases", Justification = "Every enum value is covered")] - protected static void ApplyChange(DataRowCollection rows, DataTable dataTable, ChangeType changeType) - { - switch (changeType) - { - case ChangeType.Added: - InsertDummyRow(dataTable); - break; - case ChangeType.Changed: - rows[1]["String"] += "different"; - break; - case ChangeType.Removed: - rows.RemoveAt(0); - break; - } - } -} diff --git a/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs deleted file mode 100644 index a19bc43b40..0000000000 --- a/Tests/FluentAssertions.Equivalency.Specs/DataTableSpecs.cs +++ /dev/null @@ -1,1114 +0,0 @@ -using System; -using System.Data; -using System.Globalization; -using System.Linq; -using FluentAssertions.Data; -using FluentAssertions.Execution; -using Xunit; -using Xunit.Sdk; - -namespace FluentAssertions.Equivalency.Specs; - -public class DataTableSpecs : DataSpecs -{ - [Fact] - public void When_data_tables_are_identical_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2); - } - - [Fact] - public void When_data_tables_are_both_null_equivalence_test_should_succeed() - { - // Act & Assert - ((DataTable)null).Should().BeEquivalentTo(null); - } - - [Fact] - public void When_row_match_mode_is_invalid_it_should_fail() - { - // Arrange - var typedDataSet = CreateDummyDataSet(); - - var subject = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - var expectation = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act - Action action = () => subject.Should().BeEquivalentTo(expectation, options => options.UsingRowMatchMode((RowMatchMode)2)); - - // Assert - action.Should().Throw().WithMessage( - "Unknown RowMatchMode *when trying to compare *"); - } - - [Theory] - [MemberData(nameof(EmptyPrimaryKeys))] - public void When_row_match_mode_is_primary_key_without_primary_key_it_should_fail(DataColumn[] emptyPrimaryKey) - { - // Arrange - var typedDataSet = CreateDummyDataSet(includeRelation: false); - - var subject = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - var expectation = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - - subject.PrimaryKey = emptyPrimaryKey; - - // Act - Action action = () => - subject.Should().BeEquivalentTo(expectation, options => options.UsingRowMatchMode(RowMatchMode.PrimaryKey)); - - // Assert - action.Should().Throw().WithMessage( - "*Table *containing *does not have a primary key. RowMatchMode.PrimaryKey cannot be applied.*"); - } - - public static TheoryData EmptyPrimaryKeys => new() - { - null, - new DataColumn[] { } - }; - - [Fact] - public void When_primary_key_types_do_not_match_it_should_throw() - { - // Arrange - var typedDataSetSubject = CreateDummyDataSet(includeDummyData: false, includeRelation: false); - var typedDataSetExpectation = new TypedDataSetSubclass(typedDataSetSubject); - - var subject = typedDataSetSubject.ToUntypedDataSet().Tables["TypedDataTable1"]; - var expectation = typedDataSetExpectation.ToUntypedDataSet().Tables["TypedDataTable1"]; - - subject.PrimaryKey[0].DataType = typeof(long); - subject.Rows.Add(1L); - subject.AcceptChanges(); - expectation.Rows.Add(1); - expectation.AcceptChanges(); - - // Act - Action action = () => - subject.Should().BeEquivalentTo(expectation, options => options.UsingRowMatchMode(RowMatchMode.PrimaryKey)); - - // Assert - action.Should().Throw().WithMessage( - "*Subject and expectation primary keys of table containing *do not have the same schema and cannot be compared. " + - "RowMatchMode.PrimaryKey cannot be applied.*"); - } - - [Fact] - public void When_primary_key_of_one_rows_differ_it_should_fail() - { - // Arrange - var typedDataSetSubject = CreateDummyDataSet(); - var typedDataSetExpectation = new TypedDataSetSubclass(typedDataSetSubject); - - var subject = typedDataSetSubject.ToUntypedDataSet().Tables["TypedDataTable1"]; - var expectation = typedDataSetExpectation.ToUntypedDataSet().Tables["TypedDataTable1"]; - - expectation.Rows[0].SetField(expectation.PrimaryKey[0], 0); - - expectation.AcceptChanges(); - - // Act - Action action = () => - subject.Should().BeEquivalentTo(expectation, options => options.UsingRowMatchMode(RowMatchMode.PrimaryKey)); - - // Assert - action.Should().Throw().WithMessage( - "Found unexpected row in *with key *Expected to find a row with key *in *, but no such row was found*"); - } - - [Fact] - public void When_primary_key_of_multiple_rows_differ_it_should_fail() - { - // Arrange - var typedDataSetSubject = CreateDummyDataSet(); - var typedDataSetExpectation = new TypedDataSetSubclass(typedDataSetSubject); - - var subject = typedDataSetSubject.ToUntypedDataSet().Tables["TypedDataTable1"]; - var expectation = typedDataSetExpectation.ToUntypedDataSet().Tables["TypedDataTable1"]; - - for (int i = 0; i < 3; i++) - { - expectation.Rows[i].SetField(expectation.PrimaryKey[0], i); - } - - expectation.AcceptChanges(); - - // Act - Action action = () => - subject.Should().BeEquivalentTo(expectation, options => options.UsingRowMatchMode(RowMatchMode.PrimaryKey)); - - // Assert - action.Should().Throw().WithMessage( - "Found unexpected row in *with key * rows were expected in *and not found*"); - } - - [Fact] - public void When_data_table_is_null_and_isnt_expected_to_be_equivalence_test_should_fail() - { - // Arrange - var typedDataSet = CreateDummyDataSet(); - - var dataTable = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act - Action action = () => ((DataTable)null).Should().BeEquivalentTo(dataTable); - - // Assert - action.Should().Throw().WithMessage( - "Expected *to be non-null, but found null*"); - } - - [Fact] - public void When_data_table_is_expected_to_be_null_and_isnt_equivalence_test_should_fail() - { - // Arrange - var typedDataSet = CreateDummyDataSet(); - - var dataTable = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act - Action action = () => dataTable.Should().BeEquivalentTo(null); - - // Assert - action.Should().Throw().WithMessage("Expected dataTable value to be null, but found TypedDataTable1*"); - } - - [Fact] - public void - When_data_table_type_does_not_match_and_assertion_is_not_configured_to_allow_mismatched_types_equivalence_test_should_fail() - { - // Arrange - var typedDataSet = CreateDummyDataSet(identicalTables: true); - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet); - - var dataTable = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTableOfMismatchedType = typedDataSet2.TypedDataTable1; - - // Act - Action action = () => dataTable.Should().BeEquivalentTo(dataTableOfMismatchedType); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable to be of type *TypedDataTable1*, but found *System.Data.DataTable*"); - } - - [Fact] - public void - When_data_table_type_does_not_match_but_assertion_is_configured_to_allow_mismatched_types_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet = CreateDummyDataSet(identicalTables: true); - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet); - - var dataTable = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTableOfMismatchedType = typedDataSet2.TypedDataTable1; - - // Act & Assert - dataTable.Should().BeEquivalentTo(dataTableOfMismatchedType, options => options.AllowingMismatchedTypes()); - } - - [Fact] - public void When_data_table_name_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - dataTable2.TableName += "different"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable1 to have TableName *different*, but found *TypedDataTable1* instead*"); - } - - [Fact] - public void When_excluding_invalid_constraint_it_should_throw() - { - // Arrange - var typedDataSet = CreateDummyDataSet(); - - var subject = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - var expectation = typedDataSet.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act - Action action = () => subject.Should().BeEquivalentTo(expectation, options => options - .ExcludingRelated((Constraint constraint) => new object())); - - // Assert - action.Should().Throw().WithMessage( - "*Expression must be a simple member access*"); - } - - [Fact] - public void When_data_table_name_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(identicalTables: true); - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - dataTable2.TableName += "different"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo( - dataTable2, - options => options - .Excluding(dataTable => dataTable.TableName) - .ExcludingRelated((DataColumn dataColumn) => dataColumn.Table) - .ExcludingRelated((Constraint constraint) => constraint.Table)); - } - - [Fact] - public void - When_data_table_case_sensitivity_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.CaseSensitive = !typedDataSet2.CaseSensitive; - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable1 to have CaseSensitive value of True, but found False instead*"); - } - - [Fact] - public void - When_data_table_case_sensitivity_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.CaseSensitive = !typedDataSet2.CaseSensitive; - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.CaseSensitive)); - } - - [Fact] - public void - When_data_table_display_expression_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - dataTable2.DisplayExpression = typedDataSet2.TypedDataTable1.StringColumn.ColumnName; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw().WithMessage("Expected dataTable1 to have DisplayExpression value of *String*"); - } - - [Fact] - public void - When_data_table_display_expression_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - dataTable2.DisplayExpression = typedDataSet2.TypedDataTable1.StringColumn.ColumnName; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.DisplayExpression)); - } - - [Fact] - public void - When_one_data_table_has_errors_and_the_other_does_not_and_the_property_that_indicates_the_presence_of_errors_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - dataTable2.Rows[0].RowError = "Manually added error"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw().Which.Message.Should().Contain("HasErrors"); - } - - [Fact] - public void - When_one_data_table_has_errors_and_the_other_does_not_but_the_property_that_indicates_the_presence_of_errors_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - dataTable2.Rows[0].RowError = "Manually added error"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, config => config - .Excluding(dataTable => dataTable.HasErrors) - .ExcludingRelated((DataRow dataRow) => dataRow.HasErrors)); - } - - [Fact] - public void - When_data_table_locale_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet1.Locale = new CultureInfo("en-US"); - typedDataSet2.Locale = new CultureInfo("fr-CA"); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable1 to have Locale value of *fr-CA*, but found *en-US* instead*"); - } - - [Fact] - public void When_data_table_locale_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet1.Locale = new CultureInfo("en-US"); - typedDataSet2.Locale = new CultureInfo("fr-CA"); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.Locale)); - } - - [Fact] - public void - When_data_table_namespace_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.Namespace += "different"; - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable1 to have Namespace value of *different*, but found *"); - } - - [Fact] - public void - When_data_table_namespace_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.Namespace += "different"; - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.Namespace) - .ExcludingRelated((DataColumn dataColumn) => dataColumn.Namespace)); - } - - [Fact] - public void - When_data_table_prefix_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - dataTable2.Prefix += "different"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable1 to have Prefix value of *different*, but found * instead*"); - } - - [Fact] - public void When_data_table_prefix_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - dataTable2.Prefix += "different"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.Prefix)); - } - - [Fact] - public void - When_data_table_remoting_format_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.RemotingFormat = - typedDataSet2.RemotingFormat == SerializationFormat.Binary - ? SerializationFormat.Xml - : SerializationFormat.Binary; - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable1 to have RemotingFormat value of *Binary*, but found *Xml* instead*"); - } - - [Fact] - public void - When_data_table_remoting_format_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - typedDataSet2.RemotingFormat = - typedDataSet2.RemotingFormat == SerializationFormat.Binary - ? SerializationFormat.Xml - : SerializationFormat.Binary; - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // LAST ONE - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.RemotingFormat)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_data_table_columns_do_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail( - ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - ApplyChange(dataTable2.Columns, changeType); - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw().WithMessage("Expected property dataTable1.Column* to be *, but *"); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_data_table_columns_do_not_match_but_columns_and_rows_are_excluded_equivalence_test_should_succeed( - ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - ApplyChange(dataTable2.Columns, changeType); - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.Columns) - .Excluding(dataTable => dataTable.Rows)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void - When_data_table_extended_properties_do_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail( - ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - ApplyChange(dataTable2.ExtendedProperties, changeType); - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw().WithMessage("Expected *dataTable1.ExtendedProperties* to be *, but *"); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void - When_data_table_extended_properties_do_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed( - ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - ApplyChange(dataTable2.ExtendedProperties, changeType); - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.ExtendedProperties)); - } - - [Fact] - public void - When_data_table_primary_key_does_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable2"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable2"]; - - dataTable1.Columns.Cast().Skip(2).ToList() - .ForEach(col => col.AllowDBNull = false); - - dataTable2.PrimaryKey = dataTable2.Columns.Cast().Skip(2).ToArray(); - dataTable2.Columns[0].Unique = true; - - // Act - Action action = () => - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.Constraints)); - - // Assert - action.Should().Throw() - .WithMessage( - "Expected property dataTable1.PrimaryKey to be a collection with * item(s), but *contains * item(s) less than*"); - } - - [Fact] - public void - When_data_table_primary_key_does_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - for (int i = 2; i < typedDataSet1.TypedDataTable2.Columns.Count; i++) - { - typedDataSet1.TypedDataTable2.Columns[i].AllowDBNull = false; - } - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable2"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable2"]; - - dataTable2.PrimaryKey = dataTable2.Columns.Cast().Skip(2).ToArray(); - dataTable2.Columns[0].Unique = true; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.PrimaryKey) - .Excluding(dataTable => dataTable.Constraints)); - } - - public enum NumberOfColumnsInConstraintDifference - { - SingleColumn, - MultipleColumns, - } - - [Theory] - [InlineData(NumberOfColumnsInConstraintDifference.SingleColumn)] - [InlineData(NumberOfColumnsInConstraintDifference.MultipleColumns)] - public void When_columns_for_constraint_in_data_table_do_not_match_message_should_list_all_columns_involved( - NumberOfColumnsInConstraintDifference difference) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable2"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable2"]; - - int differenceCount = - difference switch - { - NumberOfColumnsInConstraintDifference.SingleColumn => 1, - NumberOfColumnsInConstraintDifference.MultipleColumns => 2, - - _ => throw new Exception("Sanity failure") - }; - - var dataTable1ColumnsForConstraint = dataTable1.Columns.Cast() - .Take(dataTable1.Columns.Count - differenceCount) - .ToArray(); - - var dataTable2ColumnsForConstraint = dataTable2.Columns.Cast() - .Skip(differenceCount) - .ToArray(); - - const string ConstraintName = "TestSubjectConstraint"; - - dataTable1.Constraints.Add(new UniqueConstraint(ConstraintName, dataTable1ColumnsForConstraint)); - dataTable2.Constraints.Add(new UniqueConstraint(ConstraintName, dataTable2ColumnsForConstraint)); - - var missingColumnNames = dataTable2ColumnsForConstraint.Select(col => col.ColumnName) - .Except(dataTable1ColumnsForConstraint.Select(col => col.ColumnName)); - - var extraColumnNames = dataTable1ColumnsForConstraint.Select(col => col.ColumnName) - .Except(dataTable2ColumnsForConstraint.Select(col => col.ColumnName)); - - string columnsNoun = differenceCount == 1 - ? "column" - : "columns"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw().WithMessage( - $"Expected *{ConstraintName}* to include {columnsNoun} {string.Join("*", missingColumnNames)}*" + - $"Did not expect *{ConstraintName}* to include {columnsNoun} {string.Join("*", extraColumnNames)}*"); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void - When_data_table_constraints_do_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail( - ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable2"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable2"]; - - ApplyChange(dataTable2.Constraints, dataTable2.Columns["Decimal"], changeType); - - string expectedExceptionPattern = - changeType == ChangeType.Changed - ? "Found unexpected constraint named *Constraint2* in property dataTable1.Constraints*" - : "Expected property dataTable1.Columns[*].Unique to be *, but found *"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw().WithMessage(expectedExceptionPattern); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void - When_data_table_constraints_do_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed( - ChangeType changeType) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable2"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable2"]; - - ApplyChange(dataTable2.Constraints, dataTable2.Columns["Decimal"], changeType); - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.Constraints) - .ExcludingRelated(dataColumn => dataColumn.Unique)); - } - - [Theory] - [MemberData(nameof(AllChangeTypesWithAcceptChangesValues))] - public void When_data_table_rows_do_not_match_and_the_corresponding_property_is_not_excluded_equivalence_test_should_fail( - ChangeType changeType, bool acceptChanges) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - ApplyChange(dataTable2.Rows, dataTable2, changeType); - - if (acceptChanges) - { - dataTable2.AcceptChanges(); - } - - string exceptionPattern; - - if (changeType == ChangeType.Changed) - { - exceptionPattern = - acceptChanges - ? "Expected dataTable1.Rows[1][String] to be *different* with a length of *, but * has a length of *, differs near *" - : "Expected dataTable1.Rows[1] to have RowState value of *Modified*, but found *Unchanged* instead*"; - } - else - { - exceptionPattern = - "Expected property dataTable1.Rows to contain * row(s), but found 10*"; - } - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw().WithMessage(exceptionPattern); - } - - [Theory] - [MemberData(nameof(AllChangeTypesWithAcceptChangesValues))] - public void When_data_table_rows_do_not_match_but_the_corresponding_property_is_excluded_equivalence_test_should_succeed( - ChangeType changeType, bool acceptChanges) - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - ApplyChange(dataTable2.Rows, dataTable2, changeType); - - if (acceptChanges) - { - dataTable2.AcceptChanges(); - } - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.Rows)); - } - - [Fact] - public void - When_data_table_data_matches_in_different_order_and_the_row_match_mode_is_by_primary_key_equivalence_test_should_succeed() - { - // Arrange - var typedDataSet1 = CreateDummyDataSet(); - - var typedDataSet2 = new TypedDataSetSubclass(typedDataSet1, randomizeRowOrder: true); - - var dataTable1 = typedDataSet1.ToUntypedDataSet().Tables["TypedDataTable1"]; - var dataTable2 = typedDataSet2.ToUntypedDataSet().Tables["TypedDataTable1"]; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.UsingRowMatchMode(RowMatchMode.PrimaryKey)); - } - - [Fact] - public void Data_table_is_not_equivalent_to_another_type() - { - // Arrange - var subject = new - { - DataTable = "foobar" - }; - - var expected = new - { - DataTable = new DataTable() - }; - - // Act - Action act = () => subject.Should().BeEquivalentTo(expected); - - // Assert - act.Should().Throw() - .WithMessage("Expected*System.Data.DataTable*found System.String*"); - } - - [Fact] - public void When_data_table_has_expected_row_count_it_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - int correctRowCount = dataTable.Rows.Count; - - // Act & Assert - dataTable.Should().HaveRowCount(correctRowCount); - } - - [Fact] - public void Null_data_table_no_rows_and_fails_test() - { - // Arrange - var dataTable = (DataTable)null; - - int correctRowCount = -1; - - // Act - Action act = () => - { - using var _ = new AssertionScope(); - dataTable.Should().HaveRowCount(correctRowCount); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected dataTable to contain exactly*row*, but found *"); - } - - [Fact] - public void When_empty_data_table_has_expected_row_count_of_zero_it_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable2; - - dataTable.Rows.Clear(); - dataTable.AcceptChanges(); - - // Act & Assert - dataTable.Should().HaveRowCount(0); - } - - [Fact] - public void When_data_table_does_not_have_expected_row_count_does_not_match_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - int correctRowCount = dataTable.Rows.Count; - - int incorrectRowCount = correctRowCount * 2; - - // Act - Action action = - () => dataTable.Should().HaveRowCount(incorrectRowCount); - - // Assert - action.Should().Throw().WithMessage("Expected dataTable to contain exactly * row(s), but found *"); - } - - [Fact] - public void When_data_table_has_expected_column_it_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - var expectedColumnName = dataTable.Columns[0].ColumnName; - - // Act & Assert - dataTable.Should().HaveColumn(expectedColumnName); - } - - [Fact] - public void Null_data_table_has_no_columns_and_fail_the_test() - { - // Arrange - var dataTable = (DataTable)null; - - var expectedColumnName = "Does not matter"; - - // Act - Action act = () => dataTable.Should().HaveColumn(expectedColumnName); - - // Assert - act.Should().Throw() - .WithMessage("Expected dataTable to contain a column named*, but found *"); - } - - [Fact] - public void When_data_table_does_not_have_expected_column_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - // Act - Action action = - () => dataTable.Should().HaveColumn("Unicorn"); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable to contain a column named *Unicorn*, but it does not."); - } - - [Fact] - public void When_data_table_has_all_expected_columns_it_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - var existingColumnNames = dataTable.Columns.Cast() - .Select(column => column.ColumnName); - - // Act & Assert - dataTable.Should().HaveColumns(existingColumnNames); - } - - [Fact] - public void Null_data_table_has_no_columns_and_fails_the_test() - { - // Arrange - var actual = (DataTable)null; - - var existingColumnName = "Does not matter"; - - // Act - Action act = () => - { - using var _ = new AssertionScope(); - actual.Should().HaveColumns(existingColumnName); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected actual to contain*column*with specific name*, but found *"); - } - - [Fact] - public void When_data_table_has_only_some_expected_columns_then_asserting_that_it_has_all_of_them_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - var columnNames = dataTable.Columns.Cast() - .Select(column => column.ColumnName) - .Concat(new[] { "Unicorn" }); - - // Act - Action action = - () => dataTable.Should().HaveColumns(columnNames); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable to contain a column named *Unicorn*, but it does not."); - } - - [Fact] - public void When_data_table_has_none_of_the_expected_columns_then_asserting_that_it_has_all_of_them_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - var nonExistingColumnNames = new[] { "Unicorn", "Dragon" }; - - // Act - Action action = - () => dataTable.Should().HaveColumns(nonExistingColumnNames); - - // Assert - action.Should().Throw() - .WithMessage("Expected dataTable to contain a column named *Unicorn*, but it does not."); - } -} diff --git a/Tests/FluentAssertions.Equivalency.Specs/FluentAssertions.Equivalency.Specs.csproj b/Tests/FluentAssertions.Equivalency.Specs/FluentAssertions.Equivalency.Specs.csproj index a3b8f16c2f..17f0ed9e6b 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/FluentAssertions.Equivalency.Specs.csproj +++ b/Tests/FluentAssertions.Equivalency.Specs/FluentAssertions.Equivalency.Specs.csproj @@ -60,7 +60,6 @@ - runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Tests/FluentAssertions.Equivalency.Specs/TypedDataSetSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/TypedDataSetSpecs.cs deleted file mode 100644 index b3ad964315..0000000000 --- a/Tests/FluentAssertions.Equivalency.Specs/TypedDataSetSpecs.cs +++ /dev/null @@ -1,576 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using Xunit; -using Xunit.Sdk; - -namespace FluentAssertions.Equivalency.Specs; - -public class TypedDataSetSpecs : DataSpecs -{ - [Fact] - public void When_DataSets_are_identical_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2); - } - - [Fact] - public void When_DataSets_are_both_null_it_should_succeed() - { - // Act & Assert - ((TypedDataSet)null).Should().BeEquivalentTo(null); - } - - [Fact] - public void When_DataSet_is_null_and_isnt_expected_to_be_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - // Act - Action action = () => ((TypedDataSet)null).Should().BeEquivalentTo(dataSet); - - // Assert - action.Should().Throw().WithMessage( - "Expected *to be non-null, but found null*"); - } - - [Fact] - public void When_DataSet_is_expected_to_be_null_and_isnt_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - // Act - Action action = () => dataSet.Should().BeEquivalentTo(null); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DataSet_type_does_not_match_and_AllowMismatchedType_not_enabled_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataSetOfMismatchedType = new TypedDataSetSubclass(dataSet); - - // Act - Action action = () => dataSet.Should().BeEquivalentTo(dataSetOfMismatchedType); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DataSet_type_does_not_match_and_AllowMismatchedType_is_enabled_it_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataSetOfMismatchedType = new TypedDataSetSubclass(dataSet); - - // Act & Assert - dataSet.Should().BeEquivalentTo(dataSetOfMismatchedType, options => options.AllowingMismatchedTypes()); - } - - [Fact] - public void When_DataSetName_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.DataSetName += "different"; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DataSetName_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.DataSetName += "different"; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .Excluding(dataSet => dataSet.DataSetName) - .ExcludingRelated((DataRelation dataRelation) => dataRelation.DataSet)); - } - - [Fact] - public void When_CaseSensitive_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.CaseSensitive = !dataSet2.CaseSensitive; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_CaseSensitive_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.CaseSensitive = !dataSet2.CaseSensitive; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.CaseSensitive)); - } - - [Fact] - public void When_EnforceConstraints_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.EnforceConstraints = !dataSet2.EnforceConstraints; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_EnforceConstraints_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.EnforceConstraints = !dataSet2.EnforceConstraints; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.EnforceConstraints)); - } - - [Fact] - public void When_HasErrors_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.TypedDataTable1.Rows[0].RowError = "Manually added error"; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2, config => config.ExcludingTable("TypedDataTable1")); - - // Assert - action.Should().Throw().Which.Message.Should().Contain("HasErrors"); - } - - [Fact] - public void When_HasErrors_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.TypedDataTable1.Rows[0].RowError = "Manually added error"; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, - config => config.Excluding(dataSet => dataSet.HasErrors).ExcludingTable("TypedDataTable1")); - } - - [Fact] - public void When_HasErrors_does_not_match_and_property_is_excluded_as_params_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.TypedDataTable1.Rows[0].RowError = "Manually added error"; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, - config => config.Excluding(dataSet => dataSet.HasErrors).ExcludingTables("TypedDataTable1")); - } - - [Fact] - public void When_HasErrors_does_not_match_and_property_is_excluded_as_list_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.TypedDataTable1.Rows[0].RowError = "Manually added error"; - - // Act & Assert - IEnumerable excludedTables = new[] { "TypedDataTable1" }; - - dataSet1.Should().BeEquivalentTo(dataSet2, - config => config.Excluding(dataSet => dataSet.HasErrors).ExcludingTables(excludedTables)); - } - - [Fact] - public void When_Locale_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Locale = new CultureInfo("fr-CA"); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Locale_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Locale = new CultureInfo("fr-CA"); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.Locale)); - } - - [Fact] - public void When_Namespace_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Namespace += "different"; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Namespace_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Namespace += "different"; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .Excluding(dataSet => dataSet.Namespace) - .ExcludingRelated((DataTable dataTable) => dataTable.Namespace) - .ExcludingRelated((DataColumn dataColumn) => dataColumn.Namespace)); - } - - [Fact] - public void When_Prefix_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Prefix += "different"; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Prefix_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Prefix += "different"; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.Prefix)); - } - - [Fact] - public void When_RemotingFormat_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.RemotingFormat = - dataSet2.RemotingFormat == SerializationFormat.Binary - ? SerializationFormat.Xml - : SerializationFormat.Binary; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_RemotingFormat_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.RemotingFormat = - dataSet2.RemotingFormat == SerializationFormat.Binary - ? SerializationFormat.Xml - : SerializationFormat.Binary; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .Excluding(dataSet => dataSet.RemotingFormat) - .ExcludingRelated(dataTable => dataTable.RemotingFormat)); - } - - [Fact] - public void When_SchemaSerializationMode_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.SchemaSerializationMode = - dataSet2.SchemaSerializationMode == SchemaSerializationMode.ExcludeSchema - ? SchemaSerializationMode.IncludeSchema - : SchemaSerializationMode.ExcludeSchema; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_SchemaSerializationMode_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.SchemaSerializationMode = - dataSet2.SchemaSerializationMode == SchemaSerializationMode.ExcludeSchema - ? SchemaSerializationMode.IncludeSchema - : SchemaSerializationMode.ExcludeSchema; - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.SchemaSerializationMode)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_ExtendedProperties_do_not_match_and_property_is_not_excluded_it_should_fail(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - ApplyChange(dataSet2.ExtendedProperties, changeType); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_ExtendedProperties_do_not_match_and_property_is_excluded_it_should_succeed(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - ApplyChange(dataSet2.ExtendedProperties, changeType); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options.Excluding(dataSet => dataSet.ExtendedProperties)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - [SuppressMessage("Style", "IDE0010:Add missing cases", Justification = "All enum values are accounted for.")] - public void When_Relations_does_not_match_and_property_is_not_excluded_it_should_fail(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - switch (changeType) - { - case ChangeType.Added: - dataSet1.Relations.RemoveAt(0); - break; - - case ChangeType.Changed: - dataSet2.Relations[0].RelationName += "different"; - break; - - case ChangeType.Removed: - dataSet2.Relations.RemoveAt(0); - break; - } - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - [SuppressMessage("Style", "IDE0010:Add missing cases", Justification = "All enum values are accounted for.")] - public void When_Relations_does_not_match_and_property_is_excluded_it_should_succeed(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - switch (changeType) - { - case ChangeType.Added: - dataSet1.Relations.RemoveAt(0); - break; - - case ChangeType.Changed: - dataSet2.Relations[0].RelationName += "different"; - break; - - case ChangeType.Removed: - dataSet2.Relations.RemoveAt(0); - break; - } - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2, options => options - .Excluding(dataSet => dataSet.Relations) - .ExcludingRelated(dataTable => dataTable.ParentRelations) - .ExcludingRelated(dataTable => dataTable.ChildRelations)); - } - - [Fact] - public void When_Tables_are_the_same_but_in_a_different_order_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1, swapTableOrder: true); - - // Act & Assert - dataSet1.Should().BeEquivalentTo(dataSet2); - } - - [Fact] - public void When_Tables_count_does_not_match_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1, swapTableOrder: true); - - dataSet2.Tables.Add(new DataTable("ThirdWheel")); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw().Which.Message.Should().Contain("to contain " + dataSet2.Tables.Count); - } - - [Fact] - public void When_Tables_count_matches_but_tables_are_different_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1, swapTableOrder: true); - - dataSet2.TypedDataTable2.TableName = "DifferentTableName"; - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Tables_contain_different_data_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1, swapTableOrder: true); - - dataSet2.TypedDataTable2[0].Guid = Guid.NewGuid(); - - // Act - Action action = () => dataSet1.Should().BeEquivalentTo(dataSet2); - - // Assert - action.Should().Throw(); - } -} diff --git a/Tests/FluentAssertions.Equivalency.Specs/TypedDataTableSpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/TypedDataTableSpecs.cs deleted file mode 100644 index c084d9f02e..0000000000 --- a/Tests/FluentAssertions.Equivalency.Specs/TypedDataTableSpecs.cs +++ /dev/null @@ -1,666 +0,0 @@ -using System; -using System.Collections; -using System.Data; -using System.Globalization; -using System.Linq; -using FluentAssertions.Data; -using Xunit; -using Xunit.Sdk; - -namespace FluentAssertions.Equivalency.Specs; - -/// -/// DataTableEquivalency specs for typed data tables. -/// -public class TypedDataTableSpecs : DataSpecs -{ - [Fact] - public void When_DataTables_are_identical_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2); - } - - [Fact] - public void When_DataTables_are_both_null_it_should_succeed() - { - // Act & Assert - ((TypedDataTable1)null).Should().BeEquivalentTo(null); - } - - [Fact] - public void When_DataTable_is_null_and_isnt_expected_to_be_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - // Act - Action action = () => ((TypedDataTable1)null).Should().BeEquivalentTo(dataTable); - - // Assert - action.Should().Throw().WithMessage( - "Expected *to be non-null, but found null*"); - } - - [Fact] - public void When_DataTable_is_expected_to_be_null_and_isnt_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(); - - var dataTable = dataSet.TypedDataTable1; - - // Act - Action action = () => dataTable.Should().BeEquivalentTo(null); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DataTable_type_does_not_match_and_AllowMismatchedType_not_enabled_it_should_fail() - { - // Arrange - var dataSet = CreateDummyDataSet(identicalTables: true); - var dataSet2 = new TypedDataSetSubclass(dataSet); - - var dataTable = dataSet.TypedDataTable1; - var dataTableOfMismatchedType = dataSet2.TypedDataTable2; - - dataSet2.Tables.Remove(dataTable.TableName); - dataTableOfMismatchedType.TableName = dataTable.TableName; - - // Act - Action action = () => dataTable.Should().BeEquivalentTo(dataTableOfMismatchedType); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DataTable_type_does_not_match_and_AllowMismatchedType_is_enabled_it_should_succeed() - { - // Arrange - var dataSet = CreateDummyDataSet(identicalTables: true); - var dataSet2 = new TypedDataSetSubclass(dataSet); - - var dataTable = dataSet.TypedDataTable1; - var dataTableOfMismatchedType = dataSet2.TypedDataTable2; - - dataSet2.Tables.Remove(dataTable.TableName); - dataTableOfMismatchedType.TableName = dataTable.TableName; - - dataTableOfMismatchedType.Rows.Clear(); - - foreach (var row in dataTable) - { - dataTableOfMismatchedType.ImportRow(row); - } - - foreach (var col in dataTableOfMismatchedType.Columns.Cast()) - { - col.ExtendedProperties.Clear(); - - foreach (var property in dataTable.Columns[col.ColumnName].ExtendedProperties.Cast()) - { - col.ExtendedProperties.Add(property.Key, property.Value); - } - } - - dataTableOfMismatchedType.AcceptChanges(); - - // Act & Assert - dataTable.Should().BeEquivalentTo(dataTableOfMismatchedType, options => options.AllowingMismatchedTypes()); - } - - [Fact] - public void When_TableName_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.TableName += "different"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_TableName_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(identicalTables: true); - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.TableName += "different"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo( - dataTable2, - options => options - .Excluding(dataTable => dataTable.TableName) - .ExcludingRelated((DataColumn dataColumn) => dataColumn.Table) - .ExcludingRelated((Constraint constraint) => constraint.Table)); - } - - [Fact] - public void When_CaseSensitive_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.CaseSensitive = !dataSet2.CaseSensitive; - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_CaseSensitive_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.CaseSensitive = !dataSet2.CaseSensitive; - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.CaseSensitive)); - } - - [Fact] - public void When_DisplayExpression_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.DisplayExpression = dataTable2.StringColumn.ColumnName; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_DisplayExpression_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.DisplayExpression = dataTable2.StringColumn.ColumnName; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.DisplayExpression)); - } - - [Fact] - public void When_HasErrors_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.Rows[0].RowError = "Manually added error"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw().Which.Message.Should().Contain("HasErrors"); - } - - [Fact] - public void When_HasErrors_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.Rows[0].RowError = "Manually added error"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, config => config - .Excluding(dataTable => dataTable.HasErrors) - .ExcludingRelated((DataRow dataRow) => dataRow.HasErrors)); - } - - [Fact] - public void When_Locale_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Locale = new CultureInfo("fr-CA"); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Locale_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Locale = new CultureInfo("fr-CA"); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.Locale)); - } - - [Fact] - public void When_Namespace_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Namespace += "different"; - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Namespace_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.Namespace += "different"; - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.Namespace) - .ExcludingRelated((DataColumn dataColumn) => dataColumn.Namespace)); - } - - [Fact] - public void When_Prefix_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.Prefix += "different"; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_Prefix_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - dataTable2.Prefix += "different"; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.Prefix)); - } - - [Fact] - public void When_RemotingFormat_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.RemotingFormat = - dataSet2.RemotingFormat == SerializationFormat.Binary - ? SerializationFormat.Xml - : SerializationFormat.Binary; - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_RemotingFormat_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - dataSet2.RemotingFormat = - dataSet2.RemotingFormat == SerializationFormat.Binary - ? SerializationFormat.Xml - : SerializationFormat.Binary; - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.RemotingFormat)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_Columns_do_not_match_and_property_is_not_excluded_it_should_fail(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.Columns, changeType); - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_Columns_do_not_match_and_Columns_and_Rows_are_excluded_it_should_succeed(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.Columns, changeType); - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.Columns) - .Excluding(dataTable => dataTable.Rows)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_ExtendedProperties_do_not_match_and_property_is_not_excluded_it_should_fail(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.ExtendedProperties, changeType); - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_ExtendedProperties_do_not_match_and_property_is_excluded_it_should_succeed(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.ExtendedProperties, changeType); - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.ExtendedProperties)); - } - - [Fact] - public void When_PrimaryKey_does_not_match_and_property_is_not_excluded_it_should_fail() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - dataTable2.PrimaryKey = dataTable2.Columns.Cast().Skip(2).ToArray(); - dataTable2.Columns[0].Unique = true; - - // Act - Action action = () => - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.Constraints)); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void When_PrimaryKey_does_not_match_and_property_is_excluded_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - for (int i = 2; i < dataSet1.TypedDataTable2.Columns.Count; i++) - { - dataSet1.TypedDataTable2.Columns[i].AllowDBNull = false; - } - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable2; - var dataTable2 = dataSet2.TypedDataTable2; - - dataTable2.PrimaryKey = dataTable2.Columns.Cast().Skip(2).ToArray(); - dataTable2.Columns[0].Unique = true; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.PrimaryKey) - .Excluding(dataTable => dataTable.Constraints)); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_Constraints_do_not_match_and_property_is_not_excluded_it_should_fail(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.Constraints, dataTable2.DecimalColumn, changeType); - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Theory] - [MemberData(nameof(AllChangeTypes))] - public void When_Constraints_do_not_match_and_property_is_excluded_it_should_succeed(ChangeType changeType) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.Constraints, dataTable2.DecimalColumn, changeType); - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options - .Excluding(dataTable => dataTable.Constraints) - .ExcludingRelated(dataColumn => dataColumn.Unique)); - } - - [Theory] - [MemberData(nameof(AllChangeTypesWithAcceptChangesValues))] - public void When_Rows_do_not_match_and_property_is_not_excluded_it_should_fail(ChangeType changeType, bool acceptChanges) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.Rows, dataTable2, changeType); - - if (acceptChanges) - { - dataTable2.AcceptChanges(); - } - - // Act - Action action = () => dataTable1.Should().BeEquivalentTo(dataTable2); - - // Assert - action.Should().Throw(); - } - - [Theory] - [MemberData(nameof(AllChangeTypesWithAcceptChangesValues))] - public void When_Rows_do_not_match_and_property_is_excluded_it_should_succeed(ChangeType changeType, bool acceptChanges) - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - ApplyChange(dataTable2.Rows, dataTable2, changeType); - - if (acceptChanges) - { - dataTable2.AcceptChanges(); - } - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.Excluding(dataTable => dataTable.Rows)); - } - - [Fact] - public void When_data_matches_in_different_order_and_RowMatchMode_is_PrimaryKey_it_should_succeed() - { - // Arrange - var dataSet1 = CreateDummyDataSet(); - - var dataSet2 = new TypedDataSetSubclass(dataSet1, randomizeRowOrder: true); - - var dataTable1 = dataSet1.TypedDataTable1; - var dataTable2 = dataSet2.TypedDataTable1; - - // Act & Assert - dataTable1.Should().BeEquivalentTo(dataTable2, options => options.UsingRowMatchMode(RowMatchMode.PrimaryKey)); - } -} diff --git a/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionSpecs.cs deleted file mode 100644 index e59f3e6979..0000000000 --- a/Tests/FluentAssertions.Specs/Collections/Data/DataColumnCollectionAssertionSpecs.cs +++ /dev/null @@ -1,435 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using Xunit; -using Xunit.Sdk; - -namespace FluentAssertions.Specs.Collections.Data; - -public static class DataColumnCollectionAssertionSpecs -{ - public class BeSameAs - { - [Fact] - public void Succeeds_for_references_to_the_same_object() - { - // Arrange - var dataTable = new DataTable("Test"); - - var columnCollection1 = dataTable.Columns; - var columnCollection2 = columnCollection1; - - // Act & Assert - columnCollection1.Should().BeSameAs(columnCollection2); - } - - [Fact] - public void Throws_for_different_references() - { - // 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 deleted file mode 100644 index 6780b8a2c5..0000000000 --- a/Tests/FluentAssertions.Specs/Collections/Data/DataRowCollectionAssertionSpecs.cs +++ /dev/null @@ -1,625 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -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 deleted file mode 100644 index c33decc33b..0000000000 --- a/Tests/FluentAssertions.Specs/Collections/Data/DataTableCollectionAssertionSpecs.cs +++ /dev/null @@ -1,539 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -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/Tests/FluentAssertions.Specs/FluentAssertions.Specs.csproj b/Tests/FluentAssertions.Specs/FluentAssertions.Specs.csproj index eee4d5e48c..295b1b5d1c 100644 --- a/Tests/FluentAssertions.Specs/FluentAssertions.Specs.csproj +++ b/Tests/FluentAssertions.Specs/FluentAssertions.Specs.csproj @@ -63,7 +63,6 @@ - runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/docs/_pages/data.md b/docs/_pages/data.md deleted file mode 100644 index bd7ce15f47..0000000000 --- a/docs/_pages/data.md +++ /dev/null @@ -1,193 +0,0 @@ ---- -title: System.Data -permalink: /data/ -layout: single -classes: wide -sidebar: - nav: "sidebar" ---- - -Fluent Assertions can be used to assert equivalence of System.Data types such as `DataSet` and `DataTable`. - -## Basic Assertions - -As with other reference types, you can assert a value of any of the core System.Data types to be null or not null: - -```csharp -DataSet result = ...; - -result.Should().NotBeNull(); -``` - -You can also assert that two `DataSet` objects contain equivalent configuration and data, which, by default, will compare the rows contained by `DataTable` objects by their index within the collection. -Like this: - -```csharp -var expected = GetExpectedDataSet(); -var actual = GetActualDataSet(); - -actual.Should().BeEquivalentTo(expected); -``` - -The `BeEquivalentTo` test can be applied to `DataTable`, `DataColumn` and `DataRow` objects as well: - -```csharp -actual.Tables["First"].Should().BeEquivalentTo(expected.Tables["First"]); -``` - -Chaining additional assertions is supported as well. - -```csharp -dataTable.Should().HaveColumns("FirstName", "LastName") - .And.Should().HaveRowCount(3); -``` - -## `DataSet` Assertions - -The following assertions are available on `DataSet` objects: - -* `.Should().HaveTableCount(n)`: Asserts that the `DataSet`'s `Tables` collection has the expected number of members. -* `.Should().HaveTable(tableName)`, `.Should().HaveTables(tableName, tableName, ...)`: Asserts that the `DataSet`'s `Tables` collection contains at least tables with the specified names. Additional tables are ignored. -* `.Should().BeEquivalentTo(dataSet)`: Performs a deep equivalency comparison between the subject and the expectation. - -## `DataTable` Assertions - -The following assertions are available on `DataTable` objects: - -* `.Should().HaveColumn(columnName)`, `.Should().HaveColumns(columnName, columnName, ...)`: Asserts that the `DataTable`'s `Columns` collection contains at least columns with the specified names. Additional columns are ignored. -* `.Should().HaveRowCount(n)`: Asserts that the `DataTable`'s `Rows` collection has the expected number of elements. -* `.Should().BeEquivalentTo(dataTable)`: Performs a deep equivalency comparison between the subject and the expectation. - -When comparing the rows of a `DataTable`, by default the rows are matched by their index in the `Rows` collection. But, if the subject and expectation tables contain equivalent `PrimaryKey` values, then it is possible to match the rows by their primary key field data, irrespective of the row order within the `Rows` collection. See "Equivalency Assertion Options" below for how to configure this. - -## `DataColumn` Assertions - -The following assertions are available on `DataColumn` objects: - -* `.Should().BeEquivalentTo(dataColumn)`: Performs a deep equivalency comparison between the subject and the expectation. - -## `DataRow` Assertions - -The following assertions are available on `DataRow` objects: - -* `.Should().HaveColumn(columnName)`, `.Should().HaveColumns(columnName, columnName, ...)`: Asserts that the `DataTable`'s `Columns` collection contains at least columns with the specified names. Additional columns are ignored. -* `.Should().BeEquivalentTo(dataRow)`: Performs a deep equivalency comparison between the subject and the expectation. This includes comparing field values, for which the defined columns must match. - -When checking the equivalency of two `DataRow` objects, by default the `RowState` must match. But, if this is overridden using equivalency assertion options (`.Excluding(row => row.RowState)`), two `DataRow` objects with differing `RowState`s can still be considered equivalent based on their field values. FluentAssertions automatically determines which _version_ of field values to use in the subject and the expectation separately. - -* For `DataRowState.Unchanged`, field values for `DataRowVersion.Current` are used. -* For `DataRowState.Added`, field values for `DataRowVersion.Current` are used. -* For `DataRowState.Deleted`, field values for `DataRowVersion.Original` are used. -* For `DataRowState.Modified`, field values for `DataRowVersion.Current` are used. - -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. - -In addition to standard equivalency assertion options, which are applied recursively to all subjects found in the object graph, the following options are available that are specific to equivalency tests for supported `System.Data` types: - -* `.AllowingMismatchedTypes()`: Allows objects with equivalent data to be considered equivalent, even if their data types do not match. See "Typed `DataSet`, `DataTable`, `DataRow` objects" below. -* `.IgnoringUnmatchedColumns()`: Allows tables to be equivalent if one table has columns that the other does not. The column definitions and row data for these columns is ignored. -* `.UsingRowMatchMode(Index | PrimaryKey)`: Specifies the manner in which rows in two `DataTable`s should be matched up for equivalency testing. -* `.ExcludingOriginalData()`: Specifies that when comparing two `DataRow` objects whose `RowState` is both `Modified`, only the `Current` value of fields should be compared, ignoring any differences in the `Original` versions of those fields. -* `.Excluding(x => x.Member)`: Excludes the specified member of the subject type from comparison. This method can only be used to select members accessible from the subject type directly. -* `.ExcludingRelated((DataRelation x) => x.Member)`: -* `.ExcludingRelated((DataTable x) => x.Member)`: -* `.ExcludingRelated((DataColumn x) => x.Member)`: -* `.ExcludingRelated((DataRow x) => x.Member)`: -* `.ExcludingRelated((DataConstraint x) => x.Member)`: Excludes the specified member of a related System.Data type from comparison. This is to handle the case where a change to one object within a `DataSet` causes corresponding changes automatically in other places. For instance, setting `Unique` to `true` in a `DataColumn` has a side-effect of adding a new `UniqueConstraint` to the `Constraints` collection of the containing `DataTable`. -* `.ExcludingTable(tableName)`, `.ExcludingTables(tableName, tableName, ...)`: Excludes tables with the specified name(s) from comparison. -* `.ExcludingColumnInAllTables(columnName)`, `.ExcludingColumnsInAllTables(columnName, columnName, ...)`: Excludes all columns in any table within the `DataSet` with the specified name(s) from comparison. -* `.ExcludingColumn(tableName, columnName)`, `.ExcludingColumns(tableName, columnName, columnName, ...)`: Excludes the specified column(s) in tables with a specific name within the `DataSet`s from comparison. -* `.ExcludingColumn(dataColumn)`, `.ExcludingColumns(dataColumn, dataColumn, ...`): Excludes the specified column(s) in tables with names matching the owner `DataTable` of the supplied `DataColumn` object(s) from comparison. This method is supplied because with typed `DataTable` objects, it is a common pattern that accessors for `DataColumn` objects are provided. - -These configuration methods follow a fluent initialization pattern; they return the same options object they were called on, so that configuration can be chained in a single expression. - -See the "Examples" section for some uses of equivalency options. - -## Typed `DataSet`, `DataTable`, `DataRow` objects - -If some of your `DataSet`, `DataTable` or `DataRow` objects are _typed_ objects (e.g. `DataTable` classes that inherit from `TypedTableBase`), by default, equivalency tests will fail if the data types do not also match. If you want to compare typed objects with untyped objects that otherwise contain equivalent data, then the option `AllowingMismatchedTypes` can be used: - -```csharp -DataSet expected = GetExpectedDataSet(); -EmployeeData actual = service.GetEmployeeData(); - -actual.Should().BeEquivalentTo(expected, options => options.AllowingMismatchedTypes()); -``` - -Apart from the default check for matching types, whether a `DataSet`, `DataTable` or `DataRow` is a vanilla object or an instance of a custom subtype is irrelevant for the purposes of comparison. - -## Examples - -Asserting that a `DataTable` has certain columns: - -```csharp -var table = GetDataTable(); - -MyTypedTableType templateTable = GetExpectedDataTable(); - -table.Should().HaveColumn("FirstName"); - -table.Should().HaveColumns(templateTable.FirstNameColumn, templateTable.LastNameColumn); -``` - -Excluding tables and columns from equivalency tests: - -> You can exclude a column from consideration by name across all tables in a `DataSet`, or from a specific `DataTable`. - -```csharp -var expected = GetExpectedDataSet(); -var actual = GetActualDataSet(); - -actual.Should().BeEquivalentTo(expected, options => options - .ExcludingTable("Employees") - .ExcludingColumnInAllTables("EmployeeID") - .ExcludingColumn(tableName: "Employees", columnName: "Address")); -``` - -Excluding fields from types other than the subject: - -> `DataSet` objects have a hierarchy of objects representing the data and many interrelations between these objects. For instance, setting `Unique` to `true` in a `DataColumn` has a side-effect of adding a new `UniqueConstraint` to the `Constraints` collection of the containing `DataTable`. As such, to eliminate side-effects it may be necessary to ignore additional properties of types related to the subject. To support this, a method `ExcludingRelated` can be used that allows members to be selected on any related type. - -```csharp -var expected = GetExpectedDataSet(); -var actual = GetActualDataSet(); - -actual.Should().BeEquivalentTo(expected, options => options - .Excluding(dataSet => dataSet.DataSetName) - .ExcludingRelated((DataRelation relation) => relation.DataSet); -``` - -Matching the rows of `DataTable`s by their primary key values: - -> When comparing the rows of a `DataTable`, by default, rows are expected to be occur at the same indices. If a `DataTable` has a `PrimaryKey` set, then it is possible to instead match rows by their primary key, irrespective of the order in which they occur. - -```csharp -var expected = GetExpectedDataTable(); -var actual = GetActualDataTable(); - -actual.Should().BeEquivalentTo(expected, options => options.UsingRowMatchMode(RowMatchMode.PrimaryKey)); -``` diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md index 11faf69f04..bfdac56010 100644 --- a/docs/_pages/releases.md +++ b/docs/_pages/releases.md @@ -17,6 +17,8 @@ sidebar: ### Breaking Changes (for users) +* Moved support for `DataSet`, `DataTable`, `DataRow` and `DataColumn` into a new package `FluentAssertions.DataSet` - [#2267](https://github.com/fluentassertions/fluentassertions/pull/2267) + ### Breaking Changes (for extensions) ## 6.12.0