本文整理汇总了C#中BsonDocument.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.SetValue方法的具体用法?C# BsonDocument.SetValue怎么用?C# BsonDocument.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.SetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}