|
| 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.Linq; |
| 13 | +using NUnit.Framework; |
| 14 | +using NHibernate.Linq; |
| 15 | + |
| 16 | +namespace NHibernate.Test.NHSpecificTest.GH1712 |
| 17 | +{ |
| 18 | + using System.Threading.Tasks; |
| 19 | + using System.Threading; |
| 20 | + [TestFixture] |
| 21 | + public class FixtureAsync : BugTestCase |
| 22 | + { |
| 23 | + protected override void OnSetUp() |
| 24 | + { |
| 25 | + using (var session = OpenSession()) |
| 26 | + using (var tx = session.BeginTransaction()) |
| 27 | + { |
| 28 | + session.Save( |
| 29 | + "GenericEntityWithGuid", |
| 30 | + new GenericEntity<Guid>(), |
| 31 | + Guid.Parse("093D2C0D-C1A4-42CB-95FC-1039CD0C00B6")); |
| 32 | + session.Save("GenericEntityWithLong", new GenericEntity<long>(), 42L); |
| 33 | + session.Save("GenericEntityWithString", new GenericEntity<string>(), "Bob l'éponge"); |
| 34 | + session.Save("GenericEntityWithTimeSpan", new GenericEntity<TimeSpan>(), TimeSpan.FromDays(1)); |
| 35 | + tx.Commit(); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + protected override void OnTearDown() |
| 40 | + { |
| 41 | + base.OnTearDown(); |
| 42 | + using (var session = OpenSession()) |
| 43 | + using (var tx = session.BeginTransaction()) |
| 44 | + { |
| 45 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
| 46 | + tx.Commit(); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + [Test] |
| 51 | + public async Task QueryWithIEquatableEqualsShouldNotThrowAsync() |
| 52 | + { |
| 53 | + using (var session = Sfi.OpenSession()) |
| 54 | + { |
| 55 | + Assert.That( |
| 56 | + await (QueryIdAsync("GenericEntityWithGuid", Guid.Parse("093D2C0D-C1A4-42CB-95FC-1039CD0C00B6"), session)), |
| 57 | + Is.InstanceOf<GenericEntity<Guid>>()); |
| 58 | + Assert.That( |
| 59 | + await (QueryIdAsync("GenericEntityWithLong", 42L, session)), |
| 60 | + Is.InstanceOf<GenericEntity<long>>()); |
| 61 | + Assert.That( |
| 62 | + await (QueryIdAsync("GenericEntityWithString", "Bob l'éponge", session)), |
| 63 | + Is.InstanceOf<GenericEntity<string>>()); |
| 64 | + Assert.That( |
| 65 | + await (QueryIdAsync("GenericEntityWithTimeSpan", TimeSpan.FromDays(1), session)), |
| 66 | + Is.InstanceOf<GenericEntity<TimeSpan>>()); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + private Task<GenericEntity<TId>> QueryIdAsync<TId>(string name, TId id, ISession session, CancellationToken cancellationToken = default(CancellationToken)) where TId : IEquatable<TId> |
| 71 | + => (from e in session.Query<GenericEntity<TId>>(name) |
| 72 | + where e.Id.Equals(id) |
| 73 | + select e).FirstOrDefaultAsync(cancellationToken); |
| 74 | + |
| 75 | + [Test] |
| 76 | + public async Task QueryWithDefaultEqualsShouldNotThrowAsync() |
| 77 | + { |
| 78 | + using (var session = Sfi.OpenSession()) |
| 79 | + { |
| 80 | + Assert.That( |
| 81 | + await ((from e in session.Query<GenericEntity<Guid>>("GenericEntityWithGuid") |
| 82 | + where e.Id.Equals(Guid.Parse("093D2C0D-C1A4-42CB-95FC-1039CD0C00B6")) |
| 83 | + select e).FirstOrDefaultAsync()), |
| 84 | + Is.InstanceOf<GenericEntity<Guid>>()); |
| 85 | + Assert.That( |
| 86 | + await ((from e in session.Query<GenericEntity<long>>("GenericEntityWithLong") |
| 87 | + where e.Id.Equals(42L) |
| 88 | + select e).FirstOrDefaultAsync()), |
| 89 | + Is.InstanceOf<GenericEntity<long>>()); |
| 90 | + Assert.That( |
| 91 | + await ((from e in session.Query<GenericEntity<string>>("GenericEntityWithString") |
| 92 | + where e.Id.Equals("Bob l'éponge") |
| 93 | + select e).FirstOrDefaultAsync()), |
| 94 | + Is.InstanceOf<GenericEntity<string>>()); |
| 95 | + Assert.That( |
| 96 | + await ((from e in session.Query<GenericEntity<TimeSpan>>("GenericEntityWithTimeSpan") |
| 97 | + where e.Id.Equals(TimeSpan.FromDays(1)) |
| 98 | + select e).FirstOrDefaultAsync()), |
| 99 | + Is.InstanceOf<GenericEntity<TimeSpan>>()); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments