public void TestReplaceDictionaryDifferentType()
        {
            var doc      = new MutableDocument("doc1");
            var profile1 = new MutableDictionaryObject();

            profile1.SetString("name", "Scott Tiger");
            doc.SetDictionary("profile", profile1);
            doc.GetDictionary("profile").ShouldBeEquivalentTo(profile1, "because that is what was set");

            doc.SetString("profile", "Daniel Tiger");
            doc.GetString("profile").Should().Be("Daniel Tiger", "because that is what was set");

            profile1.SetInt("age", 20);
            profile1.GetString("name").Should().Be("Scott Tiger", "because profile1 should be detached now");
            profile1.GetInt("age").Should().Be(20, "because profile1 should be detached now");

            doc.GetString("profile").Should().Be("Daniel Tiger", "because profile1 should not affect the new value");

            Db.Save(doc);
            var gotDoc = Db.GetDocument("doc1");

            gotDoc.GetString("profile").Should().Be("Daniel Tiger", "because that is what was saved");
        }
Exemple #2
0
        private static void DoBatchOperation()
        {
            var db = _Database;

            // # tag::batch[]
            db.InBatch(() =>
            {
                for (var i = 0; i < 10; i++)
                {
                    using (var doc = new MutableDocument()) {
                        doc.SetString("type", "user");
                        doc.SetString("name", $"user {i}");
                        doc.SetBoolean("admin", false);
                        db.Save(doc);
                        Console.WriteLine($"Saved user document {doc.GetString("name")}");
                    }
                }
            });
            // # end::batch[]
        }
        public void TestNoBase()
        {
            ConflictResolver = new ActionResolver(conflict =>
            {
                conflict.Mine.GetString("name").Should().Be("Tiger");
                conflict.Theirs.GetString("name").Should().Be("Daniel");
                conflict.Base.Should().BeNull();
                return(conflict.Mine);
            });

            ReopenDB();

            using (var doc1a = new MutableDocument("doc1")) {
                doc1a.SetString("name", "Daniel");
                Db.Save(doc1a);
            }

            using (var doc1b = new MutableDocument("doc1")) {
                doc1b.SetString("name", "Tiger");
                Db.Save(doc1b);
                doc1b.GetString("name").Should().Be("Tiger");
            }
        }