diff --git a/src/System.Data.SqlClient/ref/System.Data.SqlClient.cs b/src/System.Data.SqlClient/ref/System.Data.SqlClient.cs index 1335ded849ac..91c92ba5e7d1 100644 --- a/src/System.Data.SqlClient/ref/System.Data.SqlClient.cs +++ b/src/System.Data.SqlClient/ref/System.Data.SqlClient.cs @@ -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 diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlClientFactory.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlClientFactory.cs index 3dab80675475..92387cbc6439 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlClientFactory.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlClientFactory.cs @@ -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 @@ -19,13 +14,11 @@ private SqlClientFactory() { } - public override DbCommand CreateCommand() { return new SqlCommand(); } - public override DbConnection CreateConnection() { return new SqlConnection(); @@ -36,6 +29,10 @@ public override DbConnectionStringBuilder CreateConnectionStringBuilder() return new SqlConnectionStringBuilder(); } + public override DbDataAdapter CreateDataAdapter() + { + return new SqlDataAdapter(); + } public override DbParameter CreateParameter() { @@ -43,4 +40,3 @@ public override DbParameter CreateParameter() } } } - diff --git a/src/System.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs b/src/System.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs new file mode 100644 index 000000000000..25366b95b68d --- /dev/null +++ b/src/System.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs @@ -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(SqlClientFactory.Instance.CreateCommand), typeof(SqlCommand) }, + new object[] { new Func(SqlClientFactory.Instance.CreateConnection), typeof(SqlConnection) }, + new object[] { new Func(SqlClientFactory.Instance.CreateConnectionStringBuilder), typeof(SqlConnectionStringBuilder) }, + new object[] { new Func(SqlClientFactory.Instance.CreateDataAdapter), typeof(SqlDataAdapter) }, + new object[] { new Func(SqlClientFactory.Instance.CreateParameter), typeof(SqlParameter) }, + }; + + [Theory] + [MemberData(nameof(FactoryMethodTestData))] + public void FactoryMethodTest(Func 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); + } + } +} diff --git a/src/System.Data.SqlClient/tests/FunctionalTests/System.Data.SqlClient.Tests.csproj b/src/System.Data.SqlClient/tests/FunctionalTests/System.Data.SqlClient.Tests.csproj index 812b80a31df0..0d8c94432c7e 100644 --- a/src/System.Data.SqlClient/tests/FunctionalTests/System.Data.SqlClient.Tests.csproj +++ b/src/System.Data.SqlClient/tests/FunctionalTests/System.Data.SqlClient.Tests.csproj @@ -18,6 +18,7 @@ +