|
2 | 2 | using NHibernate.Criterion;
|
3 | 3 | using NHibernate.Dialect;
|
4 | 4 | using NHibernate.Driver;
|
| 5 | +using NHibernate.Exceptions; |
5 | 6 | using NUnit.Framework;
|
6 | 7 |
|
7 | 8 | namespace NHibernate.Test.ProjectionFixtures
|
@@ -64,47 +65,48 @@ protected override void OnTearDown()
|
64 | 65 | }
|
65 | 66 |
|
66 | 67 |
|
67 |
| - [Test] |
68 |
| - public void ErrorFromDBWillGiveTheActualSQLExecuted() |
69 |
| - { |
70 |
| - if (!(Dialect is MsSql2000Dialect)) |
71 |
| - Assert.Ignore("Test checks for exact sql and expects an error to occur in a case which is not erroneous on all databases."); |
| 68 | + [Test] |
| 69 | + public void ErrorFromDBWillGiveTheActualSQLExecuted() |
| 70 | + { |
| 71 | + if (!(Dialect is MsSql2000Dialect)) |
| 72 | + Assert.Ignore( |
| 73 | + "Test checks for exact sql and expects an error to occur in a case which is not erroneous on all databases."); |
72 | 74 |
|
73 |
| - string pName = ((ISqlParameterFormatter) sessions.ConnectionProvider.Driver).GetParameterName(0); |
74 |
| - string expectedMessagePart0 = |
75 |
| - string.Format( |
76 |
| - @"could not execute query |
| 75 | + string pName = ((ISqlParameterFormatter) sessions.ConnectionProvider.Driver).GetParameterName(0); |
| 76 | + string expectedMessagePart0 = |
| 77 | + string.Format( |
| 78 | + @"could not execute query |
77 | 79 | [ SELECT this_.Id as y0_, count(this_.Area) as y1_ FROM TreeNode this_ WHERE this_.Id = {0} ]",
|
78 |
| - pName); |
79 |
| - string expectedMessagePart1 = string.Format(@"[SQL: SELECT this_.Id as y0_, count(this_.Area) as y1_ FROM TreeNode this_ WHERE this_.Id = {0}]",pName); |
80 |
| - |
81 |
| - DetachedCriteria projection = DetachedCriteria.For<TreeNode>("child") |
82 |
| - .Add(Restrictions.Eq("child.Key.Id", 2)) |
83 |
| - .SetProjection( |
84 |
| - Projections.ProjectionList() |
85 |
| - .Add(Projections.Property("child.Key.Id")) |
86 |
| - .Add(Projections.Count("child.Key.Area")) |
87 |
| - ); |
88 |
| - try |
89 |
| - { |
90 |
| - using (var s = sessions.OpenSession()) |
91 |
| - using (var tx = s.BeginTransaction()) |
92 |
| - { |
93 |
| - var criteria = projection.GetExecutableCriteria(s); |
94 |
| - criteria.List(); |
95 |
| - |
96 |
| - tx.Commit(); |
97 |
| - } |
98 |
| - Assert.Fail(); |
99 |
| - } |
100 |
| - catch (Exception e) |
101 |
| - { |
102 |
| - if (!e.Message.Contains(expectedMessagePart0) || !e.Message.Contains(expectedMessagePart1)) |
103 |
| - throw; |
104 |
| - } |
105 |
| - } |
106 |
| - |
107 |
| - [Test] |
| 80 | + pName); |
| 81 | + string expectedMessagePart1 = |
| 82 | + string.Format( |
| 83 | + @"[SQL: SELECT this_.Id as y0_, count(this_.Area) as y1_ FROM TreeNode this_ WHERE this_.Id = {0}]", pName); |
| 84 | + |
| 85 | + DetachedCriteria projection = DetachedCriteria.For<TreeNode>("child") |
| 86 | + .Add(Restrictions.Eq("child.Key.Id", 2)) |
| 87 | + .SetProjection( |
| 88 | + Projections.ProjectionList() |
| 89 | + .Add(Projections.Property("child.Key.Id")) |
| 90 | + .Add(Projections.Count("child.Key.Area")) |
| 91 | + ); |
| 92 | + |
| 93 | + |
| 94 | + var e = Assert.Throws<GenericADOException>(() => |
| 95 | + { |
| 96 | + using (var s = sessions.OpenSession()) |
| 97 | + using (var tx = s.BeginTransaction()) |
| 98 | + { |
| 99 | + var criteria = projection.GetExecutableCriteria(s); |
| 100 | + criteria.List(); |
| 101 | + |
| 102 | + tx.Commit(); |
| 103 | + } |
| 104 | + }); |
| 105 | + |
| 106 | + Assert.That(e.Message, Is.StringContaining(expectedMessagePart0).Or.StringContaining(expectedMessagePart1)); |
| 107 | + } |
| 108 | + |
| 109 | + [Test] |
108 | 110 | public void AggregatingHirearchyWithCount()
|
109 | 111 | {
|
110 | 112 | var root = new Key {Id = 1, Area = 2};
|
|
0 commit comments