Example #1
0
        public void DiffAFieldAddedAndAFieldModified()
        {
            var a = new BsonDocument();
            var b = new BsonDocument();

            const string existingField = "existingField";
            const string newField = "newField";

            const int newExistingFieldValue = 1;
            const int oldExistingFieldValue = 2;
            const int newFieldValue = 3;

            a.SetValue(existingField, newExistingFieldValue);
            a.SetValue(newField, newFieldValue);
            b.SetValue(existingField, oldExistingFieldValue);

            var expectedDiff = new BsonDocument
                {
                    {"+a:newField", newFieldValue},
                    {
                        existingField, new BsonDocument
                            {
                                {
                                    "values differ",
                                    new BsonDocument {{"a", newExistingFieldValue}, {"b", oldExistingFieldValue}}
                                }
                            }
                    }
                };

            var result = a.Diff(b);

            Assert.That(result, Is.EqualTo(expectedDiff));
        }
Example #2
0
        public void DiffTwoBsonDocumentsWithElementValues()
        {
            // Arrange
            var a = new BsonDocument {
                new BsonElement("Name", "John"), new BsonElement("Age", 20)
            };
            var b = new BsonDocument {
                new BsonElement("Name", "John"), new BsonElement("Age", 30)
            };
            var expected =
                new BsonDocument
            {
                new BsonElement(
                    "Age",
                    new BsonDocument(
                        "values differ",
                        new BsonDocument {
                    { "a", 20 }, { "b", 30 }
                }
                        )
                    )
            };

            // Act
            var doc = a.Diff(b);

            // Assert
            Assert.That(doc.Equals(expected));
        }
Example #3
0
        public void DiffTwoDifferentBsonValuesOfTypeDocument()
        {
            // Arrange
            BsonValue a            = new BsonDocument("x", 1);
            BsonValue b            = new BsonDocument("x", 2);
            var       expectedDiff =
                new BsonDocument
            {
                new BsonElement(
                    "x",
                    new BsonDocument
                {
                    new BsonElement(
                        "values differ",
                        new BsonDocument {
                        { "a", 1 }, { "b", 2 }
                    })
                }
                    )
            };

            // Act
            var value = a.Diff(b);

            // Assert
            Assert.That(value, Is.EqualTo(expectedDiff));
        }
Example #4
0
        public void SetValueTest()
        {
            var doc = new BsonDocument();

            var expected = BsonDocument.Parse("{'a':{'b':{'c':1}}}");

            doc.SetValue("a.b", "c");
            doc.SetValue("a.b", new BsonDocument("c",1));

            var diff = doc.Diff(expected);
            Assert.That(diff.ElementCount, Is.EqualTo(0));

            doc.SetValue("e",1);
            var expected2 = BsonDocument.Parse("{'a':{'b':{'c':1}},'e':1}");
            diff = doc.Diff(expected2);
            Assert.That(diff.ElementCount, Is.EqualTo(0));

            doc.SetValue(string.Empty, 1);
            diff = doc.Diff(expected2);
            Assert.That(diff.ElementCount, Is.EqualTo(0));
        }
Example #5
0
        public void DiffTwoBsonDocumentsWithDifferentElementNames()
        {
            // Arrange
            var a = new BsonDocument {new BsonElement("Name", "John"), new BsonElement("Age", 20)};
            var b = new BsonDocument {new BsonElement("Name", "John"), new BsonElement("Weight", 160)};
            var expected = new BsonDocument {new BsonElement("+a:Age", 20), new BsonElement("+b:Weight", 160)};

            // Act
            var doc = a.Diff(b);

            // Assert
            Assert.That(doc.Equals(expected));
        }
Example #6
0
        public void DiffTwoIdenticalBsonValuesOfTypeDocument()
        {
            // Arrange
            BsonValue a            = new BsonDocument("x", 1);
            BsonValue b            = new BsonDocument("x", 1);
            var       expectedDiff = new BsonDocument();

            // Act
            var value = a.Diff(b);

            // Assert
            Assert.That(value, Is.EqualTo(expectedDiff));
        }
Example #7
0
        public void SetValueTest()
        {
            var doc = new BsonDocument();

            var expected = BsonDocument.Parse("{'a':{'b':{'c':1}}}");

            doc.SetValue("a.b", "c");
            doc.SetValue("a.b", new BsonDocument("c", 1));

            var diff = doc.Diff(expected);

            Assert.That(diff.ElementCount, Is.EqualTo(0));

            doc.SetValue("e", 1);
            var expected2 = BsonDocument.Parse("{'a':{'b':{'c':1}},'e':1}");

            diff = doc.Diff(expected2);
            Assert.That(diff.ElementCount, Is.EqualTo(0));

            doc.SetValue(string.Empty, 1);
            diff = doc.Diff(expected2);
            Assert.That(diff.ElementCount, Is.EqualTo(0));
        }
Example #8
0
        public void DiffTwoBsonDocumentsWithDifferentElementNames()
        {
            // Arrange
            var a = new BsonDocument {
                new BsonElement("Name", "John"), new BsonElement("Age", 20)
            };
            var b = new BsonDocument {
                new BsonElement("Name", "John"), new BsonElement("Weight", 160)
            };
            var expected = new BsonDocument {
                new BsonElement("+a:Age", 20), new BsonElement("+b:Weight", 160)
            };

            // Act
            var doc = a.Diff(b);

            // Assert
            Assert.That(doc.Equals(expected));
        }
Example #9
0
        public void DiffAFieldAddedAndAFieldModified()
        {
            var a = new BsonDocument();
            var b = new BsonDocument();

            const string existingField = "existingField";
            const string newField      = "newField";

            const int newExistingFieldValue = 1;
            const int oldExistingFieldValue = 2;
            const int newFieldValue         = 3;

            a.SetValue(existingField, newExistingFieldValue);
            a.SetValue(newField, newFieldValue);
            b.SetValue(existingField, oldExistingFieldValue);

            var expectedDiff = new BsonDocument
            {
                { "+a:newField", newFieldValue },
                {
                    existingField, new BsonDocument
                    {
                        {
                            "values differ",
                            new BsonDocument {
                                { "a", newExistingFieldValue }, { "b", oldExistingFieldValue }
                            }
                        }
                    }
                }
            };

            var result = a.Diff(b);

            Assert.That(result, Is.EqualTo(expectedDiff));
        }
Example #10
0
        public void DiffTwoBsonDocumentsWithElementValues()
        {
            // Arrange
            var a = new BsonDocument {new BsonElement("Name", "John"), new BsonElement("Age", 20)};
            var b = new BsonDocument {new BsonElement("Name", "John"), new BsonElement("Age", 30)};
            var expected =
                new BsonDocument
                    {
                        new BsonElement(
                            "Age",
                            new BsonDocument(
                                "values differ",
                                new BsonDocument {{"a", 20}, {"b", 30}}
                                )
                            )
                    };

            // Act
            var doc = a.Diff(b);

            // Assert
            Assert.That(doc.Equals(expected));
        }
Example #11
0
        public void DiffTwoIdenticalBsonValuesOfTypeDocument()
        {
            // Arrange
            BsonValue a = new BsonDocument("x", 1);
            BsonValue b = new BsonDocument("x", 1);
            var expectedDiff = new BsonDocument();

            // Act
            var value = a.Diff(b);

            // Assert
            Assert.That(value, Is.EqualTo(expectedDiff));
        }
Example #12
0
        public void DiffTwoDifferentBsonValuesOfTypeDocument()
        {
            // Arrange
            BsonValue a = new BsonDocument("x", 1);
            BsonValue b = new BsonDocument("x", 2);
            var expectedDiff =
                new BsonDocument
                    {
                        new BsonElement(
                            "x",
                            new BsonDocument
                                {
                                    new BsonElement(
                                "values differ",
                                new BsonDocument {{"a", 1}, {"b", 2}})
                                }
                            )
                    };

            // Act
            var value = a.Diff(b);

            // Assert
            Assert.That(value, Is.EqualTo(expectedDiff));
        }