|
| 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 | +} |
0 commit comments