public ReplicatorTest()
#endif
        {
            ConflictResolver = new MergeThenTheirsWins();
            ReopenDB();
            _otherDB = OpenDB("otherdb");
        }
Exemplo n.º 2
0
        public void TestConflict()
        {
            ConflictResolver = new TheirsWins();
            ReopenDB();
            var doc1      = SetupConflict();
            var savedDoc1 = Db.Save(doc1);

            savedDoc1["name"].ToString().Should().Be("Scotty", "because the 'theirs' version should win");
            doc1.Dispose();
            savedDoc1.Dispose();

            ConflictResolver = new MergeThenTheirsWins();
            ReopenDB();

            var doc2 = new MutableDocument("doc2");

            doc2.SetString("type", "profile");
            doc2.SetString("name", "Scott");
            var savedDoc2 = Db.Save(doc2);

            // Force a conflict again
            var properties = doc2.ToDictionary();

            properties["type"]   = "bio";
            properties["gender"] = "male";
            SaveProperties(properties, doc2.Id);
            doc2.Dispose();

            // Save and make sure that the correct conflict resolver won
            doc2 = savedDoc2.ToMutable();
            doc2.SetString("type", "bio");
            doc2.SetInt("age", 31);

            savedDoc2.Dispose();
            savedDoc2 = Db.Save(doc2);
            doc2.Dispose();

            savedDoc2["age"].Long.Should().Be(31L, "because 'age' was changed by 'mine' and not 'theirs'");
            savedDoc2["type"].String.Should().Be("bio", "because 'type' was changed by 'mine' and 'theirs' so 'theirs' should win");
            savedDoc2["gender"].String.Should().Be("male", "because 'gender' was changed by 'theirs' but not 'mine'");
            savedDoc2["name"].String.Should().Be("Scott", "because 'name' was unchanged");
            savedDoc2.Dispose();
        }