當前位置: 首頁>>代碼示例>>C#>>正文


C# BsonDocument.Diff方法代碼示例

本文整理匯總了C#中BsonDocument.Diff方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonDocument.Diff方法的具體用法?C# BsonDocument.Diff怎麽用?C# BsonDocument.Diff使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BsonDocument的用法示例。


在下文中一共展示了BsonDocument.Diff方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DiffAFieldAddedAndAFieldModified

        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));
        }
開發者ID:jvanzella,項目名稱:ch-bson,代碼行數:34,代碼來源:Diff.cs

示例2: SetValueTest

        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));
        }
開發者ID:tanglebones,項目名稱:ch-bson,代碼行數:21,代碼來源:SetValue.cs

示例3: DiffTwoBsonDocumentsWithDifferentElementNames

        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));
        }
開發者ID:jvanzella,項目名稱:ch-bson,代碼行數:13,代碼來源:Diff.cs

示例4: DiffTwoBsonDocumentsWithElementValues

        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));
        }
開發者ID:jvanzella,項目名稱:ch-bson,代碼行數:23,代碼來源:Diff.cs

示例5: DiffTwoIdenticalBsonValuesOfTypeDocument

        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));
        }
開發者ID:jvanzella,項目名稱:ch-bson,代碼行數:13,代碼來源:Diff.cs

示例6: DiffTwoDifferentBsonValuesOfTypeDocument

        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));
        }
開發者ID:jvanzella,項目名稱:ch-bson,代碼行數:25,代碼來源:Diff.cs


注:本文中的BsonDocument.Diff方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。