|
| 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 NHibernate.Cfg.MappingSchema; |
| 12 | +using NHibernate.Criterion; |
| 13 | +using NHibernate.Mapping.ByCode; |
| 14 | +using NUnit.Framework; |
| 15 | + |
| 16 | +namespace NHibernate.Test.NHSpecificTest.GH1180 |
| 17 | +{ |
| 18 | + using System.Threading.Tasks; |
| 19 | + [KnownBug("NH-3847 (GH-1180)")] |
| 20 | + [TestFixture] |
| 21 | + public class ByCodeFixtureAsync : TestCaseMappingByCode |
| 22 | + { |
| 23 | + protected override HbmMapping GetMappings() |
| 24 | + { |
| 25 | + var mapper = new ModelMapper(); |
| 26 | + |
| 27 | + mapper.Class<Entity>(rc => |
| 28 | + { |
| 29 | + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); |
| 30 | + rc.Property(x => x.Name, m => { m.Length(10); }); |
| 31 | + rc.Property(x => x.Amount, m => { m.Precision(8); m.Scale(2); }); |
| 32 | + }); |
| 33 | + |
| 34 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 35 | + } |
| 36 | + |
| 37 | + protected override void OnTearDown() |
| 38 | + { |
| 39 | + using (var session = OpenSession()) |
| 40 | + using (var transaction = session.BeginTransaction()) |
| 41 | + { |
| 42 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
| 43 | + transaction.Commit(); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + [Test] |
| 48 | + public async Task StringTypesAsync() |
| 49 | + { |
| 50 | + using (var session = OpenSession()) |
| 51 | + using (var transaction = session.BeginTransaction()) |
| 52 | + { |
| 53 | + // data |
| 54 | + await (session.SaveAsync(new Entity {Name = "Alpha"})); |
| 55 | + await (session.SaveAsync(new Entity {Name = "Beta"})); |
| 56 | + await (session.SaveAsync(new Entity {Name = "Gamma"})); |
| 57 | + |
| 58 | + await (transaction.CommitAsync()); |
| 59 | + } |
| 60 | + |
| 61 | + // whenTrue is constant, whenFalse is property -> works even before the fix |
| 62 | + using (var session = OpenSession()) |
| 63 | + { |
| 64 | + ICriteria tagCriteria = session.CreateCriteria(typeof(Entity)); |
| 65 | + |
| 66 | + var conditionalProjection = Projections.Conditional( |
| 67 | + Restrictions.Not( |
| 68 | + Restrictions.Like(nameof(Entity.Name), "B%")), |
| 69 | + Projections.Constant("other"), |
| 70 | + Projections.Property(nameof(Entity.Name))); |
| 71 | + tagCriteria.SetProjection(conditionalProjection); |
| 72 | + |
| 73 | + // run query |
| 74 | + var results = await (tagCriteria.ListAsync()); |
| 75 | + |
| 76 | + Assert.That(results, Is.EquivalentTo(new[] {"other", "Beta", "other"})); |
| 77 | + } |
| 78 | + |
| 79 | + // whenTrue is property, whenFalse is constant -> fails before the fix |
| 80 | + using (var session = OpenSession()) |
| 81 | + { |
| 82 | + ICriteria tagCriteria = session.CreateCriteria(typeof(Entity)); |
| 83 | + |
| 84 | + var conditionalProjection = Projections.Conditional( |
| 85 | + Restrictions.Like(nameof(Entity.Name), "B%"), |
| 86 | + Projections.Property(nameof(Entity.Name)), |
| 87 | + Projections.Constant("other")); |
| 88 | + tagCriteria.SetProjection(conditionalProjection); |
| 89 | + |
| 90 | + // run query |
| 91 | + var results = await (tagCriteria.ListAsync()); |
| 92 | + |
| 93 | + Assert.That(results, Is.EquivalentTo(new[] {"other", "Beta", "other"})); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + [Test] |
| 98 | + public async Task DecimalTypesAsync() |
| 99 | + { |
| 100 | + using (var session = OpenSession()) |
| 101 | + using (var transaction = session.BeginTransaction()) |
| 102 | + { |
| 103 | + await (session.SaveAsync(new Entity {Amount = 3.14m})); |
| 104 | + await (session.SaveAsync(new Entity {Amount = 42.13m})); |
| 105 | + await (session.SaveAsync(new Entity {Amount = 17.99m})); |
| 106 | + |
| 107 | + await (transaction.CommitAsync()); |
| 108 | + } |
| 109 | + |
| 110 | + // whenTrue is constant, whenFalse is property -> works even before the fix |
| 111 | + using (var session = OpenSession()) |
| 112 | + { |
| 113 | + ICriteria tagCriteria = session.CreateCriteria(typeof(Entity)); |
| 114 | + |
| 115 | + var conditionalProjection = Projections.Conditional( |
| 116 | + Restrictions.Not( |
| 117 | + Restrictions.Ge(nameof(Entity.Amount), 20m)), |
| 118 | + Projections.Constant(20m), |
| 119 | + Projections.Property(nameof(Entity.Amount))); |
| 120 | + tagCriteria.SetProjection(conditionalProjection); |
| 121 | + |
| 122 | + // run query |
| 123 | + var results = await (tagCriteria.ListAsync()); |
| 124 | + |
| 125 | + Assert.That(results, Is.EquivalentTo(new[] {20m, 42.13m, 20m})); |
| 126 | + } |
| 127 | + |
| 128 | + // whenTrue is property, whenFalse is constant -> fails before the fix |
| 129 | + using (var session = OpenSession()) |
| 130 | + { |
| 131 | + ICriteria tagCriteria = session.CreateCriteria(typeof(Entity)); |
| 132 | + |
| 133 | + var conditionalProjection = Projections.Conditional( |
| 134 | + Restrictions.Ge(nameof(Entity.Amount), 20m), |
| 135 | + Projections.Property(nameof(Entity.Amount)), |
| 136 | + Projections.Constant(20m)); |
| 137 | + tagCriteria.SetProjection(conditionalProjection); |
| 138 | + |
| 139 | + // run query |
| 140 | + var results = await (tagCriteria.ListAsync()); |
| 141 | + |
| 142 | + Assert.That(results, Is.EquivalentTo(new[] {20m, 42.13m, 20m})); |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | +} |
0 commit comments