forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRavenArrayQueryInputTests.cs
62 lines (56 loc) · 1.82 KB
/
RavenArrayQueryInputTests.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
using System;
using System.Linq;
using Raven.Client.Indexes;
using Raven.Json.Linq;
using Raven.Tests.Helpers;
using Xunit;
namespace Raven.Tests.MailingList
{
public class RavenArrayQueryInputTests : RavenTestBase
{
public class Document
{
public string Id { get; set; }
}
public class TransformResult
{
public string Id { get; set; }
public int[] Array { get; set; }
}
public class TestTransformer : AbstractTransformerCreationTask<Document>
{
public TestTransformer()
{
TransformResults = documents => from d in documents
let index = Array.IndexOf(Parameter("array").Value<string>().Split(','), d.Id)
orderby index
select new
{
Id = d.Id,
Array = new[] {1, 2, 3}
};
}
}
[Fact]
public void CanUseArrayAsQueryInput()
{
using (var store = NewDocumentStore())
{
var transformer = new TestTransformer();
transformer.Execute(store);
using (var session = store.OpenSession())
{
session.Store(new Document());
session.Store(new Document());
session.Store(new Document());
session.SaveChanges();
}
using (var session = store.OpenSession())
{
var ids = new[] {"documents/3", "documents/1", "documents/2"};
session.Load<TestTransformer, TransformResult>(ids, c => c.AddTransformerParameter("array", string.Join(",", ids)));
}
}
}
}
}