public void TestAddNameValue()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument());
     Assert.AreEqual(false, wrapper.IsMaterialized);
     wrapper.Add("x", 1);
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreEqual(1, wrapper.ElementCount);
     Assert.AreEqual("x", wrapper.GetElement(0).Name);
     Assert.AreEqual(new BsonInt32(1), wrapper[0]);
 }
        public void TestAddNameValueFactoryWithCondition()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.Add("x", () => 1, false);
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(0, wrapper.ElementCount);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.Add("x", () => 1, true);
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, wrapper.ElementCount);
            Assert.AreEqual("x", wrapper.GetElement(0).Name);
            Assert.AreEqual(new BsonInt32(1), wrapper[0]);
        }
 public void TestSetElementByName()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
     Assert.AreEqual(false, wrapper.IsMaterialized);
     wrapper.SetElement(new BsonElement("x", 2));
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreEqual(1, wrapper.ElementCount);
     Assert.AreEqual("x", wrapper.GetElement(0).Name);
     Assert.AreEqual(new BsonInt32(2), wrapper[0]);
 }
 public void TestRemoveElement()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument { { "x", 1 }, { "y", 2 } });
     Assert.AreEqual(false, wrapper.IsMaterialized);
     wrapper.RemoveElement(new BsonElement("y", 2));
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreEqual(1, wrapper.ElementCount);
     Assert.AreEqual("x", wrapper.GetElement(0).Name);
     Assert.AreEqual(new BsonInt32(1), wrapper[0]);
 }
 public void TestMergeOverwrite()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
     Assert.AreEqual(false, wrapper.IsMaterialized);
     var result = wrapper.Merge(new BsonDocument("x", 2), true);
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreSame(wrapper, result);
     Assert.AreEqual(1, wrapper.ElementCount);
     Assert.AreEqual("x", wrapper.GetElement(0).Name);
     Assert.AreEqual(new BsonInt32(2), wrapper[0]);
 }
        public void TestIndexerByName()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
            Assert.AreEqual(false, wrapper.IsMaterialized);
            var value = wrapper["x"];
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(new BsonInt32(1), value);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper["x"] = 1;
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, wrapper.ElementCount);
            Assert.AreEqual("x", wrapper.GetElement(0).Name);
            Assert.AreEqual(new BsonInt32(1), wrapper[0]);
        }
 public void TestGetElementByName()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
     Assert.AreEqual(false, wrapper.IsMaterialized);
     var element = wrapper.GetElement("x");
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreEqual("x", element.Name);
     Assert.AreEqual(new BsonInt32(1), element.Value);
 }
        public void TestAddRangeKeyValuePairs()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.AddRange(new KeyValuePair<string, object>[0]);
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(0, wrapper.ElementCount);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.AddRange(new[] { new KeyValuePair<string, object>("x", 1) });
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, wrapper.ElementCount);
            Assert.AreEqual("x", wrapper.GetElement(0).Name);
            Assert.AreEqual(new BsonInt32(1), wrapper[0]);
        }
        public void TestAddRangeIDictionary()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.AddRange(new Dictionary<string, object>());
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(0, wrapper.ElementCount);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.AddRange((IDictionary)(new Dictionary<string, object> { { "x", 1 } }));
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, wrapper.ElementCount);
            Assert.AreEqual("x", wrapper.GetElement(0).Name);
            Assert.AreEqual(new BsonInt32(1), wrapper[0]);
        }
        public void TestAddRangeElements()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.AddRange(new BsonElement[0]);
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(0, wrapper.ElementCount);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.AddRange(new[] { new BsonElement("x", 1) });
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, wrapper.ElementCount);
            Assert.AreEqual("x", wrapper.GetElement(0).Name);
            Assert.AreEqual(new BsonInt32(1), wrapper[0]);
        }
        public void TestSetDocumentId()
        {
#pragma warning disable 618
            var wrapper = new BsonDocumentWrapper(new BsonDocument("_id", 1));
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.SetDocumentId(new BsonInt32(2));
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, wrapper.ElementCount);
            Assert.AreEqual("_id", wrapper.GetElement(0).Name);
            Assert.AreEqual(new BsonInt32(2), wrapper[0]);
#pragma warning restore
        }