-
Notifications
You must be signed in to change notification settings - Fork 16
/
ravendb_9676_test.go
102 lines (78 loc) · 2.22 KB
/
ravendb_9676_test.go
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
package tests
import (
"reflect"
"testing"
ravendb "github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
func ravendb9676canOrderByDistanceOnDynamicSpatialField(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
{
session := openSessionMust(t, store)
item := &Item{
Name: "Item1",
Latitude: 10,
Longitude: 10,
}
err = session.Store(item)
assert.NoError(t, err)
item1 := &Item{
Name: "Item2",
Latitude: 11,
Longitude: 11,
}
err = session.Store(item1)
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
var items []*Item
q := session.QueryCollectionForType(reflect.TypeOf(&Item{}))
q = q.WaitForNonStaleResults(0)
f := ravendb.NewPointField("latitude", "longitude")
fn := func(f *ravendb.SpatialCriteriaFactory) ravendb.SpatialCriteria {
return f.WithinRadius(1000, 10, 10)
}
q = q.Spatial2(f, fn)
q2 := q.OrderByDistanceLatLongDynamic(ravendb.NewPointField("latitude", "longitude"), 10, 10)
err = q2.GetResults(&items)
assert.NoError(t, err)
assert.Equal(t, len(items), 2)
session.Close()
item := items[0]
assert.Equal(t, item.Name, "Item1")
item = items[1]
assert.Equal(t, item.Name, "Item2")
items = nil
q = session.QueryCollectionForType(reflect.TypeOf(&Item{}))
q = q.WaitForNonStaleResults(0)
f = ravendb.NewPointField("latitude", "longitude")
q = q.Spatial2(f, fn)
q2 = q.OrderByDistanceDescendingLatLongDynamic(ravendb.NewPointField("latitude", "longitude"), 10, 10)
err = q2.GetResults(&items)
assert.NoError(t, err)
assert.Equal(t, len(items), 2)
session.Close()
item = items[0]
assert.Equal(t, item.Name, "Item2")
item = items[1]
assert.Equal(t, item.Name, "Item1")
}
}
type Item struct {
Name string `json:"name"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
func TestRavenDB9676(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// matches the order of Java tests
ravendb9676canOrderByDistanceOnDynamicSpatialField(t, driver)
}