PageRenderTime 2ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/ToMigrate/Raven.Tests/Conflicts/ShouldntCreateConflictIfIdentical.cs

https://github.com/georgiosd/ravendb
C# | 64 lines | 57 code | 3 blank | 4 comment | 0 complexity | eabf064f24e04671b80c7562f43ffedb MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using System.Text;
 6using System.Threading.Tasks;
 7using Raven.Abstractions.Json.Linq;
 8using Raven.Client.Document;
 9using Raven.Json.Linq;
10using Raven.Tests.Common;
11using Xunit;
12using Constants = Raven.Abstractions.Data.Constants;
13namespace Raven.Tests.Conflicts
14{
15    public class ShouldntCreateConflictIfIdentical : ReplicationBase
16    {
17        private static RavenJObject userAsObject = RavenJObject.FromObject(
18            new { Name = "Tal", Address = new { Country = "Israel", City = "Zichron" } });
19
20        private static byte[] data = {13, 35, 65};
21
22        [Fact]
23        public void IdenticalDocumentsShouldntCreateConflicts()
24        {
25            using (var store1 = CreateStore())
26            using (var store2 = CreateStore())
27            {
28                store1.DatabaseCommands.Put("users/1", null, userAsObject, null);
29                store2.DatabaseCommands.Put("users/1", null, userAsObject, null);
30                var userOnStore1 = store1.DatabaseCommands.Get("users/1");
31                var user = store2.DatabaseCommands.Get("users/1");
32                TellFirstInstanceToReplicateToSecondInstance();
33                WaitForReplication(store2, "users/1", changedSince: user.Etag);
34                //if this line doesn't throw this means that the conflict was resolved.
35                user = store2.DatabaseCommands.Get("users/1");
36                //Making sure user on store 2 has the history of versions from store 1
37                Assert.Equal(1, ((RavenJArray)user.Metadata[Constants.RavenReplicationHistory]).Length);
38                Assert.Equal(userOnStore1.Metadata[Constants.RavenReplicationSource].Value<string>(),
39                    ((RavenJObject)((RavenJArray)user.Metadata[Constants.RavenReplicationHistory]).First())[Constants.RavenReplicationSource].Value<string>());
40            }             
41        }
42
43        [Fact]
44        public void IdenticalAttachmentsShouldntCreateConflicts()
45        {
46            using (var store1 = CreateStore())
47            using (var store2 = CreateStore())
48            {
49                store1.DatabaseCommands.PutAttachment("attachments/1", null, new MemoryStream(data), null);
50                store2.DatabaseCommands.PutAttachment("attachments/1", null, new MemoryStream(data), null);
51                var attOnStore1 = store1.DatabaseCommands.GetAttachment("attachments/1");
52                var att = store2.DatabaseCommands.GetAttachment("attachments/1");
53                TellFirstInstanceToReplicateToSecondInstance();
54                WaitForAttachment(store2, "attachments/1", att.Etag);
55                //if this line doesn't throw this means that the conflict was resolved.
56                att = store2.DatabaseCommands.GetAttachment("attachments/1");
57                //Making sure user on store 2 has the history of versions from store 1
58                Assert.Equal(1, ((RavenJArray)att.Metadata[Constants.RavenReplicationHistory]).Length);
59                Assert.Equal(attOnStore1.Metadata[Constants.RavenReplicationSource].Value<string>(),
60                    ((RavenJObject)((RavenJArray)att.Metadata[Constants.RavenReplicationHistory]).First())[Constants.RavenReplicationSource].Value<string>());
61            }
62        }
63    }
64}