本文整理匯總了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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}