Created
February 21, 2013 08:28
-
-
Save janv8000/5003189 to your computer and use it in GitHub Desktop.
QueryNullableHasValue test for RavenDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using Xunit; | |
namespace Raven.Tests.Bugs | |
{ | |
public class QueryNullableHasValue : RavenTest | |
{ | |
[Fact] | |
public void CanQueryWithNullComparison() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
using (var s = store.OpenSession()) | |
{ | |
s.Store(new WithNullableField { TheNullableField = 1 }); | |
s.Store(new WithNullableField { TheNullableField = null }); | |
s.SaveChanges(); | |
} | |
using (var s = store.OpenSession()) | |
{ | |
Assert.Equal(1, s.Query<WithNullableField>().Customize(x => x.WaitForNonStaleResults(TimeSpan.MaxValue)).Count(x => x.TheNullableField == null)); | |
Assert.Equal(1, s.Query<WithNullableField>().Customize(x => x.WaitForNonStaleResults(TimeSpan.MaxValue)).Count(x => x.TheNullableField != null)); | |
} | |
} | |
} | |
[Fact] | |
public void CanQueryWithHasValue() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
using (var s = store.OpenSession()) | |
{ | |
s.Store(new WithNullableField { TheNullableField = 1 }); | |
s.Store(new WithNullableField { TheNullableField = null }); | |
s.SaveChanges(); | |
} | |
using (var s = store.OpenSession()) | |
{ | |
Assert.Equal(1, s.Query<WithNullableField>().Customize(x => x.WaitForNonStaleResults(TimeSpan.MaxValue)).Count(x => !x.TheNullableField.HasValue)); | |
Assert.Equal(1, s.Query<WithNullableField>().Customize(x => x.WaitForNonStaleResults(TimeSpan.MaxValue)).Count(x => x.TheNullableField.HasValue)); | |
} | |
} | |
} | |
public class WithNullableField | |
{ | |
public int? TheNullableField | |
{ get; set; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment