Exemplo n.º 1
0
        public void T00_TestIncrement()
        {
            // basic $inc
            {
                var doc1 = new BsonDocument { { "count", 4 } };
                var update_cmds = new BsonDocument { { "$inc", new BsonDocument { { "count", 5 } } } };
                var doc2 = new BsonDocument { { "count", 9 } };

                Assert.True(!doc2.Equals(doc1), "(basic inc) shouldn't be equal before apply");
                BsonHelper.applyUpdateCommands(doc1, update_cmds);
                Assert.True(doc2.Equals(doc1), "(basic inc) inc didn't apply");

            }

            // $inc a.b.c + 2
            {

                var doc1 = new BsonDocument {
                 { "a", new BsonDocument {
                     { "count" , 4 }
                   }
                 }};

                var update_cmds = new BsonDocument { { "$inc", new BsonDocument { { "a.count", 5 } } } };
                var doc2 = new BsonDocument {
                 { "a", new BsonDocument {
                     { "count" , 9 }
                   }
                 }};

                Assert.True(!doc2.Equals(doc1), "(nested key inc) shouldn't be equal before apply");
                BsonHelper.applyUpdateCommands(doc1, update_cmds);
                Assert.True(doc2.Equals(doc1), "(nested key inc) inc didn't apply");
            }
        }
        public void TestBsonDocumentEquals()
        {
            var a = new BsonDocument("a", 1);
            var b = new BsonDocument("a", 1);
            var c = new BsonDocument("b", 1);
            var n = (BsonDocument)null;

            Assert.IsTrue(object.Equals(a, b));
            Assert.IsFalse(object.Equals(a, c));
            Assert.IsFalse(a.Equals(n));
            Assert.IsFalse(a.Equals(null));

            Assert.IsTrue(a == b);
            Assert.IsFalse(a == c);
            Assert.IsFalse(a == null);
            Assert.IsFalse(null == a);
            Assert.IsTrue(n == null);
            Assert.IsTrue(null == n);

            Assert.IsFalse(a != b);
            Assert.IsTrue(a != c);
            Assert.IsTrue(a != null);
            Assert.IsTrue(null != a);
            Assert.IsFalse(n != null);
            Assert.IsFalse(null != n);
        }
Exemplo n.º 3
0
 public void AutoVivifyCanAddressLeafPathsDocArr()
 {
     var bson = new BsonDocument("test", new BsonDocument("doc", new BsonDocument()));
     bson.AvArray("test.doc.bar").Add("baz");
     var expected = "{'test':{'doc':{'bar':['baz']}}}".ParseBsonDocument();
     Assert.That(bson.Equals(expected));
 }
 public void TestSingleString() {
     BsonDocument document = new BsonDocument() { { "abc", "xyz" } };
     using (var bsonReader = BsonReader.Create(document)) {
         var rehydrated = BsonDocument.ReadFrom(bsonReader);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
 public void TestEmptyDocument() {
     BsonDocument document = new BsonDocument();
     using (var bsonReader = BsonReader.Create(document)) {
         var rehydrated = BsonDocument.ReadFrom(bsonReader);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
Exemplo n.º 6
0
 public void AutoVivifyCanExtendLeafByOneArrArr()
 {
     var bson = new BsonDocument("test", new BsonDocument("arr", new BsonArray()));
     bson.AvArray("test.arr[0]").Add("baz");
     var expected = "{'test':{'arr':[['baz']]}}}".ParseBsonDocument();
     Assert.That(bson.Equals(expected));
 }
Exemplo n.º 7
0
        public void TestGuid(
            [ClassValues(typeof(GuidModeValues))] GuidMode mode)
        {
            mode.Set();

#pragma warning disable 618, 1062
            if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2 && BsonDefaults.GuidRepresentation != GuidRepresentation.Unspecified)
            {
                var document = new BsonDocument
                {
                    { "guid", new Guid("B5F21E0C2A0D42d6AD03D827008D8AB6") }
                };
                using (var bsonReader = new BsonDocumentReader(document))
                {
                    var rehydrated = DeserializeBsonDocument(bsonReader);
                    Assert.True(document.Equals(rehydrated));
                }
            }
            else
            {
                var exception = Record.Exception(() => new BsonDocument("guid", new Guid("B5F21E0C2A0D42d6AD03D827008D8AB6")));
                exception.Should().BeOfType <InvalidOperationException>();
            }
#pragma warning restore 618, 1062
        }
Exemplo n.º 8
0
 public void AutoVivifyCanAddressLeafPathsDoc()
 {
     var bson = new BsonDocument("test", new BsonDocument("doc", new BsonDocument()));
     bson.AvDocument("test.doc")["bar"] = "baz";
     var expected = "{'test':{'doc':{'bar':'baz'}}}".ParseBsonDocument();
     Assert.That(bson.Equals(expected));
 }
 public void TestArray()
 {
     BsonDocument document = new BsonDocument() {
         { "array", new BsonArray { 1, 2, 3 } }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
 public void TestEmbeddedDocument()
 {
     BsonDocument document = new BsonDocument() {
         { "doc", new BsonDocument { { "a", 1 }, { "b", 2 } } }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
 public void TestBinary()
 {
     var document = new BsonDocument {
         { "bin", new BsonBinaryData(new byte[] { 1, 2, 3 }) }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
Exemplo n.º 12
0
        public void AutoVivifyCanExtendLeafByTwoDoc()
        {
            var bson = new BsonDocument("test", new BsonDocument("doc", new BsonDocument()));

            bson.AvDocument("test.doc.foo.qux")["bar"] = "baz";
            var expected = "{'test':{'doc':{'foo':{'qux':{'bar':'baz'}}}}}".ParseBsonDocument();

            Assert.That(bson.Equals(expected));
        }
Exemplo n.º 13
0
        public void AutoVivifyCanAddressContainedPathsDocArr()
        {
            var bson = new BsonDocument("test", new BsonDocument("doc", "foo"));

            bson.AvArray("test.bar").Add("baz");
            var expected = "{'test':{'doc':'foo','bar':['baz']}}".ParseBsonDocument();

            Assert.That(bson.Equals(expected));
        }
Exemplo n.º 14
0
        public void AutoVivifyCanExtendLeafByOneArrDoc()
        {
            var bson = new BsonDocument("test", new BsonDocument("arr", new BsonArray()));

            bson.AvDocument("test.arr[0]")["bar"] = "baz";
            var expected = "{'test':{'arr':[{'bar':'baz'}]}}}".ParseBsonDocument();

            Assert.That(bson.Equals(expected));
        }
Exemplo n.º 15
0
        public void AutoVivifyCanExtendLeafByOneDocArr()
        {
            var bson = new BsonDocument("test", new BsonDocument("doc", new BsonDocument()));

            bson.AvArray("test.doc.foo.bar").Add("baz");
            var expected = "{'test':{'doc':{'foo':{'bar':['baz']}}}}".ParseBsonDocument();

            Assert.That(bson.Equals(expected));
        }
Exemplo n.º 16
0
        public void AutoVivifyCanAddressLeafPathsDoc()
        {
            var bson = new BsonDocument("test", new BsonDocument("doc", new BsonDocument()));

            bson.AvDocument("test.doc")["bar"] = "baz";
            var expected = "{'test':{'doc':{'bar':'baz'}}}".ParseBsonDocument();

            Assert.That(bson.Equals(expected));
        }
Exemplo n.º 17
0
        public void AutoVivifyCanExtendLeafByOneArrArr()
        {
            var bson = new BsonDocument("test", new BsonDocument("arr", new BsonArray()));

            bson.AvArray("test.arr[0]").Add("baz");
            var expected = "{'test':{'arr':[['baz']]}}}".ParseBsonDocument();

            Assert.That(bson.Equals(expected));
        }
Exemplo n.º 18
0
 public void TestSingleString()
 {
     BsonDocument document = new BsonDocument() { { "abc", "xyz" } };
     using (var bsonReader = new BsonDocumentReader(document))
     {
         var rehydrated = DeserializeBsonDocument(bsonReader);
         Assert.True(document.Equals(rehydrated));
     }
 }
Exemplo n.º 19
0
        // methods
        /// <inheritdoc/>
        public bool Equals(BuildInfoResult other)
        {
            if (other == null)
            {
                return(false);
            }

            return(_wrapped.Equals(other._wrapped));
        }
Exemplo n.º 20
0
        // methods
        /// <inheritdoc/>
        public bool Equals(IsMasterResult other)
        {
            if (other == null)
            {
                return(false);
            }

            return(_wrapped.Equals(other._wrapped));
        }
Exemplo n.º 21
0
 public void TestEmptyDocument()
 {
     BsonDocument document = new BsonDocument();
     using (var bsonReader = new BsonDocumentReader(document))
     {
         var rehydrated = DeserializeBsonDocument(bsonReader);
         Assert.True(document.Equals(rehydrated));
     }
 }
 public void TestDateTime()
 {
     DateTime jan_1_2010 = new DateTime(2010, 1, 1);
     BsonDocument document = new BsonDocument() {
         { "date", jan_1_2010 }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
 public void TestSingleString()
 {
     BsonDocument document = new BsonDocument() { { "abc", "xyz" } };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
        public void TestEmptyDocument()
        {
            BsonDocument document = new BsonDocument();

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
Exemplo n.º 25
0
        public void TestEmptyDocument()
        {
            BsonDocument document = new BsonDocument();

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.True(document.Equals(rehydrated));
            }
        }
 public void TestDateTime() {
     DateTime jan_1_2010 = DateTime.SpecifyKind(new DateTime(2010, 1, 1), DateTimeKind.Utc);
     BsonDocument document = new BsonDocument() {
         { "date", jan_1_2010 }
     };
     using (var bsonReader = BsonReader.Create(document)) {
         var rehydrated = BsonDocument.ReadFrom(bsonReader);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
Exemplo n.º 27
0
        public void TestEmptyDocument()
        {
            BsonDocument document = new BsonDocument();

            using (var bsonReader = BsonReader.Create(document))
            {
                var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
        public void TestJavaScriptWithScope()
        {
            var document = new BsonDocument {
                { "f", new BsonJavaScriptWithScope("function f() { return n; }", new BsonDocument("n", 1)) }
            };

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
        public void TestBinary()
        {
            var document = new BsonDocument {
                { "bin", new BsonBinaryData(new byte[] { 1, 2, 3 }) }
            };

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
        public void TestNull()
        {
            var document = new BsonDocument {
                { "maxkey", BsonNull.Value }
            };

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
        public void TestTimestamp()
        {
            var document = new BsonDocument {
                { "timestamp", new BsonTimestamp(1234567890) }
            };

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
        public void TestGuid()
        {
            var document = new BsonDocument {
                { "guid", new Guid("B5F21E0C2A0D42d6AD03D827008D8AB6") }
            };

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
        public void TestSymbol()
        {
            var document = new BsonDocument {
                { "symbol", BsonSymbol.Create("name") }
            };

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
Exemplo n.º 34
0
 public void TestEmbeddedDocument()
 {
     BsonDocument document = new BsonDocument
     {
         { "doc", new BsonDocument { { "a", 1 }, { "b", 2 } } }
     };
     using (var bsonReader = new BsonDocumentReader(document))
     {
         var rehydrated = DeserializeBsonDocument(bsonReader);
         Assert.True(document.Equals(rehydrated));
     }
 }
 public void TestArray()
 {
     BsonDocument document = new BsonDocument
     {
         { "array", new BsonArray { 1, 2, 3 } }
     };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
        public void TestSingleString()
        {
            BsonDocument document = new BsonDocument()
            {
                { "abc", "xyz" }
            };

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
 public void TestEmbeddedDocument()
 {
     BsonDocument document = new BsonDocument
     {
         { "doc", new BsonDocument { { "a", 1 }, { "b", 2 } } }
     };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
Exemplo n.º 38
0
 public void TestArray()
 {
     BsonDocument document = new BsonDocument
     {
         { "array", new BsonArray { 1, 2, 3 } }
     };
     using (var bsonReader = new BsonDocumentReader(document))
     {
         var rehydrated = DeserializeBsonDocument(bsonReader);
         Assert.True(document.Equals(rehydrated));
     }
 }
Exemplo n.º 39
0
        public void TestMinKey()
        {
            var document = new BsonDocument
            {
                { "minkey", BsonMinKey.Value }
            };

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
Exemplo n.º 40
0
        public void TestJavaScriptWithScope()
        {
            var document = new BsonDocument
            {
                { "f", new BsonJavaScriptWithScope("function f() { return n; }", new BsonDocument("n", 1)) }
            };

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.True(document.Equals(rehydrated));
            }
        }
        public void TestDateTime()
        {
            DateTime     jan_1_2010 = DateTime.SpecifyKind(new DateTime(2010, 1, 1), DateTimeKind.Utc);
            BsonDocument document   = new BsonDocument()
            {
                { "date", jan_1_2010 }
            };

            using (var bsonReader = BsonReader.Create(document)) {
                var rehydrated = BsonDocument.ReadFrom(bsonReader);
                Assert.IsTrue(document.Equals(rehydrated));
            }
        }
Exemplo n.º 42
0
        public void TestGuid()
        {
            var document = new BsonDocument
            {
                { "guid", new Guid("B5F21E0C2A0D42d6AD03D827008D8AB6") }
            };

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.True(document.Equals(rehydrated));
            }
        }
Exemplo n.º 43
0
        // public methods
        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType() != typeof(ChangeStreamUpdateDescription))
            {
                return(false);
            }

            var other = (ChangeStreamUpdateDescription)obj;

            return
                (_removedFields.SequenceEqual(other._removedFields) &&
                 _updatedFields.Equals(other._updatedFields));
        }
Exemplo n.º 44
0
        public void TestNull()
        {
            var document = new BsonDocument
            {
                { "maxkey", BsonNull.Value }
            };

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.True(document.Equals(rehydrated));
            }
        }
Exemplo n.º 45
0
        public void TestSingleString()
        {
            BsonDocument document = new BsonDocument()
            {
                { "abc", "xyz" }
            };

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.True(document.Equals(rehydrated));
            }
        }
Exemplo n.º 46
0
        public void TestTimestamp()
        {
            var document = new BsonDocument
            {
                { "timestamp", new BsonTimestamp(1234567890) }
            };

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.True(document.Equals(rehydrated));
            }
        }
Exemplo n.º 47
0
        public void TestSymbol()
        {
            var document = new BsonDocument
            {
                { "symbol", BsonSymbolTable.Lookup("name") }
            };

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.True(document.Equals(rehydrated));
            }
        }
Exemplo n.º 48
0
        public void TestBinary()
        {
            var document = new BsonDocument
            {
                { "bin", new BsonBinaryData(new byte[] { 1, 2, 3 }) }
            };

            using (var bsonReader = new BsonDocumentReader(document))
            {
                var rehydrated = DeserializeBsonDocument(bsonReader);
                Assert.True(document.Equals(rehydrated));
            }
        }
        public void TestBsonDocumentEquals()
        {
            var a = new BsonDocument("a", 1);
            var b = new BsonDocument("a", 1);
            var c = new BsonDocument("b", 1);
            var n = (BsonDocument)null;

            Assert.IsTrue(object.Equals(a, b));
            Assert.IsFalse(object.Equals(a, c));
            Assert.IsFalse(a.Equals(n));
            Assert.IsFalse(a.Equals(null));

            Assert.IsTrue(a == b);
            Assert.IsFalse(a == c);
            Assert.IsFalse(a == null);
            Assert.IsFalse(null == a);
            Assert.IsTrue(n == null);
            Assert.IsTrue(null == n);

            Assert.IsFalse(a != b);
            Assert.IsTrue(a != c);
            Assert.IsTrue(a != null);
            Assert.IsTrue(null != a);
            Assert.IsFalse(n != null);
            Assert.IsFalse(null != n);
        }
 public void TestJavaScript()
 {
     var document = new BsonDocument {
         { "f", new BsonJavaScript("function f() { return 1; }") }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
 public void TestGuid()
 {
     var document = new BsonDocument
     {
         { "guid", new Guid("B5F21E0C2A0D42d6AD03D827008D8AB6") }
     };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
 public void TestNull()
 {
     var document = new BsonDocument
     {
         { "maxkey", BsonNull.Value }
     };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
 public void TestGuid()
 {
     var document = new BsonDocument {
         { "guid", new Guid("B5F21E0C2A0D42d6AD03D827008D8AB6") }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
 public void TestTimestamp()
 {
     var document = new BsonDocument
     {
         { "timestamp", new BsonTimestamp(1234567890) }
     };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
 public void TestSymbol()
 {
     var document = new BsonDocument
     {
         { "symbol", BsonSymbolTable.Lookup("name") }
     };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
 public void TestDateTime()
 {
     DateTime jan_1_2010 = DateTime.SpecifyKind(new DateTime(2010, 1, 1), DateTimeKind.Utc);
     BsonDocument document = new BsonDocument
     {
         { "date", jan_1_2010 }
     };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }
 public void TestTimestamp()
 {
     var document = new BsonDocument {
         { "timestamp", new BsonTimestamp(1234567890) }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
 public void TestSymbol()
 {
     var document = new BsonDocument {
         { "symbol", BsonSymbol.Create("name") }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
 public void TestNull()
 {
     var document = new BsonDocument {
         { "maxkey", BsonNull.Value }
     };
     var rehydrated = BsonDocument.ReadFrom(BsonReader.Create(document));
     Assert.IsTrue(document.Equals(rehydrated));
 }
 public void TestBinary()
 {
     var document = new BsonDocument
     {
         { "bin", new BsonBinaryData(new byte[] { 1, 2, 3 }) }
     };
     using (var bsonReader = BsonReader.Create(document))
     {
         var rehydrated = (BsonDocument)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), null);
         Assert.IsTrue(document.Equals(rehydrated));
     }
 }