-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathBulkCopyAE.cs
More file actions
79 lines (68 loc) · 2.82 KB
/
BulkCopyAE.cs
File metadata and controls
79 lines (68 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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.Data;
using Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.Setup;
using Xunit;
namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
/// <summary>
/// Always Encrypted public API Manual tests.
/// </summary>
[Trait("Set", "AE")]
public sealed class BulkCopyAE : IClassFixture<SQLSetupStrategyCertStoreProvider>, IDisposable
{
private SQLSetupStrategy fixture;
private readonly string tableName;
public BulkCopyAE(SQLSetupStrategyCertStoreProvider context)
{
fixture = context;
tableName = fixture.BulkCopyAETestTable.Name;
}
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestBulkCopyString(string connectionString)
{
var dataTable = new DataTable();
dataTable.Columns.Add("c1", typeof(string));
var dataRow = dataTable.NewRow();
string result = "stringValue";
dataRow["c1"] = result;
dataTable.Rows.Add(dataRow);
dataTable.AcceptChanges();
var encryptionEnabledConnectionString = new SqlConnectionStringBuilder(connectionString)
{
ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled
}.ConnectionString;
using (var connection = new SqlConnection(encryptionEnabledConnectionString))
using (var bulkCopy = new SqlBulkCopy(connection)
{
EnableStreaming = true,
BatchSize = 1,
DestinationTableName = "[" + tableName + "]"
})
{
connection.Open();
Table.DeleteData(tableName, connection);
bulkCopy.WriteToServer(dataTable);
string queryString = "SELECT * FROM [" + tableName + "];";
SqlCommand command = new SqlCommand(queryString, connection);
SqlDataReader reader = command.ExecuteReader();
reader.Read();
Assert.Equal(result, reader.GetString(0));
}
}
public void Dispose()
{
foreach (string connection in DataTestUtility.AEConnStringsSetup)
{
using (SqlConnection sqlConnection = new SqlConnection(connection))
{
sqlConnection.Open();
Table.DeleteData(fixture.BulkCopyAETestTable.Name, sqlConnection);
}
}
}
}
}