Skip to content

Commit 8edec48

Browse files
committed
Enable NH-2207 tests for Sql2008ClientDriver
1 parent 58e98b4 commit 8edec48

File tree

2 files changed

+111
-7
lines changed

2 files changed

+111
-7
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data;
13+
using NHibernate.Driver;
14+
using NHibernate.Engine;
15+
using NUnit.Framework;
16+
17+
namespace NHibernate.Test.NHSpecificTest.NH2207
18+
{
19+
using System.Threading.Tasks;
20+
using System.Threading;
21+
[TestFixture]
22+
public class SampleTestAsync : BugTestCase
23+
{
24+
protected override bool AppliesTo(ISessionFactoryImplementor factory)
25+
{
26+
return factory.ConnectionProvider.Driver is Sql2008ClientDriver;
27+
28+
}
29+
30+
[Test]
31+
public async Task WithoutUseNHSqlDataProviderWorkProperlyAsync()
32+
{
33+
var createTable = "CREATE TABLE TryDate([Id] [int] IDENTITY(1,1) NOT NULL,[MyDate] [date] NOT NULL)";
34+
var dropTable = "DROP TABLE TryDate";
35+
var insertTable = "INSERT INTO TryDate([MyDate]) VALUES(@p0)";
36+
using(var sqlConnection = new System.Data.SqlClient.SqlConnection(cfg.Properties[Cfg.Environment.ConnectionString]))
37+
{
38+
await (sqlConnection.OpenAsync(CancellationToken.None));
39+
using (var tx = sqlConnection.BeginTransaction())
40+
{
41+
var command = sqlConnection.CreateCommand();
42+
command.Transaction = tx;
43+
command.CommandText = createTable;
44+
await (command.ExecuteNonQueryAsync(CancellationToken.None));
45+
tx.Commit();
46+
}
47+
48+
try
49+
{
50+
using (var tx = sqlConnection.BeginTransaction())
51+
{
52+
var command = sqlConnection.CreateCommand();
53+
command.Transaction = tx;
54+
command.CommandText = insertTable;
55+
var dateParam = command.CreateParameter();
56+
dateParam.ParameterName = "@p0";
57+
dateParam.DbType = DbType.Date;
58+
dateParam.SqlDbType = SqlDbType.Date;
59+
dateParam.Value = DateTime.MinValue.Date;
60+
command.Parameters.Add(dateParam);
61+
await (command.ExecuteNonQueryAsync(CancellationToken.None));
62+
tx.Commit();
63+
}
64+
}
65+
finally
66+
{
67+
using (var tx = sqlConnection.BeginTransaction())
68+
{
69+
var command = sqlConnection.CreateCommand();
70+
command.Transaction = tx;
71+
command.CommandText = dropTable;
72+
await (command.ExecuteNonQueryAsync(CancellationToken.None));
73+
tx.Commit();
74+
}
75+
}
76+
}
77+
}
78+
79+
[Test]
80+
public async Task Dates_Before_1753_Should_Not_Insert_NullAsync()
81+
{
82+
object savedId;
83+
var expectedStoredValue = DateTime.MinValue.Date.AddDays(1).Date;
84+
using (ISession session = OpenSession())
85+
using (var tx = session.BeginTransaction())
86+
{
87+
var concrete = new DomainClass{Date = expectedStoredValue.AddMinutes(90)};
88+
savedId = await (session.SaveAsync(concrete));
89+
await (tx.CommitAsync());
90+
}
91+
92+
using (ISession session = OpenSession())
93+
using (var tx = session.BeginTransaction())
94+
{
95+
var savedObj = await (session.GetAsync<DomainClass>(savedId));
96+
Assert.That(savedObj.Date, Is.EqualTo(expectedStoredValue));
97+
await (session.DeleteAsync(savedObj));
98+
await (tx.CommitAsync());
99+
}
100+
}
101+
}
102+
}

src/NHibernate.Test/NHSpecificTest/NH2207/SampleTest.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
using System;
22
using System.Data;
3-
using NHibernate.Dialect;
3+
using NHibernate.Driver;
4+
using NHibernate.Engine;
45
using NUnit.Framework;
56

67
namespace NHibernate.Test.NHSpecificTest.NH2207
78
{
8-
[TestFixture, Ignore("Demostration of external issue")]
9+
[TestFixture]
910
public class SampleTest : BugTestCase
1011
{
11-
protected override bool AppliesTo(Dialect.Dialect dialect)
12+
protected override bool AppliesTo(ISessionFactoryImplementor factory)
1213
{
13-
return dialect as MsSql2008Dialect != null;
14+
return factory.ConnectionProvider.Driver is Sql2008ClientDriver;
15+
1416
}
1517

1618
[Test]
@@ -41,6 +43,7 @@ public void WithoutUseNHSqlDataProviderWorkProperly()
4143
var dateParam = command.CreateParameter();
4244
dateParam.ParameterName = "@p0";
4345
dateParam.DbType = DbType.Date;
46+
dateParam.SqlDbType = SqlDbType.Date;
4447
dateParam.Value = DateTime.MinValue.Date;
4548
command.Parameters.Add(dateParam);
4649
command.ExecuteNonQuery();
@@ -56,10 +59,9 @@ public void WithoutUseNHSqlDataProviderWorkProperly()
5659
command.CommandText = dropTable;
5760
command.ExecuteNonQuery();
5861
tx.Commit();
59-
}
62+
}
6063
}
6164
}
62-
6365
}
6466

6567
[Test]
@@ -85,4 +87,4 @@ public void Dates_Before_1753_Should_Not_Insert_Null()
8587
}
8688
}
8789
}
88-
}
90+
}

0 commit comments

Comments
 (0)