Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding passing test - date ranges using lucene
- Loading branch information
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} | ||
} |
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