Skip to content
79 changes: 79 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH2820/FixtureByCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Linq;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Dialect;
using NHibernate.Mapping.ByCode;
using NUnit.Framework;
using NHibernate.Linq;

namespace NHibernate.Test.NHSpecificTest.GH2820
{
using System.Threading.Tasks;
[TestFixture]
public class PostgresTimestampzFixtureAsync : TestCaseMappingByCode
{
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Entity>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
rc.Property(x => x.Name);
rc.Property(x => x.Timestamp, m => m.Column(x => x.SqlType("timestamp with time zone")));
});

return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

protected override bool AppliesTo(Dialect.Dialect dialect)
{
return dialect is PostgreSQLDialect;
}

protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var e1 = new Entity {Name = "Bob", Timestamp = DateTimeOffset.UtcNow};
session.Save(e1);

transaction.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
}

[Test]
public async Task CanRetrieveEntityWithTimeStampColumnAsync()
{
using (var session = OpenSession())
{
var result = from e in session.Query<Entity>()
where e.Name == "Bob"
select e;

Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
}
}
}
}
11 changes: 11 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2820/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace NHibernate.Test.NHSpecificTest.GH2820
{
class Entity
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual DateTimeOffset Timestamp { get; set; }
}
}
67 changes: 67 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2820/FixtureByCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Linq;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Dialect;
using NHibernate.Mapping.ByCode;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH2820
{
[TestFixture]
public class PostgresTimestampzFixture : TestCaseMappingByCode
{
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Entity>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
rc.Property(x => x.Name);
rc.Property(x => x.Timestamp, m => m.Column(x => x.SqlType("timestamp with time zone")));
});

return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

protected override bool AppliesTo(Dialect.Dialect dialect)
{
return dialect is PostgreSQLDialect;
}

protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var e1 = new Entity {Name = "Bob", Timestamp = DateTimeOffset.UtcNow};
session.Save(e1);

transaction.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
}

[Test]
public void CanRetrieveEntityWithTimeStampColumn()
{
using (var session = OpenSession())
{
var result = from e in session.Query<Entity>()
where e.Name == "Bob"
select e;

Assert.That(result.ToList(), Has.Count.EqualTo(1));
}
}
}
}