Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wasm] Enable System.Data.Common tests #39463

Merged
merged 6 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyName>System.Data.Common</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -78,6 +78,8 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="System\Data\DataTableExtensions.cs" />
<Compile Include="System\Data\DataTableExtensions.Any.cs" Condition="'$(TargetsBrowser)' != 'true'" />
<Compile Include="System\Data\DataTableExtensions.Browser.cs" Condition="'$(TargetsBrowser)' == 'true'" />
<Compile Include="System\Data\DataTableClearEvent.cs" />
<Compile Include="System\Data\DataTableClearEventHandler.cs" />
<Compile Include="System\Data\DataTableCollection.cs" />
Expand Down Expand Up @@ -217,6 +219,8 @@
<Compile Include="System\Data\Common\DbParameterCollection.cs" />
<Compile Include="System\Data\Common\DbProviderFactory.cs" />
<Compile Include="System\Data\Common\DbProviderFactories.cs" />
<Compile Include="System\Data\Common\DbProviderFactories.Any.cs" Condition="'$(TargetsBrowser)' != 'true'" />
<Compile Include="System\Data\Common\DbProviderFactories.Browser.cs" Condition="'$(TargetsBrowser)' == 'true'" />
<Compile Include="System\Data\Common\DbProviderSpecificTypePropertyAttribute.cs" />
<Compile Include="System\Data\Common\DBSchemaRow.cs" />
<Compile Include="System\Data\Common\DBSchemaTable.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace System.Data.Common
{
public static partial class DbProviderFactories
{
private const string AssemblyQualifiedNameColumnName = "AssemblyQualifiedName";
private const string InvariantNameColumnName = "InvariantName";
private const string NameColumnName = "Name";
private const string DescriptionColumnName = "Description";
private const string ProviderGroupColumnName = "DbProviderFactories";

public static DbProviderFactory GetFactory(string providerInvariantName)
{
return GetFactory(providerInvariantName, throwOnError: true)!;
}

public static DbProviderFactory GetFactory(DataRow providerRow)
{
ADP.CheckArgumentNull(providerRow, nameof(providerRow));

DataColumn? assemblyQualifiedNameColumn = providerRow.Table.Columns[AssemblyQualifiedNameColumnName];
if (null == assemblyQualifiedNameColumn)
{
throw ADP.Argument(SR.ADP_DbProviderFactories_NoAssemblyQualifiedName);
}

string? assemblyQualifiedName = providerRow[assemblyQualifiedNameColumn] as string;
if (string.IsNullOrWhiteSpace(assemblyQualifiedName))
{
throw ADP.Argument(SR.ADP_DbProviderFactories_NoAssemblyQualifiedName);
}

return GetFactoryInstance(GetProviderTypeFromTypeName(assemblyQualifiedName));
}


public static DbProviderFactory? GetFactory(DbConnection connection)
{
ADP.CheckArgumentNull(connection, nameof(connection));

return connection.ProviderFactory;
}

public static DataTable GetFactoryClasses()
{
DataColumn nameColumn = new DataColumn(NameColumnName, typeof(string)) { ReadOnly = true };
DataColumn descriptionColumn = new DataColumn(DescriptionColumnName, typeof(string)) { ReadOnly = true };
DataColumn invariantNameColumn = new DataColumn(InvariantNameColumnName, typeof(string)) { ReadOnly = true };
DataColumn assemblyQualifiedNameColumn = new DataColumn(AssemblyQualifiedNameColumnName, typeof(string)) { ReadOnly = true };

DataTable toReturn = new DataTable(ProviderGroupColumnName) { Locale = CultureInfo.InvariantCulture };
toReturn.Columns.AddRange(new[] { nameColumn, descriptionColumn, invariantNameColumn, assemblyQualifiedNameColumn });
toReturn.PrimaryKey = new[] { invariantNameColumn };
foreach (var kvp in _registeredFactories)
{
DataRow newRow = toReturn.NewRow();
newRow[InvariantNameColumnName] = kvp.Key;
newRow[AssemblyQualifiedNameColumnName] = kvp.Value.FactoryTypeAssemblyQualifiedName;
newRow[NameColumnName] = string.Empty;
newRow[DescriptionColumnName] = string.Empty;
toReturn.AddRow(newRow);
}
return toReturn;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace System.Data.Common
{
public static partial class DbProviderFactories
{
public static DbProviderFactory GetFactory(string providerInvariantName)
{
throw new PlatformNotSupportedException();
}

public static DbProviderFactory GetFactory(DataRow providerRow)
{
throw new PlatformNotSupportedException();
}

public static DbProviderFactory? GetFactory(DbConnection connection)
{
throw new PlatformNotSupportedException();
}

public static DataTable GetFactoryClasses()
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ internal ProviderRegistration(string factoryTypeAssemblyQualifiedName, DbProvide
}

private static readonly ConcurrentDictionary<string, ProviderRegistration> _registeredFactories = new ConcurrentDictionary<string, ProviderRegistration>();
private const string AssemblyQualifiedNameColumnName = "AssemblyQualifiedName";
private const string InvariantNameColumnName = "InvariantName";
private const string NameColumnName = "Name";
private const string DescriptionColumnName = "Description";
private const string ProviderGroupColumnName = "DbProviderFactories";
private const string InstanceFieldName = "Instance";

public static bool TryGetFactory(string providerInvariantName, [NotNullWhen(true)] out DbProviderFactory? factory)
Expand All @@ -46,60 +41,6 @@ public static bool TryGetFactory(string providerInvariantName, [NotNullWhen(true
return factory != null;
}

public static DbProviderFactory GetFactory(string providerInvariantName)
{
return GetFactory(providerInvariantName, throwOnError: true)!;
}

public static DbProviderFactory GetFactory(DataRow providerRow)
{
ADP.CheckArgumentNull(providerRow, nameof(providerRow));

DataColumn? assemblyQualifiedNameColumn = providerRow.Table.Columns[AssemblyQualifiedNameColumnName];
if (null == assemblyQualifiedNameColumn)
{
throw ADP.Argument(SR.ADP_DbProviderFactories_NoAssemblyQualifiedName);
}

string? assemblyQualifiedName = providerRow[assemblyQualifiedNameColumn] as string;
if (string.IsNullOrWhiteSpace(assemblyQualifiedName))
{
throw ADP.Argument(SR.ADP_DbProviderFactories_NoAssemblyQualifiedName);
}

return GetFactoryInstance(GetProviderTypeFromTypeName(assemblyQualifiedName));
}


public static DbProviderFactory? GetFactory(DbConnection connection)
{
ADP.CheckArgumentNull(connection, nameof(connection));

return connection.ProviderFactory;
}

public static DataTable GetFactoryClasses()
{
DataColumn nameColumn = new DataColumn(NameColumnName, typeof(string)) { ReadOnly = true };
DataColumn descriptionColumn = new DataColumn(DescriptionColumnName, typeof(string)) { ReadOnly = true };
DataColumn invariantNameColumn = new DataColumn(InvariantNameColumnName, typeof(string)) { ReadOnly = true };
DataColumn assemblyQualifiedNameColumn = new DataColumn(AssemblyQualifiedNameColumnName, typeof(string)) { ReadOnly = true };

DataTable toReturn = new DataTable(ProviderGroupColumnName) { Locale = CultureInfo.InvariantCulture };
toReturn.Columns.AddRange(new[] { nameColumn, descriptionColumn, invariantNameColumn, assemblyQualifiedNameColumn });
toReturn.PrimaryKey = new[] { invariantNameColumn };
foreach (var kvp in _registeredFactories)
{
DataRow newRow = toReturn.NewRow();
newRow[InvariantNameColumnName] = kvp.Key;
newRow[AssemblyQualifiedNameColumnName] = kvp.Value.FactoryTypeAssemblyQualifiedName;
newRow[NameColumnName] = string.Empty;
newRow[DescriptionColumnName] = string.Empty;
toReturn.AddRow(newRow);
}
return toReturn;
}

public static IEnumerable<string> GetProviderInvariantNames()
{
return _registeredFactories.Keys.ToList();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

namespace System.Data
{

/// <summary>
/// This static class defines the DataTable extension methods.
/// </summary>
public static partial class DataTableExtensions
{
/// <summary>
/// Creates a LinkDataView of DataRow over the input table.
/// </summary>
/// <param name="table">DataTable that the view is over.</param>
/// <returns>An instance of LinkDataView.</returns>
public static DataView AsDataView(this DataTable table)
{
DataSetUtil.CheckArgumentNull<DataTable>(table, nameof(table));
return new LinqDataView(table, null);
}

/// <summary>
/// Creates a LinqDataView from EnumerableDataTable
/// </summary>
/// <typeparam name="T">Type of the row in the table. Must inherit from DataRow</typeparam>
/// <param name="source">The enumerable-datatable over which view must be created.</param>
/// <returns>Generated LinkDataView of type T</returns>
public static DataView AsDataView<T>(this EnumerableRowCollection<T> source) where T : DataRow
{
DataSetUtil.CheckArgumentNull<EnumerableRowCollection<T>>(source, nameof(source));
return source.GetLinqDataView();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

namespace System.Data
{

/// <summary>
/// This static class defines the DataTable extension methods.
/// </summary>
public static partial class DataTableExtensions
{
/// <summary>
/// Creates a LinkDataView of DataRow over the input table.
/// </summary>
/// <param name="table">DataTable that the view is over.</param>
/// <returns>An instance of LinkDataView.</returns>
public static DataView AsDataView(this DataTable table)
{
throw new PlatformNotSupportedException();
}

/// <summary>
/// Creates a LinqDataView from EnumerableDataTable
/// </summary>
/// <typeparam name="T">Type of the row in the table. Must inherit from DataRow</typeparam>
/// <param name="source">The enumerable-datatable over which view must be created.</param>
/// <returns>Generated LinkDataView of type T</returns>
public static DataView AsDataView<T>(this EnumerableRowCollection<T> source) where T : DataRow
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace System.Data
/// <summary>
/// This static class defines the DataTable extension methods.
/// </summary>
public static class DataTableExtensions
public static partial class DataTableExtensions
{
/// <summary>
/// This method returns a IEnumerable of Datarows.
Expand Down Expand Up @@ -218,28 +218,5 @@ private static DataTable LoadTableFromEnumerable<T>(IEnumerable<T> source, DataT
Debug.Assert(null != table, "null DataTable");
return table;
}

/// <summary>
/// Creates a LinkDataView of DataRow over the input table.
/// </summary>
/// <param name="table">DataTable that the view is over.</param>
/// <returns>An instance of LinkDataView.</returns>
public static DataView AsDataView(this DataTable table)
{
DataSetUtil.CheckArgumentNull<DataTable>(table, nameof(table));
return new LinqDataView(table, null);
}

/// <summary>
/// Creates a LinqDataView from EnumerableDataTable
/// </summary>
/// <typeparam name="T">Type of the row in the table. Must inherit from DataRow</typeparam>
/// <param name="source">The enumerable-datatable over which view must be created.</param>
/// <returns>Generated LinkDataView of type T</returns>
public static DataView AsDataView<T>(this EnumerableRowCollection<T> source) where T : DataRow
{
DataSetUtil.CheckArgumentNull<EnumerableRowCollection<T>>(source, nameof(source));
return source.GetLinqDataView();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public sealed class TestProviderFactory : DbProviderFactory
private TestProviderFactory() { }
}

[PlatformSpecific(~TestPlatforms.Browser)]
public class DbProviderFactoriesTests
{
[Fact]
Expand Down Expand Up @@ -69,6 +70,7 @@ public void GetFactoryWithDataRowTest()
public void RegisterFactoryWithTypeNameTest()
{
ClearRegisteredFactories();
Console.WriteLine("Name: " + typeof(System.Data.SqlClient.SqlClientFactory).AssemblyQualifiedName);
steveisok marked this conversation as resolved.
Show resolved Hide resolved
RegisterSqlClientAndTestRegistration(()=>DbProviderFactories.RegisterFactory("System.Data.SqlClient", typeof(System.Data.SqlClient.SqlClientFactory).AssemblyQualifiedName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace System.Data.Tests.Common
{
[PlatformSpecific(~TestPlatforms.Browser)]
public class DbProviderFactoryTest
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ public void IsNull_ByIndex()
Assert.True(dr.IsNull(1));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotInvariantGlobalization))]
public void IsNull_ByName()
{
DataTable dt = new DataTable();
Expand Down
Loading