Skip to content

Commit ab3adca

Browse files
committed
.
1 parent d25dad5 commit ab3adca

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This test:
5050
```cs
5151
await Verify(connection);
5252
```
53-
<sup><a href='/src/Tests/Tests.cs#L317-L321' title='Snippet source file'>snippet source</a> | <a href='#snippet-SqlServerSchema' title='Start of snippet'>anchor</a></sup>
53+
<sup><a href='/src/Tests/Tests.cs#L316-L320' title='Snippet source file'>snippet source</a> | <a href='#snippet-SqlServerSchema' title='Start of snippet'>anchor</a></sup>
5454
<!-- endSnippet -->
5555

5656
Will result in the following verified file:
@@ -69,7 +69,7 @@ await Verify(connection)
6969
// include only tables and views
7070
.SchemaIncludes(DbObjects.Tables | DbObjects.Views);
7171
```
72-
<sup><a href='/src/Tests/Tests.cs#L683-L689' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaInclude' title='Start of snippet'>anchor</a></sup>
72+
<sup><a href='/src/Tests/Tests.cs#L682-L688' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaInclude' title='Start of snippet'>anchor</a></sup>
7373
<!-- endSnippet -->
7474

7575
Available values:
@@ -107,7 +107,7 @@ await Verify(connection)
107107
_ => _ is TableViewBase ||
108108
_.Name == "MyTrigger");
109109
```
110-
<sup><a href='/src/Tests/Tests.cs#L708-L716' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
110+
<sup><a href='/src/Tests/Tests.cs#L707-L715' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
111111
<!-- endSnippet -->
112112

113113

@@ -129,7 +129,7 @@ command.CommandText = "select Value from MyTable";
129129
var value = await command.ExecuteScalarAsync();
130130
await Verify(value!);
131131
```
132-
<sup><a href='/src/Tests/Tests.cs#L492-L502' title='Snippet source file'>snippet source</a> | <a href='#snippet-Recording' title='Start of snippet'>anchor</a></sup>
132+
<sup><a href='/src/Tests/Tests.cs#L491-L501' title='Snippet source file'>snippet source</a> | <a href='#snippet-Recording' title='Start of snippet'>anchor</a></sup>
133133
<!-- endSnippet -->
134134

135135
Will result in the following verified file:
@@ -184,7 +184,7 @@ await Verify(
184184
sqlEntries = entries
185185
});
186186
```
187-
<sup><a href='/src/Tests/Tests.cs#L569-L599' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
187+
<sup><a href='/src/Tests/Tests.cs#L568-L598' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
188188
<!-- endSnippet -->
189189

190190

@@ -212,7 +212,7 @@ var sqlErrorsViaType = entries
212212
.Select(_ => _.Data)
213213
.OfType<ErrorEntry>();
214214
```
215-
<sup><a href='/src/Tests/Tests.cs#L625-L644' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
215+
<sup><a href='/src/Tests/Tests.cs#L624-L643' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
216216
<!-- endSnippet -->
217217

218218

src/Tests/Tests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[TestFixture]
22
public class Tests
33
{
4-
static readonly FieldInfo sqlConnectionObjectField =
5-
typeof(ConnectionManager).GetField("m_SqlConnectionObject", BindingFlags.NonPublic | BindingFlags.Instance)!;
6-
74
static SqlInstance sqlInstance;
85

96
static Tests() =>
@@ -12,7 +9,7 @@ static Tests() =>
129
connection =>
1310
{
1411
var serverConnection = new ServerConnection();
15-
sqlConnectionObjectField.SetValue(serverConnection, connection);
12+
SqlScriptBuilder.SqlConnectionObjectField.SetValue(serverConnection, connection);
1613
serverConnection.NonPooledConnection = true;
1714
var server = new Server(serverConnection);
1815
server.ConnectionContext.ExecuteNonQuery(

src/Verify.SqlServer/SchemaValidation/SqlScriptBuilder.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
class SqlScriptBuilder(SchemaSettings settings)
22
{
3+
// TODO: when Microsoft.Data.SqlClient 7.0.1 adds TypeForwardedTo for SqlAuthenticationMethod,
4+
// revert to using new ServerConnection(SqlConnection) and remove this reflection workaround.
5+
//
36
// SMO 181.15.0 ServerConnection(SqlConnection) constructor calls InitFromSqlConnection
47
// which references SqlAuthenticationMethod — a type moved from Microsoft.Data.SqlClient
58
// to Microsoft.Data.SqlClient.Extensions.Abstractions in SqlClient 7.0. The CLR can't
@@ -8,8 +11,9 @@ class SqlScriptBuilder(SchemaSettings settings)
811
// Workaround: construct ServerConnection() with default constructor (no InitFromSqlConnection),
912
// then set the internal m_SqlConnectionObject field via reflection to reuse the open connection.
1013
// SMO detects the connection is already open and uses it directly.
11-
static readonly FieldInfo sqlConnectionObjectField =
12-
typeof(ConnectionManager).GetField("m_SqlConnectionObject", BindingFlags.NonPublic | BindingFlags.Instance)!;
14+
internal static readonly FieldInfo SqlConnectionObjectField =
15+
typeof(ConnectionManager).GetField("m_SqlConnectionObject", BindingFlags.NonPublic | BindingFlags.Instance) ??
16+
throw new("Could not find field m_SqlConnectionObject on ConnectionManager. The SMO internals may have changed.");
1317

1418
static Dictionary<string, string> tableSettingsToScrubLookup;
1519

@@ -46,7 +50,7 @@ public string BuildContent(SqlConnection connection)
4650
};
4751
try
4852
{
49-
sqlConnectionObjectField.SetValue(serverConnection, connection);
53+
SqlConnectionObjectField.SetValue(serverConnection, connection);
5054
var server = new Server(serverConnection);
5155
return BuildContent(server, builder);
5256
}

src/Verify.SqlServer/Verify.SqlServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<TargetFrameworks>net48;net8.0;net9.0;net10.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
6+
<InternalsVisibleTo Include="Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd" />
67
<PackageReference Include="Microsoft.Data.SqlClient" />
78
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" />
89
<PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom" />

0 commit comments

Comments
 (0)