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
SqlClientFactory: Override CreateDataAdapter (#19682)
Browse files Browse the repository at this point in the history
* SqlClientFactory: Override CreateDataAdapter

Override CreateDataAdapter and add tests.

* Address CR feedback
  • Loading branch information
justinvp authored and ViktorHofer committed May 12, 2017
1 parent 9ee2ac6 commit 88f562c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/System.Data.SqlClient/ref/System.Data.SqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ internal SqlClientFactory() { }
public override System.Data.Common.DbCommand CreateCommand() { throw null; }
public override System.Data.Common.DbConnection CreateConnection() { throw null; }
public override System.Data.Common.DbConnectionStringBuilder CreateConnectionStringBuilder() { throw null; }
public override System.Data.Common.DbDataAdapter CreateDataAdapter() { throw null; }
public override System.Data.Common.DbParameter CreateParameter() { throw null; }
}
public sealed partial class SqlCommand : System.Data.Common.DbCommand, System.ICloneable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.



//------------------------------------------------------------------------------

using System.Data.Common;


namespace System.Data.SqlClient
{
public sealed class SqlClientFactory : DbProviderFactory
Expand All @@ -19,13 +14,11 @@ private SqlClientFactory()
{
}


public override DbCommand CreateCommand()
{
return new SqlCommand();
}


public override DbConnection CreateConnection()
{
return new SqlConnection();
Expand All @@ -36,11 +29,14 @@ public override DbConnectionStringBuilder CreateConnectionStringBuilder()
return new SqlConnectionStringBuilder();
}

public override DbDataAdapter CreateDataAdapter()
{
return new SqlDataAdapter();
}

public override DbParameter CreateParameter()
{
return new SqlParameter();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;

namespace System.Data.SqlClient.Tests
{
public class SqlClientFactoryTest
{
[Fact]
public void InstanceTest()
{
SqlClientFactory instance = SqlClientFactory.Instance;
Assert.NotNull(instance);
Assert.Same(instance, SqlClientFactory.Instance);
}

public static readonly object[][] FactoryMethodTestData =
{
new object[] { new Func<object>(SqlClientFactory.Instance.CreateCommand), typeof(SqlCommand) },
new object[] { new Func<object>(SqlClientFactory.Instance.CreateConnection), typeof(SqlConnection) },
new object[] { new Func<object>(SqlClientFactory.Instance.CreateConnectionStringBuilder), typeof(SqlConnectionStringBuilder) },
new object[] { new Func<object>(SqlClientFactory.Instance.CreateDataAdapter), typeof(SqlDataAdapter) },
new object[] { new Func<object>(SqlClientFactory.Instance.CreateParameter), typeof(SqlParameter) },
};

[Theory]
[MemberData(nameof(FactoryMethodTestData))]
public void FactoryMethodTest(Func<object> factory, Type expectedType)
{
object value1 = factory();
Assert.NotNull(value1);
Assert.IsType(expectedType, value1);

object value2 = factory();
Assert.NotNull(value2);
Assert.IsType(expectedType, value2);

Assert.NotSame(value1, value2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Compile Include="ExceptionTest.cs" />
<Compile Include="FakeDiagnosticListenerObserver.cs" />
<Compile Include="SqlBulkCopyColumnMappingCollectionTest.cs" />
<Compile Include="SqlClientFactoryTest.cs" />
<Compile Include="SqlConnectionTest.RetrieveStatistics.cs" />
<Compile Include="SqlErrorCollectionTest.cs" />
<Compile Include="TcpDefaultForAzureTest.cs" />
Expand Down

1 comment on commit 88f562c

@bfyxzls
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是对ado.net的支持吧。。。

Please sign in to comment.