Skip to content

Instantly share code, notes, and snippets.

@janv8000
Created February 21, 2013 08:28
Show Gist options
  • Save janv8000/5003189 to your computer and use it in GitHub Desktop.
Save janv8000/5003189 to your computer and use it in GitHub Desktop.
QueryNullableHasValue test for RavenDB
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