|
| 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 CountWithConditionalDoesNotThrow() |
| 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.Count( |
| 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, Ignore("Not fixed yet")] |
| 61 | +public void GroupByClauseHasParameterSet() |
| 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.GroupProperty( |
| 73 | +Projections.Conditional( |
| 74 | +Restrictions.Eq(Projections.Property<Entity>(x => x.Name), ""), |
| 75 | +Projections.Constant(1), |
| 76 | +Projections.Constant(2))) |
| 77 | + .WithAlias(() => mappingEntity.Count)) |
| 78 | +).TransformUsing(Transformers.AliasToBean<MappingEntity>()).List<MappingEntity>() |
| 79 | +); |
| 80 | +} |
| 81 | +} |
| 82 | +} |
| 83 | +} |
0 commit comments