/Raven.Tests/Linq/IsNullOrEmpty.cs
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
- using System.Linq;
-
- using Raven.Tests.Common;
-
- using Xunit;
-
- namespace Raven.Tests.Linq
- {
- public class IsNullOrEmpty : RavenTest
- {
- private class TestDoc
- {
- public string SomeProperty { get; set; }
- }
-
- [Fact]
- public void IsNullOrEmptyEqTrue()
- {
- using (var store = NewDocumentStore())
- {
- using (var session = store.OpenSession())
- {
- session.Store(new TestDoc { SomeProperty = "Has some content" });
- session.Store(new TestDoc { SomeProperty = "" });
- session.Store(new TestDoc { SomeProperty = null });
- session.SaveChanges();
- }
-
- using (var session = store.OpenSession())
- {
- Assert.Equal(2, session.Query<TestDoc>().Count(p => string.IsNullOrEmpty(p.SomeProperty)));
- }
-
- WaitForUserToContinueTheTest(store);
- }
- }
-
- [Fact]
- public void IsNullOrEmptyEqFalse()
- {
- using (var store = NewDocumentStore())
- {
- using (var session = store.OpenSession())
- {
- session.Store(new TestDoc { SomeProperty = "Has some content" });
- session.Store(new TestDoc { SomeProperty = "" });
- session.Store(new TestDoc { SomeProperty = null });
- session.SaveChanges();
- }
-
- using (var session = store.OpenSession())
- {
- Assert.Equal(1, session.Query<TestDoc>().Count(p => string.IsNullOrEmpty(p.SomeProperty) == false));
- }
- }
- }
-
- [Fact]
- public void IsNullOrEmptyNegated()
- {
- using (var store = NewDocumentStore())
- {
- using (var session = store.OpenSession())
- {
- session.Store(new TestDoc { SomeProperty = "Has some content" });
- session.Store(new TestDoc { SomeProperty = "" });
- session.Store(new TestDoc { SomeProperty = null });
- session.SaveChanges();
- }
-
- using (var session = store.OpenSession())
- {
- Assert.Equal(1, session.Query<TestDoc>().Count(p => !string.IsNullOrEmpty(p.SomeProperty)));
- }
- }
- }
-
- [Fact]
- public void WithAny()
- {
- using (var store = NewDocumentStore())
- {
- using (var session = store.OpenSession())
- {
- session.Store(new TestDoc { SomeProperty = "Has some content" });
- session.Store(new TestDoc { SomeProperty = "" });
- session.Store(new TestDoc { SomeProperty = null });
- session.SaveChanges();
- }
-
- using (var session = store.OpenSession())
- {
- Assert.Equal(1, session.Query<TestDoc>().Count(p => p.SomeProperty.Any()));
- }
- }
- }
-
- [Fact]
- public void WithAnyEqFalse()
- {
- using (var store = NewDocumentStore())
- {
- using (var session = store.OpenSession())
- {
- session.Store(new TestDoc { SomeProperty = "Has some content" });
- session.Store(new TestDoc { SomeProperty = "" });
- session.Store(new TestDoc { SomeProperty = null });
- session.SaveChanges();
- }
-
- using (var session = store.OpenSession())
- {
- Assert.Equal(2, session.Query<TestDoc>().Count(p => p.SomeProperty.Any() == false));
- }
- }
- }
- }
- }