forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCanLoadDocumentArray.cs
78 lines (67 loc) · 2.73 KB
/
CanLoadDocumentArray.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
using System.Linq;
using Raven.Client.Indexes;
using Raven.Tests.Common;
using Raven.Tests.Helpers;
using Xunit;
using System.Collections.Generic;
using Raven.Abstractions.Indexing;
namespace Raven.Tests.MailingList
{
public class CanLoadDocumentArray : RavenTestBase
{
private class Student
{
public string Id { get; set; }
public string Email { get; set; }
public IEnumerable<string> Friends { get; set; }
}
private class Students_WithFriends
: AbstractIndexCreationTask<Student, Students_WithFriends.Mapping>
{
public class Mapping
{
public string EmailDomain { get; set; }
public IEnumerable<string> Friends { get; set; }
}
public Students_WithFriends()
{
Map = students => from student in students
let friends = LoadDocument<Student>(student.Friends)
select new Mapping
{
EmailDomain = student.Email.Split('@').Last(),
Friends = friends.Select(a => a.Email)
};
Analyzers.Add(x => x.Friends, "Lucene.Net.Analysis.SimpleAnalyzer, Lucene.Net");
Indexes.Add(x => x.Friends, FieldIndexing.Analyzed);
}
}
[Fact]
public void WillSupportLoadDocumentArray()
{
using (var store = NewDocumentStore())
{
using (var session = store.OpenSession())
{
var student1 = new Student { Email = "support@something.com" };
var student2 = new Student { Email = "ayende@something.com" };
var student3 = new Student { Email = "oren@something.com" };
session.Store(student1);
session.Store(student2);
student3.Friends = new List<string>() { student1.Id, student2.Id };
session.Store(student3);
session.SaveChanges();
}
new Students_WithFriends().Execute(store);
using (var session = store.OpenSession())
{
var results = session.Query<Student, Students_WithFriends>()
.Customize(customization => customization.WaitForNonStaleResults())
.ToList();
Assert.Empty(store.DatabaseCommands.GetStatistics().Errors);
Assert.Equal(3, results.Count);
}
}
}
}
}