From f3cf6e601a2a9f84e62258207aef5368fff1763f Mon Sep 17 00:00:00 2001
From: Edward Neal <55035479+edwardneal@users.noreply.github.com>
Date: Sat, 28 Jun 2025 20:30:34 +0100
Subject: [PATCH 01/15] Move SqlVectorTest, adjust namespace
---
.../tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs | 3 +--
.../UnitTests/{ => Microsoft/Data/SqlTypes}/SqlVectorTest.cs | 4 ++--
2 files changed, 3 insertions(+), 4 deletions(-)
rename src/Microsoft.Data.SqlClient/tests/UnitTests/{ => Microsoft/Data/SqlTypes}/SqlVectorTest.cs (99%)
diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
index faf44a4e29..d83cedd74d 100644
--- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlJsonTest.cs
@@ -7,10 +7,9 @@
using System;
using System.Data.SqlTypes;
using System.Text.Json;
-using Microsoft.Data.SqlTypes;
using Xunit;
-namespace Microsoft.Data.SqlClient.UnitTests;
+namespace Microsoft.Data.SqlTypes.UnitTests;
public class SqlJsonTest
{
diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/SqlVectorTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlVectorTest.cs
similarity index 99%
rename from src/Microsoft.Data.SqlClient/tests/UnitTests/SqlVectorTest.cs
rename to src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlVectorTest.cs
index 3390d95c02..9e6e520b63 100644
--- a/src/Microsoft.Data.SqlClient/tests/UnitTests/SqlVectorTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlTypes/SqlVectorTest.cs
@@ -4,12 +4,12 @@
// See the LICENSE file in the project root for more information.
using System;
-using Microsoft.Data.SqlTypes;
+using Microsoft.Data.SqlClient;
using Xunit;
#nullable enable
-namespace Microsoft.Data.SqlClient.Tests;
+namespace Microsoft.Data.SqlTypes.UnitTests;
public class SqlVectorTest
{
From 9b55f4c554d7ca79447154a2c735850d611b3dfe Mon Sep 17 00:00:00 2001
From: Edward Neal <55035479+edwardneal@users.noreply.github.com>
Date: Sat, 28 Jun 2025 20:39:06 +0100
Subject: [PATCH 02/15] Replace LocalAppContextSwitchesTests
---
.../LocalAppContextSwitchesTests.cs | 34 -------------------
.../SqlClient/LocalAppContextSwitchesTest.cs | 34 +++++++++++++++++++
2 files changed, 34 insertions(+), 34 deletions(-)
delete mode 100644 src/Microsoft.Data.SqlClient/tests/FunctionalTests/LocalAppContextSwitchesTests.cs
create mode 100644 src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs
diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/LocalAppContextSwitchesTests.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/LocalAppContextSwitchesTests.cs
deleted file mode 100644
index 170e39a322..0000000000
--- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/LocalAppContextSwitchesTests.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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 System;
-using System.Reflection;
-using Xunit;
-
-namespace Microsoft.Data.SqlClient.Tests
-{
- public class LocalAppContextSwitchesTests
- {
- [Theory]
- [InlineData("LegacyRowVersionNullBehavior", false)]
- [InlineData("SuppressInsecureTlsWarning", false)]
- [InlineData("MakeReadAsyncBlocking", false)]
- [InlineData("UseMinimumLoginTimeout", true)]
- [InlineData("LegacyVarTimeZeroScaleBehaviour", true)]
- [InlineData("UseCompatibilityProcessSni", false)]
- [InlineData("UseCompatibilityAsyncBehaviour", false)]
- [InlineData("UseConnectionPoolV2", false)]
- #if NETFRAMEWORK
- [InlineData("DisableTnirByDefault", false)]
- #endif
- public void DefaultSwitchValue(string property, bool expectedDefaultValue)
- {
- var switchesType = typeof(SqlCommand).Assembly.GetType("Microsoft.Data.SqlClient.LocalAppContextSwitches");
-
- var switchValue = (bool)switchesType.GetProperty(property, BindingFlags.Public | BindingFlags.Static).GetValue(null);
-
- Assert.Equal(expectedDefaultValue, switchValue);
- }
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs
new file mode 100644
index 0000000000..ba58ab292e
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs
@@ -0,0 +1,34 @@
+// 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 System;
+using Xunit;
+
+namespace Microsoft.Data.SqlClient.UnitTests
+{
+ ///
+ /// Provides unit tests for verifying the default values of all SqlClient-specific AppContext switches.
+ ///
+ public class LocalAppContextSwitchesTest
+ {
+ ///
+ /// Tests the default values of every AppContext switch used by SqlClient.
+ ///
+ [Fact]
+ public void TestDefaultAppContextSwitchValues()
+ {
+ Assert.False(LocalAppContextSwitches.LegacyRowVersionNullBehavior);
+ Assert.False(LocalAppContextSwitches.SuppressInsecureTlsWarning);
+ Assert.False(LocalAppContextSwitches.MakeReadAsyncBlocking);
+ Assert.True(LocalAppContextSwitches.UseMinimumLoginTimeout);
+ Assert.True(LocalAppContextSwitches.LegacyVarTimeZeroScaleBehaviour);
+ Assert.False(LocalAppContextSwitches.UseCompatibilityProcessSni);
+ Assert.False(LocalAppContextSwitches.UseCompatibilityAsyncBehaviour);
+ Assert.False(LocalAppContextSwitches.UseConnectionPoolV2);
+ #if NETFRAMEWORK
+ Assert.False(LocalAppContextSwitches.DisableTnirByDefault);
+ #endif
+ }
+ }
+}
From fae085a5c7b8b36bb5b4bb3e779bd36e5c4e888d Mon Sep 17 00:00:00 2001
From: Edward Neal <55035479+edwardneal@users.noreply.github.com>
Date: Sat, 28 Jun 2025 20:48:08 +0100
Subject: [PATCH 03/15] Move SqlBufferTests
---
.../Microsoft.Data.SqlClient.FunctionalTests.csproj | 2 --
.../Microsoft/Data/SqlClient}/SqlBufferTests.cs | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
rename src/Microsoft.Data.SqlClient/tests/{FunctionalTests => UnitTests/Microsoft/Data/SqlClient}/SqlBufferTests.cs (99%)
diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.FunctionalTests.csproj b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.FunctionalTests.csproj
index 56265208b4..b755d05423 100644
--- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.FunctionalTests.csproj
+++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.FunctionalTests.csproj
@@ -30,10 +30,8 @@
-
-
diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlBufferTests.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlBufferTests.cs
similarity index 99%
rename from src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlBufferTests.cs
rename to src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlBufferTests.cs
index 2be8f5bd3b..1ffb3d9f50 100644
--- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlBufferTests.cs
+++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlBufferTests.cs
@@ -9,7 +9,7 @@
using System.Reflection;
using Xunit;
-namespace Microsoft.Data.SqlClient.Tests
+namespace Microsoft.Data.SqlClient.UnitTests
{
public sealed class SqlBufferTests
{
From 996e4601b0aee8be85ba4f0610022877405c2e89 Mon Sep 17 00:00:00 2001
From: Edward Neal <55035479+edwardneal@users.noreply.github.com>
Date: Sat, 28 Jun 2025 20:55:55 +0100
Subject: [PATCH 04/15] Remove unnecessary reflection from SqlBufferTests
---
.../Data/SqlClient/SqlBufferTests.cs | 160 +-----------------
1 file changed, 7 insertions(+), 153 deletions(-)
diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlBufferTests.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlBufferTests.cs
index 1ffb3d9f50..9d556b7dd9 100644
--- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlBufferTests.cs
+++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlBufferTests.cs
@@ -3,53 +3,14 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Collections.Generic;
using System.Data.SqlTypes;
-using System.Linq;
-using System.Reflection;
using Xunit;
namespace Microsoft.Data.SqlClient.UnitTests
{
public sealed class SqlBufferTests
{
- static SqlBufferTests()
- {
- const string sqlBufferTypeFullName = "Microsoft.Data.SqlClient.SqlBuffer";
- const string storageTypeName = nameof(SqlBufferProxy.StorageType);
-
- var assembly = typeof(SqlClientFactory).Assembly;
- _sqlBufferType = assembly.GetType(sqlBufferTypeFullName)
- ?? throw new Exception($"Type not found [{sqlBufferTypeFullName}]");
- _storageTypeType = _sqlBufferType.GetNestedTypes(BindingFlags.NonPublic)
- .FirstOrDefault(x => x.Name == storageTypeName)
- ?? throw new Exception($"Type not found [{sqlBufferTypeFullName}+{storageTypeName}]");
- }
-
- private static readonly Type _sqlBufferType;
- private static readonly Type _storageTypeType;
- private readonly SqlBufferProxy _target = new();
-
- public static IEnumerable