Skip to content

Commit

Permalink
Adding passing test - date ranges using lucene
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Aug 12, 2010
1 parent c01432b commit 721c50e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
117 changes: 117 additions & 0 deletions Raven.Client.Tests/Bugs/DateRanges.cs
@@ -0,0 +1,117 @@
using System;
using Raven.Client.Linq;
using Raven.Database.Indexing;
using Xunit;
using System.Linq;

namespace Raven.Client.Tests.Bugs
{
public class DateRanges : BaseClientTest
{
[Fact]
public void CanQueryByDate()
{
using(var store = NewDocumentStore())
{
using(var session = store.OpenSession())
{
session.Store(new Record
{
Date = new DateTime(2001,1,1)
});
session.SaveChanges();
}

store.DatabaseCommands.PutIndex("Date",
new IndexDefinition
{
Map = "from doc in docs select new { doc.Date}"
});


using(var session = store.OpenSession())
{
var result = session.LuceneQuery<Record>("Date")
.Where("Date:" + DateTools.DateToString(new DateTime(2001,1,1), DateTools.Resolution.MILLISECOND))
.WaitForNonStaleResults()
.ToList();

Assert.Equal(1, result.Count);
}
}
}


[Fact]
public void CanQueryByDateRange_LowerThan()
{
using (var store = NewDocumentStore())
{
using (var session = store.OpenSession())
{
session.Store(new Record
{
Date = new DateTime(2001, 1, 1)
});
session.SaveChanges();
}

store.DatabaseCommands.PutIndex("Date",
new IndexDefinition
{
Map = "from doc in docs select new { doc.Date}"
});


using (var session = store.OpenSession())
{
var result = session.LuceneQuery<Record>("Date")
.Where("Date:[* TO " + DateTools.DateToString(new DateTime(2001, 1, 2), DateTools.Resolution.MILLISECOND) +"]")
.WaitForNonStaleResults()
.ToList();

Assert.Equal(1, result.Count);
}
}
}


[Fact]
public void CanQueryByDateRange_GreaterThan()
{
using (var store = NewDocumentStore())
{
using (var session = store.OpenSession())
{
session.Store(new Record
{
Date = new DateTime(2001, 1, 1)
});
session.SaveChanges();
}

store.DatabaseCommands.PutIndex("Date",
new IndexDefinition
{
Map = "from doc in docs select new { doc.Date}"
});


using (var session = store.OpenSession())
{
var result = session.LuceneQuery<Record>("Date")
.Where("Date:[" + DateTools.DateToString(new DateTime(2000, 1, 1), DateTools.Resolution.MILLISECOND) + " TO NULL]")
.WaitForNonStaleResults()
.ToList();

Assert.Equal(1, result.Count);
}
}
}
public class Record
{
public string Id { get; set; }
public DateTime Date { get; set; }
}
}
}
1 change: 1 addition & 0 deletions Raven.Client.Tests/Raven.Client.Tests.csproj
Expand Up @@ -103,6 +103,7 @@
<Compile Include="Bugs\CanDetectChanges.cs" />
<Compile Include="Bugs\CanSelectFieldsFromIndex.cs" />
<Compile Include="Bugs\CustomEntityName.cs" />
<Compile Include="Bugs\DateRanges.cs" />
<Compile Include="Bugs\DecimalPrecision.cs" />
<Compile Include="Bugs\EntityWithDate.cs" />
<Compile Include="Bugs\Etag.cs" />
Expand Down

0 comments on commit 721c50e

Please sign in to comment.