|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections; |
| 7 | +using System.Collections.Generic; |
| 8 | +using Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.Setup; |
| 9 | +using Xunit; |
| 10 | + |
| 11 | +namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted |
| 12 | +{ |
| 13 | + public sealed class DateOnlyReadTests : IClassFixture<PlatformSpecificTestContext>, IDisposable |
| 14 | + { |
| 15 | + private SQLSetupStrategy fixture; |
| 16 | + |
| 17 | + private readonly string tableName; |
| 18 | + |
| 19 | + public DateOnlyReadTests(PlatformSpecificTestContext context) |
| 20 | + { |
| 21 | + fixture = context.Fixture; |
| 22 | + tableName = fixture.DateOnlyTestTable.Name; |
| 23 | + } |
| 24 | + |
| 25 | + // tests |
| 26 | + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))] |
| 27 | + [ClassData(typeof(TestSelectOnEncryptedNonEncryptedColumnsDataDateOnly))] |
| 28 | + public void TestSelectOnEncryptedNonEncryptedColumns(string connString, string selectQuery, int totalColumnsInSelect, string[] types) |
| 29 | + { |
| 30 | + Assert.False(string.IsNullOrWhiteSpace(selectQuery), "FAILED: select query should not be null or empty."); |
| 31 | + Assert.True(totalColumnsInSelect <= 3, "FAILED: totalColumnsInSelect should <= 3."); |
| 32 | + |
| 33 | + using (SqlConnection sqlConn = new SqlConnection(connString)) |
| 34 | + { |
| 35 | + sqlConn.Open(); |
| 36 | + |
| 37 | + Table.DeleteData(tableName, sqlConn); |
| 38 | + |
| 39 | + // insert 1 row data |
| 40 | + CustomerDateOnly customer = new CustomerDateOnly( |
| 41 | + 45, |
| 42 | + "Microsoft", |
| 43 | + "Corporation", |
| 44 | + new DateOnly(2001, 1, 31), |
| 45 | + new TimeOnly(18, 36, 45)); |
| 46 | + |
| 47 | + DatabaseHelper.InsertCustomerDateOnlyData(sqlConn, null, tableName, customer); |
| 48 | + |
| 49 | + using (SqlCommand sqlCommand = new SqlCommand(string.Format(selectQuery, tableName), |
| 50 | + sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled)) |
| 51 | + { |
| 52 | + using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) |
| 53 | + { |
| 54 | + Assert.True(sqlDataReader.HasRows, "FAILED: Select statement did not return any rows."); |
| 55 | + |
| 56 | + while (sqlDataReader.Read()) |
| 57 | + { |
| 58 | + DatabaseHelper.CompareResults(sqlDataReader, types, totalColumnsInSelect); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + public void Dispose() |
| 67 | + { |
| 68 | + foreach (string connStrAE in DataTestUtility.AEConnStringsSetup) |
| 69 | + { |
| 70 | + using (SqlConnection sqlConnection = new SqlConnection(connStrAE)) |
| 71 | + { |
| 72 | + sqlConnection.Open(); |
| 73 | + Table.DeleteData(fixture.DateOnlyTestTable.Name, sqlConnection); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + public class TestSelectOnEncryptedNonEncryptedColumnsDataDateOnly : IEnumerable<object[]> |
| 80 | + { |
| 81 | + public IEnumerator<object[]> GetEnumerator() |
| 82 | + { |
| 83 | + foreach (string connStrAE in DataTestUtility.AEConnStrings) |
| 84 | + { |
| 85 | + yield return new object[] { connStrAE, @"select CustomerId, FirstName, LastName from [{0}] ", 3, new string[] { @"int", @"string", @"string" } }; |
| 86 | + yield return new object[] { connStrAE, @"select CustomerId, FirstName from [{0}] ", 2, new string[] { @"int", @"string" } }; |
| 87 | + yield return new object[] { connStrAE, @"select LastName from [{0}] ", 1, new string[] { @"string" }}; |
| 88 | + yield return new object[] { connStrAE, @"select DateOfBirth, TimeOfDay from [{0}] ", 2, new string[] { @"DateOnly", "TimeOnly" } }; |
| 89 | + } |
| 90 | + } |
| 91 | + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); |
| 92 | + } |
| 93 | +} |
0 commit comments