|
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,47 @@ 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."); |
72 | | - |
73 | | - string pName = ((ISqlParameterFormatter) sessions.ConnectionProvider.Driver).GetParameterName(0); |
74 | | - string expectedMessagePart0 = |
75 | | - string.Format( |
76 | | - @"could not execute query |
77 | | -[ 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] |
| 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."); |
| 74 | + |
| 75 | + string pName = ((ISqlParameterFormatter) sessions.ConnectionProvider.Driver).GetParameterName(0); |
| 76 | + string expectedMessagePart0 = |
| 77 | + string.Format("could not execute query" + Environment.NewLine + |
| 78 | + "[ SELECT this_.Id as y0_, count(this_.Area) as y1_ FROM TreeNode this_ WHERE this_.Id = {0} ]", |
| 79 | + pName); |
| 80 | + string expectedMessagePart1 = |
| 81 | + string.Format( |
| 82 | + @"[SQL: SELECT this_.Id as y0_, count(this_.Area) as y1_ FROM TreeNode this_ WHERE this_.Id = {0}]", pName); |
| 83 | + |
| 84 | + DetachedCriteria projection = DetachedCriteria.For<TreeNode>("child") |
| 85 | + .Add(Restrictions.Eq("child.Key.Id", 2)) |
| 86 | + .SetProjection( |
| 87 | + Projections.ProjectionList() |
| 88 | + .Add(Projections.Property("child.Key.Id")) |
| 89 | + .Add(Projections.Count("child.Key.Area")) |
| 90 | + ); |
| 91 | + |
| 92 | + |
| 93 | + var e = Assert.Throws<GenericADOException>(() => |
| 94 | + { |
| 95 | + using (var s = sessions.OpenSession()) |
| 96 | + using (var tx = s.BeginTransaction()) |
| 97 | + { |
| 98 | + var criteria = projection.GetExecutableCriteria(s); |
| 99 | + criteria.List(); |
| 100 | + |
| 101 | + tx.Commit(); |
| 102 | + } |
| 103 | + }); |
| 104 | + |
| 105 | + Assert.That(e.Message, Is.StringContaining(expectedMessagePart0).Or.StringContaining(expectedMessagePart1)); |
| 106 | + } |
| 107 | + |
| 108 | + [Test] |
108 | 109 | public void AggregatingHirearchyWithCount() |
109 | 110 | { |
110 | 111 | var root = new Key {Id = 1, Area = 2}; |
|
0 commit comments