PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/Raven.Tests/Linq/IsNullOrEmpty.cs

https://github.com/barryhagan/ravendb
C# | 118 lines | 104 code | 14 blank | 0 comment | 2 complexity | e2e716e3b2c3cd1d4ba4ee1be42ad10e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause, CC-BY-SA-3.0
  1. using System.Linq;
  2. using Raven.Tests.Common;
  3. using Xunit;
  4. namespace Raven.Tests.Linq
  5. {
  6. public class IsNullOrEmpty : RavenTest
  7. {
  8. private class TestDoc
  9. {
  10. public string SomeProperty { get; set; }
  11. }
  12. [Fact]
  13. public void IsNullOrEmptyEqTrue()
  14. {
  15. using (var store = NewDocumentStore())
  16. {
  17. using (var session = store.OpenSession())
  18. {
  19. session.Store(new TestDoc { SomeProperty = "Has some content" });
  20. session.Store(new TestDoc { SomeProperty = "" });
  21. session.Store(new TestDoc { SomeProperty = null });
  22. session.SaveChanges();
  23. }
  24. using (var session = store.OpenSession())
  25. {
  26. Assert.Equal(2, session.Query<TestDoc>().Count(p => string.IsNullOrEmpty(p.SomeProperty)));
  27. }
  28. WaitForUserToContinueTheTest(store);
  29. }
  30. }
  31. [Fact]
  32. public void IsNullOrEmptyEqFalse()
  33. {
  34. using (var store = NewDocumentStore())
  35. {
  36. using (var session = store.OpenSession())
  37. {
  38. session.Store(new TestDoc { SomeProperty = "Has some content" });
  39. session.Store(new TestDoc { SomeProperty = "" });
  40. session.Store(new TestDoc { SomeProperty = null });
  41. session.SaveChanges();
  42. }
  43. using (var session = store.OpenSession())
  44. {
  45. Assert.Equal(1, session.Query<TestDoc>().Count(p => string.IsNullOrEmpty(p.SomeProperty) == false));
  46. }
  47. }
  48. }
  49. [Fact]
  50. public void IsNullOrEmptyNegated()
  51. {
  52. using (var store = NewDocumentStore())
  53. {
  54. using (var session = store.OpenSession())
  55. {
  56. session.Store(new TestDoc { SomeProperty = "Has some content" });
  57. session.Store(new TestDoc { SomeProperty = "" });
  58. session.Store(new TestDoc { SomeProperty = null });
  59. session.SaveChanges();
  60. }
  61. using (var session = store.OpenSession())
  62. {
  63. Assert.Equal(1, session.Query<TestDoc>().Count(p => !string.IsNullOrEmpty(p.SomeProperty)));
  64. }
  65. }
  66. }
  67. [Fact]
  68. public void WithAny()
  69. {
  70. using (var store = NewDocumentStore())
  71. {
  72. using (var session = store.OpenSession())
  73. {
  74. session.Store(new TestDoc { SomeProperty = "Has some content" });
  75. session.Store(new TestDoc { SomeProperty = "" });
  76. session.Store(new TestDoc { SomeProperty = null });
  77. session.SaveChanges();
  78. }
  79. using (var session = store.OpenSession())
  80. {
  81. Assert.Equal(1, session.Query<TestDoc>().Count(p => p.SomeProperty.Any()));
  82. }
  83. }
  84. }
  85. [Fact]
  86. public void WithAnyEqFalse()
  87. {
  88. using (var store = NewDocumentStore())
  89. {
  90. using (var session = store.OpenSession())
  91. {
  92. session.Store(new TestDoc { SomeProperty = "Has some content" });
  93. session.Store(new TestDoc { SomeProperty = "" });
  94. session.Store(new TestDoc { SomeProperty = null });
  95. session.SaveChanges();
  96. }
  97. using (var session = store.OpenSession())
  98. {
  99. Assert.Equal(2, session.Query<TestDoc>().Count(p => p.SomeProperty.Any() == false));
  100. }
  101. }
  102. }
  103. }
  104. }