forked from ravendb/ravendb
/
RavenDbNestedPatchTesting.cs
80 lines (68 loc) · 1.88 KB
/
RavenDbNestedPatchTesting.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
using Raven.Abstractions.Commands;
using Raven.Abstractions.Data;
using Raven.Client;
using Raven.Client.Document;
using Raven.Client.Embedded;
using Xunit;
namespace Raven.Tests.Bugs
{
public class RavenDbNestedPatchTesting : RemoteClientTest
{
[Fact]
public void RavenTestArrayPatchingRemove()
{
using(GetNewServer())
using (var docStore = new DocumentStore{Url = "http://localhost:8079"}.Initialize())
{
const string trackId = "tracks/3";
var artist295 = new ArtistInfo {Id = "artists/295", Name = "Bob Dylan"};
var artist296 = new ArtistInfo {Id = "artists/296", Name = "Roy Orbison"};
var track1 = new MultipleArtistTrack
{Id = trackId, Name = "Handle With Care", Artists = new[] {artist295, artist296}};
using (IDocumentSession session = docStore.OpenSession())
{
session.Store(track1);
session.SaveChanges();
}
int removedPosition = 1;
BatchResult[] result = docStore.DatabaseCommands.Batch(new[]
{
new PatchCommandData
{
Key = trackId,
Patches = new[]
{
new PatchRequest
{
Type = PatchCommandType.Remove,
Name = "Artists",
Position = removedPosition
//Value = RavenJToken.FromObject(artist296)
}
}
},
});
using (IDocumentSession session = docStore.OpenSession())
{
track1 = session.Load<MultipleArtistTrack>(trackId);
}
Assert.Equal(1, track1.Artists.Length);
}
}
#region Nested type: ArtistInfo
public class ArtistInfo
{
public string Id { get; set; }
public string Name { get; set; }
}
#endregion
#region Nested type: MultipleArtistTrack
public class MultipleArtistTrack
{
public string Id { get; set; }
public string Name { get; set; }
public ArtistInfo[] Artists { get; set; }
}
#endregion
}
}