PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/okb/nhibernate-core
C# | 75 lines | 57 code | 15 blank | 3 comment | 0 complexity | df5a437c5b8be8ce899ff24acada25b8 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception, LGPL-3.0, Apache-2.0, CC-BY-SA-3.0
  1. using System.Linq;
  2. using NHibernate.Linq;
  3. using NUnit.Framework;
  4. namespace NHibernate.Test.NHSpecificTest.NH2846
  5. {
  6. [TestFixture]
  7. public class Fixture : BugTestCase
  8. {
  9. protected override void OnSetUp()
  10. {
  11. base.OnSetUp();
  12. using (var session = OpenSession())
  13. {
  14. using (var tran = session.BeginTransaction())
  15. {
  16. // Add a test category
  17. var category = new Category { Id = 1, Title = "Cat 1" };
  18. session.Save(category);
  19. // Add a test post
  20. var post = new Post { Id = 1, Title = "Post 1", Category = category };
  21. session.Save(post);
  22. var comment1 = new Comment { Id = 1, Title = "Comment 1", Post = post };
  23. var comment2 = new Comment { Id = 2, Title = "Comment 2", Post = post };
  24. session.Save(comment1);
  25. session.Save(comment2);
  26. session.Save(post);
  27. // Flush the changes
  28. session.Flush();
  29. tran.Commit();
  30. }
  31. }
  32. }
  33. protected override void OnTearDown()
  34. {
  35. base.OnTearDown();
  36. using (var session = OpenSession())
  37. {
  38. using (var tran = session.BeginTransaction())
  39. {
  40. session.Delete("from Comment");
  41. session.Delete("from Post");
  42. session.Delete("from Category");
  43. tran.Commit();
  44. }
  45. }
  46. }
  47. [Test]
  48. public void FetchOnCountWorks()
  49. {
  50. using (var session = OpenSession())
  51. {
  52. var count = session.Query<Post>()
  53. .Fetch(p => p.Category)
  54. .FetchMany(p => p.Comments)
  55. .Count();
  56. Assert.AreEqual(1, count);
  57. }
  58. }
  59. }
  60. }