|
1 | 1 | using System;
|
2 |
| -using System.Collections; |
3 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Linq; |
4 | 4 | using System.Text.RegularExpressions;
|
5 | 5 | using NHibernate.Criterion;
|
6 | 6 | using NHibernate.Dialect;
|
@@ -78,7 +78,7 @@ public void UsingSqlFunctions_Concat()
|
78 | 78 | [Test]
|
79 | 79 | public void UsingSqlFunctions_Concat_WithCast()
|
80 | 80 | {
|
81 |
| - if(Dialect is Oracle8iDialect) |
| 81 | + if (Dialect is Oracle8iDialect) |
82 | 82 | {
|
83 | 83 | Assert.Ignore("Not supported by the active dialect:{0}.", Dialect);
|
84 | 84 | }
|
@@ -198,6 +198,84 @@ public void UsingConditionals()
|
198 | 198 | }
|
199 | 199 | }
|
200 | 200 |
|
| 201 | + [Test] |
| 202 | + public void UsingMultiConditionals() |
| 203 | + { |
| 204 | + if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters) |
| 205 | + Assert.Ignore("Current dialect does not support this test"); |
| 206 | + |
| 207 | + var students = new[] |
| 208 | + { |
| 209 | + new Student() { StudentNumber = 6L, Name = "testa", }, |
| 210 | + new Student() { StudentNumber = 5L, Name = "testz", }, |
| 211 | + new Student() { StudentNumber = 4L, Name = "test1", }, |
| 212 | + new Student() { StudentNumber = 3L, Name = "test2", }, |
| 213 | + new Student() { StudentNumber = 2L, Name = "test998", }, |
| 214 | + new Student() { StudentNumber = 1L, Name = "test999", }, |
| 215 | + }; |
| 216 | + |
| 217 | + var expecteds = new[] |
| 218 | + { |
| 219 | + students[0], |
| 220 | + students[1], |
| 221 | + students[2], |
| 222 | + students[3], |
| 223 | + }; |
| 224 | + |
| 225 | + // student, sortingindex |
| 226 | + var testData = new Tuple<Student, string>[] |
| 227 | + { |
| 228 | + System.Tuple.Create(expecteds[0], "1"), |
| 229 | + System.Tuple.Create(expecteds[1], "2"), |
| 230 | + System.Tuple.Create(expecteds[2], "3"), |
| 231 | + System.Tuple.Create(expecteds[3], "4"), |
| 232 | + }; |
| 233 | + |
| 234 | + using (ISession session = this.Sfi.OpenSession()) |
| 235 | + { |
| 236 | + using (ITransaction transaction = session.BeginTransaction()) |
| 237 | + { |
| 238 | + session.Save<Student>(students); |
| 239 | + transaction.Commit(); |
| 240 | + } |
| 241 | + |
| 242 | + using (ITransaction transaction = session.BeginTransaction()) |
| 243 | + { |
| 244 | + // when Name = "testa" then 1 ... |
| 245 | + var criterionProjections = testData |
| 246 | + .Select(x => new ConditionalCriterionProjectionPair(Expression.Eq(nameof(Student.Name), x.Item1.Name), Projections.Constant(x.Item2))) |
| 247 | + .ToArray(); |
| 248 | + |
| 249 | + // ... else 99 |
| 250 | + var elseProjection = Projections.Constant("99"); |
| 251 | + |
| 252 | + var conditionalsProjection = Projections.Conditionals(criterionProjections, elseProjection); |
| 253 | + |
| 254 | + var order = Order.Asc(conditionalsProjection); |
| 255 | + |
| 256 | + var criteria = session.CreateCriteria(typeof(Student)) |
| 257 | + .AddOrder(order); |
| 258 | + |
| 259 | + var actuals = criteria.List<Student>(); |
| 260 | + |
| 261 | + Assert.GreaterOrEqual(actuals.Count, expecteds.Length); |
| 262 | + for (int i = 0; i < expecteds.Length; i++) |
| 263 | + { |
| 264 | + var expected = expecteds[i]; |
| 265 | + var actual = actuals[i]; |
| 266 | + |
| 267 | + Assert.AreEqual(expected.Name, actual.Name); |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + using (ITransaction transaction = session.BeginTransaction()) |
| 272 | + { |
| 273 | + session.Delete<Student>(students); |
| 274 | + transaction.Commit(); |
| 275 | + } |
| 276 | + } |
| 277 | + } |
| 278 | + |
201 | 279 | [Test]
|
202 | 280 | public void UseInWithProjection()
|
203 | 281 | {
|
|
0 commit comments