|
1 | | -using NUnit.Framework; |
2 | | -using System.Data; |
3 | | -using System.Data.Common; |
4 | | - |
5 | | -namespace Snowflake.Data.Tests.IntegrationTests |
6 | | -{ |
7 | | - |
8 | | - [TestFixture] |
9 | | - class SFDbFactoryIT : SFBaseTest |
10 | | - { |
11 | | - DbProviderFactory _factory; |
12 | | - DbCommand _command; |
13 | | - DbConnection _connection; |
14 | | - |
15 | | - [SetUp] |
16 | | - public new void BeforeTest() |
17 | | - { |
18 | | -#if NETFRAMEWORK |
19 | | - _factory = DbProviderFactories.GetFactory("Snowflake.Data"); |
20 | | -#else |
21 | | - // In .NET Standard, DbProviderFactories is gone. |
22 | | - // Reference https://weblog.west-wind.com/posts/2017/Nov/27/Working-around-the-lack-of-dynamic-DbProviderFactory-loading-in-NET-Core |
23 | | - // for more details |
24 | | - _factory = Snowflake.Data.Client.SnowflakeDbFactory.Instance; |
25 | | -#endif |
26 | | - |
27 | | - _command = _factory.CreateCommand(); |
28 | | - _connection = _factory.CreateConnection(); |
29 | | - |
30 | | - _connection.ConnectionString = ConnectionString; |
31 | | - _connection.Open(); |
32 | | - } |
33 | | - |
34 | | - [TearDown] |
35 | | - public new void AfterTest() |
36 | | - { |
37 | | - _connection.Close(); |
38 | | - } |
39 | | - |
40 | | - [Test] |
41 | | - public void TestSimpleDbFactory() |
42 | | - { |
43 | | - // set commnad's connection object |
44 | | - _command.Connection = _connection; |
45 | | - _command.CommandText = "select 1"; |
46 | | - |
47 | | - object res = _command.ExecuteScalar(); |
48 | | - |
49 | | - Assert.AreEqual(1, res); |
50 | | - } |
51 | | - |
52 | | - [Test] |
53 | | - public void TestDbFactoryWithParameter() |
54 | | - { |
55 | | - int expectedIntValue = 1; |
56 | | - |
57 | | - DbParameter parameter = _factory.CreateParameter(); |
58 | | - parameter.ParameterName = "1"; |
59 | | - parameter.Value = expectedIntValue; |
60 | | - parameter.DbType = DbType.Int16; |
61 | | - _command.Parameters.Add(parameter); |
62 | | - |
63 | | - // set command's connection object |
64 | | - _command.Connection = _connection; |
65 | | - _command.CommandText = "select ?"; |
66 | | - |
67 | | - var result = _command.ExecuteScalar(); |
68 | | - |
69 | | - Assert.AreEqual(expectedIntValue, result); |
70 | | - } |
71 | | - |
72 | | - [Test] |
73 | | - public void TestDbFactoryWithConnectionStringBuilder() |
74 | | - { |
75 | | - DbConnectionStringBuilder builder = _factory.CreateConnectionStringBuilder(); |
76 | | - builder.ConnectionString = ConnectionString; |
77 | | - |
78 | | - _connection.ConnectionString = builder.ConnectionString; |
79 | | - _connection.Open(); |
80 | | - |
81 | | - // set command's connection object |
82 | | - _command.Connection = _connection; |
83 | | - _command.CommandText = "select 1"; |
84 | | - |
85 | | - var result = _command.ExecuteScalar(); |
86 | | - |
87 | | - Assert.AreEqual(1, result); |
88 | | - } |
89 | | - |
90 | | - [Test] |
91 | | - public void TestDbFactoryWithCommandBuilderAndAdapter() |
92 | | - { |
93 | | - // set command's connection object |
94 | | - _command.Connection = _connection; |
95 | | - _command.CommandText = "select 1"; |
96 | | - |
97 | | - DbDataAdapter adapter = _factory.CreateDataAdapter(); |
98 | | - adapter.SelectCommand = _command; |
99 | | - DbCommandBuilder builder = _factory.CreateCommandBuilder(); |
100 | | - builder.DataAdapter = adapter; |
101 | | - DataSet ds = new DataSet("ds"); |
102 | | - |
103 | | - adapter.Fill(ds); |
104 | | - |
105 | | - Assert.AreEqual(1, ds.Tables[0].Rows[0].ItemArray[0]); |
106 | | - } |
107 | | - } |
108 | | -} |
| 1 | +using NUnit.Framework; |
| 2 | +using System.Data; |
| 3 | +using System.Data.Common; |
| 4 | + |
| 5 | +namespace Snowflake.Data.Tests.IntegrationTests |
| 6 | +{ |
| 7 | + |
| 8 | + [TestFixture] |
| 9 | + class SFDbFactoryIT : SFBaseTest |
| 10 | + { |
| 11 | + DbProviderFactory _factory; |
| 12 | + DbCommand _command; |
| 13 | + DbConnection _connection; |
| 14 | + |
| 15 | + [SetUp] |
| 16 | + public new void BeforeTest() |
| 17 | + { |
| 18 | +#if NETFRAMEWORK |
| 19 | + _factory = DbProviderFactories.GetFactory("Snowflake.Data"); |
| 20 | +#else |
| 21 | + // In .NET Standard, DbProviderFactories is gone. |
| 22 | + // Reference https://weblog.west-wind.com/posts/2017/Nov/27/Working-around-the-lack-of-dynamic-DbProviderFactory-loading-in-NET-Core |
| 23 | + // for more details |
| 24 | + _factory = Snowflake.Data.Client.SnowflakeDbFactory.Instance; |
| 25 | +#endif |
| 26 | + |
| 27 | + _command = _factory.CreateCommand(); |
| 28 | + _connection = _factory.CreateConnection(); |
| 29 | + |
| 30 | + _connection.ConnectionString = ConnectionString; |
| 31 | + _connection.Open(); |
| 32 | + } |
| 33 | + |
| 34 | + [TearDown] |
| 35 | + public new void AfterTest() |
| 36 | + { |
| 37 | + _connection.Close(); |
| 38 | + } |
| 39 | + |
| 40 | + [Test] |
| 41 | + public void TestSimpleDbFactory() |
| 42 | + { |
| 43 | + // set commnad's connection object |
| 44 | + _command.Connection = _connection; |
| 45 | + _command.CommandText = "select 1"; |
| 46 | + |
| 47 | + object res = _command.ExecuteScalar(); |
| 48 | + |
| 49 | + Assert.AreEqual(1, res); |
| 50 | + } |
| 51 | + |
| 52 | + [Test] |
| 53 | + public void TestDbFactoryWithParameter() |
| 54 | + { |
| 55 | + int expectedIntValue = 1; |
| 56 | + |
| 57 | + DbParameter parameter = _factory.CreateParameter(); |
| 58 | + parameter.ParameterName = "1"; |
| 59 | + parameter.Value = expectedIntValue; |
| 60 | + parameter.DbType = DbType.Int16; |
| 61 | + _command.Parameters.Add(parameter); |
| 62 | + |
| 63 | + // set command's connection object |
| 64 | + _command.Connection = _connection; |
| 65 | + _command.CommandText = "select ?"; |
| 66 | + |
| 67 | + var result = _command.ExecuteScalar(); |
| 68 | + |
| 69 | + Assert.AreEqual(expectedIntValue, result); |
| 70 | + } |
| 71 | + |
| 72 | + [Test] |
| 73 | + public void TestDbFactoryWithConnectionStringBuilder() |
| 74 | + { |
| 75 | + DbConnectionStringBuilder builder = _factory.CreateConnectionStringBuilder(); |
| 76 | + builder.ConnectionString = ConnectionString; |
| 77 | + |
| 78 | + _connection.ConnectionString = builder.ConnectionString; |
| 79 | + _connection.Open(); |
| 80 | + |
| 81 | + // set command's connection object |
| 82 | + _command.Connection = _connection; |
| 83 | + _command.CommandText = "select 1"; |
| 84 | + |
| 85 | + var result = _command.ExecuteScalar(); |
| 86 | + |
| 87 | + Assert.AreEqual(1, result); |
| 88 | + } |
| 89 | + |
| 90 | + [Test] |
| 91 | + public void TestDbFactoryWithCommandBuilderAndAdapter() |
| 92 | + { |
| 93 | + // set command's connection object |
| 94 | + _command.Connection = _connection; |
| 95 | + _command.CommandText = "select 1"; |
| 96 | + |
| 97 | + DbDataAdapter adapter = _factory.CreateDataAdapter(); |
| 98 | + adapter.SelectCommand = _command; |
| 99 | + DbCommandBuilder builder = _factory.CreateCommandBuilder(); |
| 100 | + builder.DataAdapter = adapter; |
| 101 | + DataSet ds = new DataSet("ds"); |
| 102 | + |
| 103 | + adapter.Fill(ds); |
| 104 | + |
| 105 | + Assert.AreEqual(1, ds.Tables[0].Rows[0].ItemArray[0]); |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments