Skip to content

Commit d533eb0

Browse files
hazzikfredericDelaporte
authored andcommitted
NH-2207 - Enable tests for Sql2008ClientDriver
NH-1754 - More edge cases
1 parent c16868d commit d533eb0

File tree

4 files changed

+148
-5
lines changed

4 files changed

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

src/NHibernate.Test/Async/TypesTest/DateTypeTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ public Task ReadWriteMinAsync()
5757
}
5858
}
5959

60+
[Test]
61+
public Task ReadWriteYear750Async()
62+
{
63+
try
64+
{
65+
var expected = new DateTime(750, 5, 13);
66+
if (Sfi.ConnectionProvider.Driver.MinDate > expected)
67+
{
68+
Assert.Ignore($"The driver does not support dates below {Sfi.ConnectionProvider.Driver.MinDate:O}");
69+
}
70+
return ReadWriteAsync(expected);
71+
}
72+
catch (Exception ex)
73+
{
74+
return Task.FromException<object>(ex);
75+
}
76+
}
77+
6078
private async Task ReadWriteAsync(DateTime expected, CancellationToken cancellationToken = default(CancellationToken))
6179
{
6280
// Add an hour to check it is correctly ignored once read back from db.

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
using System;
22
using System.Data;
33
using NHibernate.Dialect;
4+
using NHibernate.Driver;
5+
using NHibernate.Engine;
46
using NUnit.Framework;
57

68
namespace NHibernate.Test.NHSpecificTest.NH2207
79
{
8-
[TestFixture, Ignore("Demostration of external issue")]
10+
[TestFixture]
911
public class SampleTest : BugTestCase
1012
{
1113
protected override bool AppliesTo(Dialect.Dialect dialect)
1214
{
13-
return dialect as MsSql2008Dialect != null;
15+
return dialect is MsSql2008Dialect;
16+
}
17+
18+
protected override bool AppliesTo(ISessionFactoryImplementor factory)
19+
{
20+
return factory.ConnectionProvider.Driver is Sql2008ClientDriver;
1421
}
1522

1623
[Test]
@@ -41,6 +48,7 @@ public void WithoutUseNHSqlDataProviderWorkProperly()
4148
var dateParam = command.CreateParameter();
4249
dateParam.ParameterName = "@p0";
4350
dateParam.DbType = DbType.Date;
51+
dateParam.SqlDbType = SqlDbType.Date;
4452
dateParam.Value = DateTime.MinValue.Date;
4553
command.Parameters.Add(dateParam);
4654
command.ExecuteNonQuery();
@@ -56,10 +64,9 @@ public void WithoutUseNHSqlDataProviderWorkProperly()
5664
command.CommandText = dropTable;
5765
command.ExecuteNonQuery();
5866
tx.Commit();
59-
}
67+
}
6068
}
6169
}
62-
6370
}
6471

6572
[Test]
@@ -85,4 +92,4 @@ public void Dates_Before_1753_Should_Not_Insert_Null()
8592
}
8693
}
8794
}
88-
}
95+
}

src/NHibernate.Test/TypesTest/DateTypeTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ public void ReadWriteMin()
6767
ReadWrite(expected);
6868
}
6969

70+
[Test]
71+
public void ReadWriteYear750()
72+
{
73+
var expected = new DateTime(750, 5, 13);
74+
if (Sfi.ConnectionProvider.Driver.MinDate > expected)
75+
{
76+
Assert.Ignore($"The driver does not support dates below {Sfi.ConnectionProvider.Driver.MinDate:O}");
77+
}
78+
ReadWrite(expected);
79+
}
80+
7081
private void ReadWrite(DateTime expected)
7182
{
7283
// Add an hour to check it is correctly ignored once read back from db.

0 commit comments

Comments
 (0)