Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #22856 from hughbe/dataset-extensions-tests
Browse files Browse the repository at this point in the history
Fix porting bug for argument validation in DataSetExtensions
  • Loading branch information
stephentoub authored Aug 2, 2017
2 parents 1fabf6a + 6ab3f8d commit dd38e6f
Show file tree
Hide file tree
Showing 11 changed files with 501 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,10 @@ private static bool CompareArray(Array a, Array b)

private static bool CompareEquatableArray<TElem>(TElem[] a, TElem[] b) where TElem : IEquatable<TElem>
{
if (ReferenceEquals(a, b))
{
return true;
}

if (ReferenceEquals(a, null) ||
ReferenceEquals(b, null))
{
return false;
}

if (a.Length != b.Length)
{
return false;
}
Debug.Assert(!ReferenceEquals(a, b));
Debug.Assert(a != null);
Debug.Assert(b != null);
Debug.Assert(a.Length == b.Length);

for (int i = 0; i < a.Length; ++i)
{
Expand Down Expand Up @@ -187,7 +176,7 @@ public bool Equals(TRow leftRow, TRow rightRow)
/// <returns>HashCode for row based on values in the row.</returns>
public int GetHashCode(TRow row)
{
DataSetUtil.CheckArgumentNull(nameof(row), "row");
DataSetUtil.CheckArgumentNull(row, nameof(row));

if (row.RowState == DataRowState.Deleted)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class DataRowExtensions
/// <returns>The DataRow value for the column specified.</returns>
public static T Field<T>(this DataRow row, string columnName)
{
DataSetUtil.CheckArgumentNull(nameof(row), "row");
DataSetUtil.CheckArgumentNull(row, nameof(row));
return UnboxT<T>.s_unbox(row[columnName]);
}

Expand All @@ -38,7 +38,7 @@ public static T Field<T>(this DataRow row, string columnName)
/// <returns>The DataRow value for the column specified.</returns>
public static T Field<T>(this DataRow row, DataColumn column)
{
DataSetUtil.CheckArgumentNull(nameof(row), "row");
DataSetUtil.CheckArgumentNull(row, nameof(row));;
return UnboxT<T>.s_unbox(row[column]);
}

Expand All @@ -53,7 +53,7 @@ public static T Field<T>(this DataRow row, DataColumn column)
/// <returns>The DataRow value for the column specified.</returns>
public static T Field<T>(this DataRow row, int columnIndex)
{
DataSetUtil.CheckArgumentNull(nameof(row), "row");
DataSetUtil.CheckArgumentNull(row, nameof(row));;
return UnboxT<T>.s_unbox(row[columnIndex]);
}

Expand All @@ -69,7 +69,7 @@ public static T Field<T>(this DataRow row, int columnIndex)
/// <returns>The DataRow value for the column specified.</returns>
public static T Field<T>(this DataRow row, int columnIndex, DataRowVersion version)
{
DataSetUtil.CheckArgumentNull(nameof(row), "row");
DataSetUtil.CheckArgumentNull(row, nameof(row));;
return UnboxT<T>.s_unbox(row[columnIndex, version]);
}

Expand All @@ -85,7 +85,7 @@ public static T Field<T>(this DataRow row, int columnIndex, DataRowVersion versi
/// <returns>The DataRow value for the column specified.</returns>
public static T Field<T>(this DataRow row, string columnName, DataRowVersion version)
{
DataSetUtil.CheckArgumentNull(nameof(row), "row");
DataSetUtil.CheckArgumentNull(row, nameof(row));;
return UnboxT<T>.s_unbox(row[columnName, version]);
}

Expand All @@ -101,7 +101,7 @@ public static T Field<T>(this DataRow row, string columnName, DataRowVersion ver
/// <returns>The DataRow value for the column specified.</returns>
public static T Field<T>(this DataRow row, DataColumn column, DataRowVersion version)
{
DataSetUtil.CheckArgumentNull(nameof(row), "row");
DataSetUtil.CheckArgumentNull(row, nameof(row));;
return UnboxT<T>.s_unbox(row[column, version]);
}

Expand All @@ -125,7 +125,7 @@ public static void SetField<T>(this DataRow row, int columnIndex, T value)
/// <param name="value">The new row value for the specified column.</param>
public static void SetField<T>(this DataRow row, string columnName, T value)
{
DataSetUtil.CheckArgumentNull(nameof(row), "row");
DataSetUtil.CheckArgumentNull(row, nameof(row));;
row[columnName] = (object)value ?? DBNull.Value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class DataTableExtensions
/// <returns>IEnumerable of datarows.</returns>
public static EnumerableRowCollection<DataRow> AsEnumerable(this DataTable source)
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
return new EnumerableRowCollection<DataRow>(source);
}

Expand All @@ -38,7 +38,7 @@ public static EnumerableRowCollection<DataRow> AsEnumerable(this DataTable sourc
public static DataTable CopyToDataTable<T>(this IEnumerable<T> source)
where T : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
return LoadTableFromEnumerable(source, table: null, options: null, errorHandler: null);
}

Expand All @@ -48,8 +48,8 @@ public static DataTable CopyToDataTable<T>(this IEnumerable<T> source)
public static void CopyToDataTable<T>(this IEnumerable<T> source, DataTable table, LoadOption options)
where T : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(nameof(table), "table");
DataSetUtil.CheckArgumentNull(source, nameof(source));
DataSetUtil.CheckArgumentNull(table, nameof(table));
LoadTableFromEnumerable(source, table, options, errorHandler: null);
}

Expand Down Expand Up @@ -77,8 +77,8 @@ public static void CopyToDataTable<T>(this IEnumerable<T> source, DataTable tabl
public static void CopyToDataTable<T>(this IEnumerable<T> source, DataTable table, LoadOption options, FillErrorEventHandler errorHandler)
where T : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(nameof(table), "table");
DataSetUtil.CheckArgumentNull(source, nameof(source));
DataSetUtil.CheckArgumentNull(table, nameof(table));
LoadTableFromEnumerable(source, table, options, errorHandler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ internal void AddSortExpression<TKey>(Func<TRow, TKey> keySelector, bool isDesce
/// </summary>
internal void AddSortExpression<TKey>(Func<TRow, TKey> keySelector, IComparer<TKey> comparer, bool isDescending, bool isOrderBy)
{
DataSetUtil.CheckArgumentNull(nameof(keySelector), "keySelector");
DataSetUtil.CheckArgumentNull(nameof(comparer), "comparer");
DataSetUtil.CheckArgumentNull(keySelector, nameof(keySelector));
DataSetUtil.CheckArgumentNull(comparer, nameof(comparer));

_sortExpression.Add(
delegate (TRow input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class TypedTableBaseExtensions
/// </summary>
public static EnumerableRowCollection<TRow> Where<TRow>(this TypedTableBase<TRow> source, Func<TRow, bool> predicate) where TRow : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
EnumerableRowCollection<TRow> erc = new EnumerableRowCollection<TRow>(source);
return erc.Where(predicate);
}
Expand All @@ -27,7 +27,7 @@ public static EnumerableRowCollection<TRow> Where<TRow>(this TypedTableBase<TRow
/// </summary>
public static OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey>(this TypedTableBase<TRow> source, Func<TRow, TKey> keySelector) where TRow : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
EnumerableRowCollection<TRow> erc = new EnumerableRowCollection<TRow>(source);
return erc.OrderBy(keySelector);
}
Expand All @@ -40,7 +40,7 @@ public static OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey>(
Func<TRow, TKey> keySelector,
IComparer<TKey> comparer) where TRow : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
EnumerableRowCollection<TRow> erc = new EnumerableRowCollection<TRow>(source);
return erc.OrderBy(keySelector, comparer);
}
Expand All @@ -50,7 +50,7 @@ public static OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey>(
/// </summary>
public static OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>(this TypedTableBase<TRow> source, Func<TRow, TKey> keySelector) where TRow : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
EnumerableRowCollection<TRow> erc = new EnumerableRowCollection<TRow>(source);
return erc.OrderByDescending(keySelector);
}
Expand All @@ -63,7 +63,7 @@ public static OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>
Func<TRow, TKey> keySelector,
IComparer<TKey> comparer) where TRow : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
EnumerableRowCollection<TRow> erc = new EnumerableRowCollection<TRow>(source);
return erc.OrderByDescending(keySelector, comparer);
}
Expand All @@ -76,7 +76,7 @@ public static OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>
/// </summary>
public static EnumerableRowCollection<S> Select<TRow, S>(this TypedTableBase<TRow> source, Func<TRow, S> selector) where TRow : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
EnumerableRowCollection<TRow> erc = new EnumerableRowCollection<TRow>(source);
return erc.Select(selector);
}
Expand All @@ -88,7 +88,7 @@ public static EnumerableRowCollection<S> Select<TRow, S>(this TypedTableBase<TRo
/// <returns>IEnumerable of datarows.</returns>
public static EnumerableRowCollection<TRow> AsEnumerable<TRow>(this TypedTableBase<TRow> source) where TRow : DataRow
{
DataSetUtil.CheckArgumentNull(nameof(source), "source");
DataSetUtil.CheckArgumentNull(source, nameof(source));
return new EnumerableRowCollection<TRow>(source as DataTable);
}

Expand Down
23 changes: 0 additions & 23 deletions src/System.Data.DataSetExtensions/tests/SmokeTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="SmokeTest.cs" />
<Compile Include="System\Data\DataRowComparerTests.cs" />
<Compile Include="System\Data\DataRowExtensionsTests.cs" />
<Compile Include="System\Data\DataTableExtensionsTests.cs" />
<Compile Include="System\Data\TypedTableBaseExtensionsTests.cs" />
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>Common\System\PlatformDetection.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
Loading

0 comments on commit dd38e6f

Please sign in to comment.