PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NHibernate.Test/NHSpecificTest/NH3386/Fixture.cs

https://github.com/ngbrown/nhibernate-core
C# | 80 lines | 69 code | 11 blank | 0 comment | 0 complexity | 1297fe3ffe7e1612eea144bf368a0000 MD5 | raw file
  1. using System.Linq;
  2. using NHibernate.Linq;
  3. using NUnit.Framework;
  4. using System;
  5. using NHibernate.SqlCommand;
  6. namespace NHibernate.Test.NHSpecificTest.NH3386
  7. {
  8. [TestFixture]
  9. public class Fixture : BugTestCase
  10. {
  11. protected override bool AppliesTo(Dialect.Dialect dialect)
  12. {
  13. return dialect is Dialect.MsSql2000Dialect;
  14. }
  15. protected override void OnSetUp()
  16. {
  17. using (ISession session = OpenSession())
  18. using (ITransaction transaction = session.BeginTransaction())
  19. {
  20. var e1 = new Entity {Name = "Bob"};
  21. session.Save(e1);
  22. var e2 = new Entity {Name = "Sally"};
  23. session.Save(e2);
  24. session.Flush();
  25. transaction.Commit();
  26. }
  27. }
  28. protected override void OnTearDown()
  29. {
  30. using (ISession session = OpenSession())
  31. using (ITransaction transaction = session.BeginTransaction())
  32. {
  33. session.Delete("from System.Object");
  34. session.Flush();
  35. transaction.Commit();
  36. }
  37. }
  38. [Test]
  39. public void ShouldSupportNonRuntimeExtensionWithoutEntityReference()
  40. {
  41. var sqlInterceptor = new SqlInterceptor();
  42. using (ISession session = OpenSession(sqlInterceptor))
  43. using (session.BeginTransaction())
  44. {
  45. var result = session.Query<Entity>()
  46. .OrderBy(e => SqlServerFunction.NewID());
  47. Assert.DoesNotThrow(() => { result.ToList(); });
  48. Assert.That(sqlInterceptor.Sql.ToString(), Does.Contain(nameof(SqlServerFunction.NewID)).IgnoreCase);
  49. }
  50. }
  51. }
  52. public static class SqlServerFunction
  53. {
  54. [LinqExtensionMethod]
  55. public static Guid NewID()
  56. {
  57. throw new InvalidOperationException("To be translated to SQL only");
  58. }
  59. }
  60. public class SqlInterceptor: EmptyInterceptor
  61. {
  62. public SqlString Sql { get; private set; }
  63. public override SqlString OnPrepareStatement(SqlString sql)
  64. {
  65. Sql = sql;
  66. return base.OnPrepareStatement(sql);
  67. }
  68. }
  69. }