• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fluentassertions / fluentassertions.datasets / 13245501597

10 Feb 2025 04:22PM UTC coverage: 94.362% (+0.3%) from 94.089%
13245501597

Pull #24

github

web-flow
Bump Verify.Xunit from 28.9.0 to 28.10.1 in the xunit group

Bumps the xunit group with 1 update: [Verify.Xunit](https://github.com/VerifyTests/Verify).


Updates `Verify.Xunit` from 28.9.0 to 28.10.1
- [Release notes](https://github.com/VerifyTests/Verify/releases)
- [Commits](https://github.com/VerifyTests/Verify/compare/28.9.0...28.10.1)

---
updated-dependencies:
- dependency-name: Verify.Xunit
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: xunit
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #24: Bump Verify.Xunit from 28.9.0 to 28.10.1 in the xunit group

458 of 498 branches covered (91.97%)

Branch coverage included in aggregate %.

1266 of 1329 relevant lines covered (95.26%)

2324.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.04
/Src/FluentAssertions.DataSets/DataRowAssertions.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Data;
4
using System.Diagnostics;
5
using System.Linq;
6
using FluentAssertions.DataSets.Common;
7
using FluentAssertions.Execution;
8
using FluentAssertions.Primitives;
9

10
namespace FluentAssertions.DataSets;
11

12
/// <summary>
13
/// Provides convenient assertion methods on a <see cref="DataRow"/> that can be
14
/// used to assert equivalency and the presence of columns.
15
/// </summary>
16
[DebuggerNonUserCode]
17
public class DataRowAssertions<TDataRow> : ReferenceTypeAssertions<TDataRow, DataRowAssertions<TDataRow>>
18
    where TDataRow : DataRow
19
{
20
    public DataRowAssertions(TDataRow dataRow, AssertionChain assertionChain)
21
        : base(dataRow, assertionChain)
50✔
22
    {
23
    }
50✔
24

25
    /// <summary>
26
    /// Asserts that an instance of <see cref="DataRow"/> has a column with the expected column name.
27
    /// </summary>
28
    /// <param name="expectedColumnName">The value that is expected in <see cref="DataColumn.ColumnName"/>.</param>
29
    /// <param name="because">
30
    /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
31
    /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
32
    /// </param>
33
    /// <param name="becauseArgs">
34
    /// Zero or more objects to format using the placeholders in <paramref name="because"/>.
35
    /// </param>
36
    public AndWhichConstraint<DataRowAssertions<TDataRow>, DataColumn> HaveColumn(string expectedColumnName, string because = "",
37
        params object[] becauseArgs)
38
    {
39
        var subjectColumn = default(DataColumn);
6✔
40

41
        if (Subject is null)
6✔
42
        {
43
            CurrentAssertionChain
2✔
44
                .BecauseOf(because, becauseArgs)
2✔
45
                .FailWith("Expected {context:DataRow} to contain a column named {0}{reason}, but found <null>.",
2✔
46
                    expectedColumnName);
2✔
47
        }
48
        else if (!Subject.Table.Columns.Contains(expectedColumnName))
4✔
49
        {
50
            CurrentAssertionChain
2✔
51
                .BecauseOf(because, becauseArgs)
2✔
52
                .FailWith("Expected {context:DataRow} to contain a column named {0}{reason}, but it does not.",
2✔
53
                    expectedColumnName);
2✔
54
        }
55
        else
56
        {
57
            subjectColumn = Subject.Table.Columns[expectedColumnName];
2✔
58
        }
59

60
        return new AndWhichConstraint<DataRowAssertions<TDataRow>, DataColumn>(this, subjectColumn);
2✔
61
    }
62

63
    /// <summary>
64
    /// Asserts that an instance of <see cref="DataRow"/> has columns with all of the supplied expected column names.
65
    /// </summary>
66
    /// <param name="expectedColumnNames">An array of values expected in <see cref="DataColumn.ColumnName"/>.</param>
67
    public AndConstraint<DataRowAssertions<TDataRow>> HaveColumns(params string[] expectedColumnNames)
68
    {
69
        return HaveColumns((IEnumerable<string>)expectedColumnNames);
6✔
70
    }
71

72
    /// <summary>
73
    /// Asserts that an instance of <see cref="DataRow"/> has columns with all of the supplied expected column names.
74
    /// </summary>
75
    /// <param name="expectedColumnNames">An <see cref="IEnumerable{T}"/> of string values expected in <see cref="DataColumn.ColumnName"/>.</param>
76
    /// <param name="because">
77
    /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
78
    /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
79
    /// </param>
80
    /// <param name="becauseArgs">
81
    /// Zero or more objects to format using the placeholders in <paramref name="because"/>.
82
    /// </param>
83
    public AndConstraint<DataRowAssertions<TDataRow>> HaveColumns(IEnumerable<string> expectedColumnNames, string because = "",
84
        params object[] becauseArgs)
85
    {
86
        CurrentAssertionChain
10✔
87
            .ForCondition(Subject is not null)
10✔
88
            .BecauseOf(because, becauseArgs)
10✔
89
            .FailWith(
10✔
90
                "Expected {context:DataRow} to be in a table containing {0} column(s) with specific names{reason}, but found <null>.",
10✔
91
                () => expectedColumnNames.Count());
12✔
92

93
        if (CurrentAssertionChain.Succeeded)
10✔
94
        {
95
            foreach (var expectedColumnName in expectedColumnNames)
68✔
96
            {
97
                CurrentAssertionChain
28✔
98
                    .ForCondition(Subject.Table.Columns.Contains(expectedColumnName))
28✔
99
                    .BecauseOf(because, becauseArgs)
28✔
100
                    .FailWith("Expected table containing {context:DataRow} to contain a column named {0}{reason}, but it does not.",
28✔
101
                        expectedColumnName);
28✔
102
            }
103
        }
104

105
        return new AndConstraint<DataRowAssertions<TDataRow>>(this);
6✔
106
    }
107

108
    /// <summary>
109
    /// Asserts that an instance of <see cref="DataRow"/> is equivalent to another.
110
    /// </summary>
111
    /// <remarks>
112
    /// Data rows are equivalent when they contain identical field data for the row they represent, and
113
    /// the following members have the same values:
114
    ///
115
    /// <list type="bullet">
116
    ///   <item><description>HasErrors</description></item>
117
    ///   <item><description>RowState</description></item>
118
    /// </list>
119
    ///
120
    /// The <see cref="DataRow"/> objects must be of the same type; if two <see cref="DataRow"/> objects
121
    /// are equivalent in all ways, except that one is part of a typed <see cref="DataTable"/> and is of a subclass
122
    /// of <see cref="DataRow"/>, then by default, they will not be considered equivalent. This can be overridden
123
    /// by using the overload that takes <see cref="IDataEquivalencyAssertionOptions{DataSet}"/>.
124
    /// </remarks>
125
    /// <param name="expectation">A <see cref="DataColumn"/> with the expected configuration.</param>
126
    /// <param name="because">
127
    /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
128
    /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
129
    /// </param>
130
    /// <param name="becauseArgs">
131
    /// Zero or more objects to format using the placeholders in <paramref name="because"/>.
132
    /// </param>
133
    public AndConstraint<DataRowAssertions<TDataRow>> BeEquivalentTo(DataRow expectation, string because = "",
134
        params object[] becauseArgs)
135
    {
136
        return BeEquivalentTo(
20✔
137
            expectation,
20✔
138
            options => options,
20✔
139
            because,
20✔
140
            becauseArgs);
20✔
141
    }
142

143
    /// <summary>
144
    /// Asserts that an instance of <see cref="DataRow"/> is equivalent to another.
145
    /// </summary>
146
    /// <remarks>
147
    /// Data rows are equivalent when they contain identical field data for the row they represent, and
148
    /// the following members have the same values:
149
    ///
150
    /// <list type="bullet">
151
    ///   <item><description>HasErrors</description></item>
152
    ///   <item><description>RowState</description></item>
153
    /// </list>
154
    ///
155
    /// <para>
156
    /// The <see cref="DataRow"/> objects must be of the same type; if two <see cref="DataRow"/> objects
157
    /// are equivalent in all ways, except that one is part of a typed <see cref="DataTable"/> and is of a subclass
158
    /// of <see cref="DataRow"/>, then by default, they will not be considered equivalent.
159
    /// </para>
160
    /// <para>
161
    /// This, as well as testing of any property can be overridden using the <paramref name="config"/> callback.
162
    /// By calling <see cref="IDataEquivalencyAssertionOptions{T}.AllowingMismatchedTypes"/>, two <see cref="DataRow"/>
163
    /// objects of differing types can be considered equivalent. Exclude specific properties using
164
    /// <see cref="IDataEquivalencyAssertionOptions{T}.Excluding(System.Linq.Expressions.Expression{Func{T, object}})"/>.
165
    /// Exclude columns of the data table (which also excludes the related field data in <see cref="DataRow"/>
166
    /// objects) using <see cref="IDataEquivalencyAssertionOptions{T}.ExcludingColumn(DataColumn)"/> or a related function.
167
    /// </para>
168
    /// </remarks>
169
    ///
170
    /// You can use <see cref="IDataEquivalencyAssertionOptions{T}.ExcludingRelated(System.Linq.Expressions.Expression{Func{DataTable, object}})"/>
171
    /// and related functions to exclude properties on other related System.Data types.
172
    /// <param name="expectation">A <see cref="DataColumn"/> with the expected configuration.</param>
173
    /// <param name="config">
174
    /// A reference to the <see cref="IDataEquivalencyAssertionOptions{DataRow}"/> configuration object that can be used
175
    /// to influence the way the object graphs are compared. You can also provide an alternative instance of the
176
    /// <see cref="IDataEquivalencyAssertionOptions{DataRow}"/> class. The global defaults are determined by the
177
    /// <see cref="AssertionConfiguration"/> class.
178
    /// </param>
179
    /// <param name="because">
180
    /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
181
    /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
182
    /// </param>
183
    /// <param name="becauseArgs">
184
    /// Zero or more objects to format using the placeholders in <paramref name="because"/>.
185
    /// </param>
186
    /// <exception cref="ArgumentNullException"><paramref name="config"/> is <see langword="null"/>.</exception>
187
    public AndConstraint<DataRowAssertions<TDataRow>> BeEquivalentTo(DataRow expectation,
188
        Func<IDataEquivalencyAssertionOptions<DataRow>, IDataEquivalencyAssertionOptions<DataRow>> config, string because = "",
189
        params object[] becauseArgs)
190
    {
191
        Guard.ThrowIfArgumentIsNull(config);
34✔
192

193
        var defaults = new DataEquivalencyAssertionOptions<DataRow>(AssertionConfiguration.Current.Equivalency.CloneDefaults<DataRow>());
34✔
194
        config(defaults);
34✔
195

196
        ((object)Subject).Should().BeEquivalentTo(expectation, _ => defaults, because, becauseArgs);
68✔
197

198
        return new AndConstraint<DataRowAssertions<TDataRow>>(this);
20✔
199
    }
200

201
    protected override string Identifier => "DataRow";
×
202
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc