|
| 1 | +using NHibernate.Criterion; |
| 2 | +using NHibernate.Transform; |
| 3 | +using NUnit.Framework; |
| 4 | + |
| 5 | +namespace NHibernate.Test.NHSpecificTest.NH3609 |
| 6 | +{ |
| 7 | + [TestFixture] |
| 8 | + public class Fixture : BugTestCase |
| 9 | + { |
| 10 | + protected override void OnSetUp() |
| 11 | + { |
| 12 | + using (var session = OpenSession()) |
| 13 | + using (var transaction = session.BeginTransaction()) |
| 14 | + { |
| 15 | + var e1 = new Entity {Name = "Bob"}; |
| 16 | + session.Save(e1); |
| 17 | + |
| 18 | + var e2 = new Entity {Name = "Sally"}; |
| 19 | + session.Save(e2); |
| 20 | + |
| 21 | + session.Flush(); |
| 22 | + transaction.Commit(); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + protected override void OnTearDown() |
| 27 | + { |
| 28 | + using (var session = OpenSession()) |
| 29 | + using (var transaction = session.BeginTransaction()) |
| 30 | + { |
| 31 | + session.Delete("from System.Object"); |
| 32 | + |
| 33 | + session.Flush(); |
| 34 | + transaction.Commit(); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + [Test] |
| 39 | + public void AvgWithConditionalDoesNotThrow() |
| 40 | + { |
| 41 | + using (var session = OpenSession()) |
| 42 | + using (session.BeginTransaction()) |
| 43 | + { |
| 44 | + MappingEntity mappingEntity = null; |
| 45 | + Assert.DoesNotThrow( |
| 46 | + () => |
| 47 | + session.QueryOver<Entity>().SelectList( |
| 48 | + builder => |
| 49 | + builder.Select( |
| 50 | + Projections.Avg( |
| 51 | + Projections.Conditional( |
| 52 | + Restrictions.Eq(Projections.Property<Entity>(x => x.Name), "FOO"), |
| 53 | + Projections.Constant("", NHibernateUtil.String), |
| 54 | + Projections.Constant(null, NHibernateUtil.String))).WithAlias(() => mappingEntity.Count)) |
| 55 | + ).TransformUsing(Transformers.AliasToBean<MappingEntity>()).List<MappingEntity>() |
| 56 | + ); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + [Test] |
| 61 | + public void CountWithConditionalDoesNotThrow() |
| 62 | + { |
| 63 | + using (var session = OpenSession()) |
| 64 | + using (session.BeginTransaction()) |
| 65 | + { |
| 66 | + MappingEntity mappingEntity = null; |
| 67 | + Assert.DoesNotThrow( |
| 68 | + () => |
| 69 | + session.QueryOver<Entity>().SelectList( |
| 70 | + builder => |
| 71 | + builder.Select( |
| 72 | + Projections.Count( |
| 73 | + Projections.Conditional( |
| 74 | + Restrictions.Eq(Projections.Property<Entity>(x => x.Name), "FOO"), |
| 75 | + Projections.Constant("", NHibernateUtil.String), |
| 76 | + Projections.Constant(null, NHibernateUtil.String))).WithAlias(() => mappingEntity.Count)) |
| 77 | + ).TransformUsing(Transformers.AliasToBean<MappingEntity>()).List<MappingEntity>() |
| 78 | + ); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + [Test, Ignore("Not fixed yet")] |
| 83 | + public void GroupByClauseHasParameterSet() |
| 84 | + { |
| 85 | + using (var session = OpenSession()) |
| 86 | + using (session.BeginTransaction()) |
| 87 | + { |
| 88 | + MappingEntity mappingEntity = null; |
| 89 | + Assert.DoesNotThrow( |
| 90 | + () => |
| 91 | + session.QueryOver<Entity>().SelectList( |
| 92 | + builder => |
| 93 | + builder.Select( |
| 94 | + Projections.GroupProperty( |
| 95 | + Projections.Conditional( |
| 96 | + Restrictions.Eq(Projections.Property<Entity>(x => x.Name), ""), |
| 97 | + Projections.Constant(1), |
| 98 | + Projections.Constant(2))) |
| 99 | + .WithAlias(() => mappingEntity.Count)) |
| 100 | + ).TransformUsing(Transformers.AliasToBean<MappingEntity>()).List<MappingEntity>() |
| 101 | + ); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments