forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFacetQueryNotCorrectWithDefaultFieldSpecified.cs
141 lines (120 loc) · 4.36 KB
/
FacetQueryNotCorrectWithDefaultFieldSpecified.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.Linq;
using Raven.Abstractions.Data;
using Raven.Client;
using Raven.Client.Document;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
using Raven.Client.Listeners;
using Raven.Tests.Common;
using Xunit;
namespace Raven.Tests.MailingList
{
public class FacetQueryNotCorrectWithDefaultFieldSpecified : RavenTest
{
/// <summary>
/// Works
/// </summary>
[Fact]
public void ShouldWorkWithEmbeddedRaven()
{
//arrange
using(var store = NewDocumentStore())
{
store.RegisterListener(new NoStaleQueriesListener());
SetupTestData(store);
WaitForIndexing(store);
//Act
FacetResults result = ExecuteTest(store);
//Assert
CheckResults(result);
}
}
/// <summary>
/// Should work but does not
/// </summary>
[Fact]
public void ShouldWorkWithRavenServer()
{
//arrange
using(var store = NewRemoteDocumentStore())
{
store.RegisterListener(new NoStaleQueriesListener());
SetupTestData(store);
WaitForIndexing(store);
//Act
FacetResults result = ExecuteTest(store);
WaitForUserToContinueTheTest();
//Assert
CheckResults(result);
}
}
private static void CheckResults(FacetResults result)
{
Assert.Contains("Brand", result.Results.Select(x=>x.Key));
FacetResult facetResult = result.Results["Brand"];
Assert.Equal(1, facetResult.Values.Count);
facetResult.Values[0] = new FacetValue { Range = "mybrand1", Hits = 1 };
}
private static FacetResults ExecuteTest(IDocumentStore store)
{
FacetResults result = store.DatabaseCommands.GetFacets("Product/AvailableForSale2", new IndexQuery { Query = "MyName1", DefaultField = "Any" }, "facets/ProductFacets");
return result;
}
private static void SetupTestData(IDocumentStore store)
{
new Product_AvailableForSale2().Execute(store);
Product product1 = new Product("MyName1", "MyBrand1");
Product product2 = new Product("MyName2", "MyBrand2");
FacetSetup facetSetup = new FacetSetup { Id = "facets/ProductFacets", Facets = new List<Facet> { new Facet { Name = "Brand" } } };
using (IDocumentSession docSession = store.OpenSession())
{
foreach (var productDoc in docSession.Query<Product>())
{
docSession.Delete(productDoc);
}
docSession.SaveChanges();
docSession.Store(product1);
docSession.Store(product2);
docSession.Store(facetSetup);
docSession.SaveChanges();
}
}
public class Product
{
public Product(string name, string brand)
{
Name = name;
Brand = brand;
}
public string Id { get; set; }
public string Name { get; set; }
public string Brand { get; set; }
}
public class Product_AvailableForSale2 : AbstractIndexCreationTask<Product>
{
public Product_AvailableForSale2()
{
Map = products => from p in products
select new
{
p.Name,
p.Brand,
Any = new object[]
{
p.Name,
p.Brand
}
};
}
}
public class NoStaleQueriesListener : IDocumentQueryListener
{
public void BeforeQueryExecuted(IDocumentQueryCustomization queryCustomization)
{
queryCustomization.WaitForNonStaleResults(TimeSpan.FromSeconds(30));
}
}
}
}