1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Runtime . CompilerServices ;
3
4
using System . Security . Cryptography . X509Certificates ;
5
+ using System . Text ;
4
6
using Xunit ;
5
7
6
8
namespace Microsoft . Data . SqlClient . ManualTesting . Tests . AlwaysEncrypted
@@ -11,13 +13,39 @@ public class TestTrustedMasterKeyPaths : IClassFixture<SQLSetupStrategyCertStore
11
13
private readonly string tableName ;
12
14
private readonly string columnMasterKeyPath ;
13
15
16
+ private static void Log (
17
+ string message ,
18
+ [ CallerMemberName ] string who = "" )
19
+ {
20
+ StringBuilder builder = new ( ) ;
21
+ builder . Append ( DateTime . UtcNow . ToString ( "HH:mm:ss.fff" ) ) ;
22
+ builder . Append ( ' ' ) ;
23
+ builder . Append ( nameof ( TestTrustedMasterKeyPaths ) ) ;
24
+ builder . Append ( '.' ) ;
25
+ builder . Append ( who ) ;
26
+ builder . Append ( "(): " ) ;
27
+ builder . Append ( message ) ;
28
+ Console . WriteLine ( builder . ToString ( ) ) ;
29
+ }
30
+
31
+ private static void LogStart (
32
+ [ CallerMemberName ] string who = "" )
33
+ {
34
+ Log ( "Start" , who ) ;
35
+ }
36
+ private static void LogEnd (
37
+ [ CallerMemberName ] string who = "" )
38
+ {
39
+ Log ( "End" , who ) ;
40
+ }
41
+
14
42
public TestTrustedMasterKeyPaths ( SQLSetupStrategyCertStoreProvider fixture )
15
43
{
16
- Console . WriteLine ( "Start: TestTrustedMasterKeyPaths()" ) ;
44
+ LogStart ( ) ;
17
45
columnMasterKeyPath = string . Format ( @"{0}/{1}/{2}" , StoreLocation . CurrentUser . ToString ( ) , @"my" , CertificateUtility . CreateCertificate ( ) . Thumbprint ) ;
18
46
this . fixture = fixture ;
19
47
tableName = fixture . TrustedMasterKeyPathsTestTable . Name ;
20
- Console . WriteLine ( "End: TestTrustedMasterKeyPaths()" ) ;
48
+ LogEnd ( ) ;
21
49
}
22
50
23
51
/// <summary>
@@ -26,7 +54,7 @@ public TestTrustedMasterKeyPaths(SQLSetupStrategyCertStoreProvider fixture)
26
54
/// <param name="sqlDataReader"></param>
27
55
private void ValidateResultSet ( SqlDataReader sqlDataReader )
28
56
{
29
- Console . WriteLine ( "Start: ValidateResultSet()" ) ;
57
+ LogStart ( ) ;
30
58
// Validate the result set
31
59
int rowsFound = 0 ;
32
60
while ( sqlDataReader . Read ( ) )
@@ -45,15 +73,15 @@ private void ValidateResultSet(SqlDataReader sqlDataReader)
45
73
rowsFound ++ ;
46
74
}
47
75
Assert . True ( rowsFound == 1 , "Incorrect number of rows returned in first execution." ) ;
48
- Console . WriteLine ( "End: ValidateResultSet()" ) ;
76
+ LogEnd ( ) ;
49
77
}
50
78
51
79
[ PlatformSpecific ( TestPlatforms . Windows ) ]
52
80
[ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringSetupForAE ) ) ]
53
81
[ ClassData ( typeof ( AEConnectionStringProvider ) ) ]
54
82
public void TestTrustedColumnEncryptionMasterKeyPathsWithNullDictionary ( string connection )
55
83
{
56
- Console . WriteLine ( $ "Start: TestTrustedColumnEncryptionMasterKeyPathsWithNullDictionary(); connection string: { connection } " ) ;
84
+ LogStart ( ) ;
57
85
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder ( connection ) ;
58
86
connBuilder . ConnectTimeout = 10000 ;
59
87
string connStringNow = connBuilder . ToString ( ) ;
@@ -86,15 +114,15 @@ FROM [{tableName}]
86
114
}
87
115
// Clear out trusted key paths
88
116
SqlConnection . ColumnEncryptionTrustedMasterKeyPaths . Clear ( ) ;
89
- Console . WriteLine ( "End: TestTrustedColumnEncryptionMasterKeyPathsWithNullDictionary()" ) ;
117
+ LogEnd ( ) ;
90
118
}
91
119
92
120
[ PlatformSpecific ( TestPlatforms . Windows ) ]
93
121
[ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringSetupForAE ) ) ]
94
122
[ ClassData ( typeof ( AEConnectionStringProvider ) ) ]
95
123
public void TestTrustedColumnEncryptionMasterKeyPathsWithOneServer ( string connection )
96
124
{
97
- Console . WriteLine ( $ "Start: TestTrustedColumnEncryptionMasterKeyPathsWithOneServer(); connection string: { connection } " ) ;
125
+ LogStart ( ) ;
98
126
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder ( connection ) ;
99
127
connBuilder . ConnectTimeout = 10000 ;
100
128
string connStringNow = connBuilder . ToString ( ) ;
@@ -134,15 +162,15 @@ FROM [{tableName}]
134
162
}
135
163
// Clear out trusted key paths
136
164
SqlConnection . ColumnEncryptionTrustedMasterKeyPaths . Clear ( ) ;
137
- Console . WriteLine ( "End: TestTrustedColumnEncryptionMasterKeyPathsWithOneServer()" ) ;
165
+ LogEnd ( ) ;
138
166
}
139
167
140
168
[ PlatformSpecific ( TestPlatforms . Windows ) ]
141
169
[ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringSetupForAE ) ) ]
142
170
[ ClassData ( typeof ( AEConnectionStringProvider ) ) ]
143
171
public void TestTrustedColumnEncryptionMasterKeyPathsWithMultipleServers ( string connection )
144
172
{
145
- Console . WriteLine ( $ "Start: TestTrustedColumnEncryptionMasterKeyPathsWithMultipleServers(); connection string: { connection } " ) ;
173
+ LogStart ( ) ;
146
174
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder ( connection ) ;
147
175
connBuilder . ConnectTimeout = 10000 ;
148
176
string connStringNow = connBuilder . ToString ( ) ;
@@ -199,15 +227,15 @@ FROM [{tableName}]
199
227
}
200
228
// Clear out trusted key paths
201
229
SqlConnection . ColumnEncryptionTrustedMasterKeyPaths . Clear ( ) ;
202
- Console . WriteLine ( "End: TestTrustedColumnEncryptionMasterKeyPathsWithMultipleServers()" ) ;
230
+ LogEnd ( ) ;
203
231
}
204
232
205
233
[ PlatformSpecific ( TestPlatforms . Windows ) ]
206
234
[ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringSetupForAE ) ) ]
207
235
[ ClassData ( typeof ( AEConnectionStringProvider ) ) ]
208
236
public void TestTrustedColumnEncryptionMasterKeyPathsWithInvalidInputs ( string connection )
209
237
{
210
- Console . WriteLine ( $ "Start: TestTrustedColumnEncryptionMasterKeyPathsWithInvalidInputs(); connection string: { connection } " ) ;
238
+ LogStart ( ) ;
211
239
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder ( connection ) ;
212
240
connBuilder . ConnectTimeout = 10000 ;
213
241
string connStringNow = connBuilder . ToString ( ) ;
@@ -314,7 +342,7 @@ FROM [{tableName}]
314
342
315
343
// Clear out trusted key paths
316
344
SqlConnection . ColumnEncryptionTrustedMasterKeyPaths . Clear ( ) ;
317
- Console . WriteLine ( "End: TestTrustedColumnEncryptionMasterKeyPathsWithInvalidInputs()" ) ;
345
+ LogEnd ( ) ;
318
346
}
319
347
}
320
348
}
0 commit comments