Beispiel #1
0
        public void TestAddNameValue()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());

            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.Add("x", 1);
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(1, wrapper.ElementCount);
            Assert.Equal("x", wrapper.GetElement(0).Name);
            Assert.Equal(new BsonInt32(1), wrapper[0]);
        }
Beispiel #2
0
        public void TestSetElementByName()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));

            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.SetElement(new BsonElement("x", 2));
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(1, wrapper.ElementCount);
            Assert.Equal("x", wrapper.GetElement(0).Name);
            Assert.Equal(new BsonInt32(2), wrapper[0]);
        }
Beispiel #3
0
        public void TestGetElementByName()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));

            Assert.Equal(false, wrapper.IsMaterialized);
            var element = wrapper.GetElement("x");

            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal("x", element.Name);
            Assert.Equal(new BsonInt32(1), element.Value);
        }
Beispiel #4
0
        public void TestInsertAt()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());

            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper.InsertAt(0, 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
        }
Beispiel #6
0
        public void TestRemoveElement()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument {
                { "x", 1 }, { "y", 2 }
            });

            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.RemoveElement(new BsonElement("y", 2));
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(1, wrapper.ElementCount);
            Assert.Equal("x", wrapper.GetElement(0).Name);
            Assert.Equal(new BsonInt32(1), wrapper[0]);
        }
Beispiel #7
0
        public void TestMergeOverwrite()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));

            Assert.Equal(false, wrapper.IsMaterialized);
            var result = wrapper.Merge(new BsonDocument("x", 2), true);

            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Same(wrapper, result);
            Assert.Equal(1, wrapper.ElementCount);
            Assert.Equal("x", wrapper.GetElement(0).Name);
            Assert.Equal(new BsonInt32(2), wrapper[0]);
        }
Beispiel #8
0
        public void TestAddNameValueFactoryWithCondition()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());

            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.Add("x", () => 1, false);
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(0, wrapper.ElementCount);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.Add("x", () => 1, true);
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(1, wrapper.ElementCount);
            Assert.Equal("x", wrapper.GetElement(0).Name);
            Assert.Equal(new BsonInt32(1), wrapper[0]);
        }
Beispiel #9
0
        public void TestAddRangeKeyValuePairs()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());

            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.AddRange(new KeyValuePair <string, object> [0]);
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(0, wrapper.ElementCount);

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

            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.AddRange(new BsonElement[0]);
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(0, wrapper.ElementCount);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.AddRange(new[] { new BsonElement("x", 1) });
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(1, wrapper.ElementCount);
            Assert.Equal("x", wrapper.GetElement(0).Name);
            Assert.Equal(new BsonInt32(1), wrapper[0]);
        }
Beispiel #11
0
        public void TestIndexerByName()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));

            Assert.Equal(false, wrapper.IsMaterialized);
            var value = wrapper["x"];

            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(new BsonInt32(1), value);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper["x"] = 1;
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(1, wrapper.ElementCount);
            Assert.Equal("x", wrapper.GetElement(0).Name);
            Assert.Equal(new BsonInt32(1), wrapper[0]);
        }
Beispiel #12
0
        public void TestAddRangeIDictionary()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());

            Assert.Equal(false, wrapper.IsMaterialized);
            wrapper.AddRange(new Dictionary <string, object>());
            Assert.Equal(true, wrapper.IsMaterialized);
            Assert.Equal(0, wrapper.ElementCount);

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