forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SelfReference.cs
75 lines (63 loc) · 1.43 KB
/
SelfReference.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Raven.Json.Linq;
using Xunit;
namespace Raven.Tests.Bugs
{
public class SelfReference : LocalClientTest
{
[JsonObject(IsReference = true)]
public class Foo
{
// No default ctor!!!
public Foo(string something)
{
}
public Foo OtherFoo { get; set; }
}
public class Bar
{
public string Id { get; set; }
public Foo MyFoo { get; private set; }
public Bar()
{
MyFoo = new Foo("something");
}
}
[Fact]
public void Should_deserialize_correctly()
{
var rjson = RavenJToken.FromObject(new Bar()).ToString();
var robj = RavenJToken.Parse(rjson);
var json = JToken.FromObject(new Bar()).ToString();
var obj = JToken.Parse(json);
Assert.Equal(json, rjson);
using (var store = NewDocumentStore())
{
string id;
using (var session = store.OpenSession())
{
var bar = new Bar();
session.Store(bar);
session.SaveChanges();
id = bar.Id;
}
using (var session = store.OpenSession())
{
var bar = session.Load<Bar>(id);
Assert.NotNull(bar);
}
WaitForIndexing(store);
using (var session = store.OpenSession())
{
var bar = session.Query<Bar>().FirstOrDefault();
Assert.NotNull(bar);
}
}
}
}
}