forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeSpanIndexing.cs
116 lines (104 loc) · 3.93 KB
/
TimeSpanIndexing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// -----------------------------------------------------------------------
// <copyright file="TimeSpanIndexing.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Linq;
using Lucene.Net.Documents;
using Raven.Client;
using Raven.Client.Indexes;
using Xunit;
namespace Raven.Tests.Bugs
{
public class TimeSpanIndexing : IDisposable
{
private IDocumentStore Store { get; set; }
public TimeSpanIndexing()
{
Store = new Raven.Client.Embedded.EmbeddableDocumentStore {RunInMemory = true}
.Initialize();
new SimpleIndex().Execute(Store);
var indexes = Store.DatabaseCommands.GetIndexNames(0, int.MaxValue);
Assert.NotEmpty(indexes);
}
public void Dispose()
{
Store.Dispose();
}
[Fact]
public void CanStoreAndQueryBasicValueWithIndex()
{
using (var session = Store.OpenSession())
{
const string id = "one";
const string value = "value1";
session.Store(new Simple {Id = id, Value = value});
session.SaveChanges();
var result =
session.Query<Simple, SimpleIndex>()
.Customize(x => x.WaitForNonStaleResultsAsOfNow())
.FirstOrDefault(x => x.Id == id);
Assert.NotNull(result);
Assert.Equal(value, result.Value);
}
}
[Fact]
public void CanStoreTimeFormatInvalidValueAndQueryIndexForSameValue()
{
using (var session = Store.OpenSession())
{
const string id = "one";
const string value = "12:62";
session.Store(new Simple {Id = id, Value = value});
session.SaveChanges();
var result =
session.Query<Simple, SimpleIndex>()
.Customize(x => x.WaitForNonStaleResultsAsOfNow())
.FirstOrDefault(x => x.Id == id);
Assert.NotNull(result);
Assert.Equal(value, result.Value);
}
}
[Fact]
public void CanStoreTimeFormatValidValueAndQueryIndexForSameValue()
{
using (var session = Store.OpenSession())
{
const string id = "one";
const string value = "12:12";
session.Store(new Simple {Id = id, Value = value});
session.SaveChanges();
var result =
session.Query<Simple, SimpleIndex>()
.Customize(x => x.WaitForNonStaleResultsAsOfNow())
.FirstOrDefault(x => x.Id == id);
Assert.NotNull(result);
Assert.Equal(value, result.Value);
}
}
public class Simple
{
public string Id { get; set; }
public string Value { get; set; }
}
public class SimpleIndex : AbstractIndexCreationTask<Simple>
{
public SimpleIndex()
{
Map = mps => from s in mps
select new
{
s.Id
};
TransformResults = (db, results) => from r in results
let s = db.Load<Simple>(r.Id)
select new
{
r.Id,
s.Value
};
}
}
}
}