public void BsonKeyValueNode_clears_stored_value() { // ARRANGE var node = new BsonKeyValueNode <int>(this.nodes, new BsonDocument()); this.nodes.Insert(node.BsonDocument); node.SetValue(1); // ACT var result = node.RemoveValue(); // ASSERT Assert.True(result); Assert.False(node.TryGetValue(out var value)); // check db: removes uses update which doesn var nodeDoc = this.nodes.FindAll().Single(); Assert.True(nodeDoc.TryGetValue("_id", out var nodeDocId)); Assert.False(nodeDoc.TryGetValue("key", out var nodeDocKey)); Assert.False(nodeDoc.TryGetValue("value", out var valueBson)); }
public void BsonKeyValueNode_stores_value_as_an_update() { // ARRANGE var node = new BsonKeyValueNode <int>(this.nodes, new BsonDocument()); this.nodes.Insert(node.BsonDocument); // ACT node.SetValue(1); // ASSERT Assert.True(node.TryGetValue(out var value)); Assert.Equal(1, value); // check db update writes the node var nodeDoc = this.nodes.FindAll().Single(); Assert.True(nodeDoc.TryGetValue("_id", out var nodeDocId)); Assert.False(nodeDoc.TryGetValue("key", out var nodeDocKey)); Assert.True(nodeDoc.TryGetValue("value", out var nodeDocValue)); Assert.Equal(1, nodeDocValue.RawValue); }
public void BsonKeyValueNode_fails_on_SetValue_for_unsaved_document() { // ARRANGE var node = new BsonKeyValueNode <int>(this.nodes, new BsonDocument()); // ACT node.SetValue(1); // ASSERT Assert.True(node.TryGetValue(out var value)); Assert.Equal(1, value); // check db update writes the node Assert.False(this.nodes.FindAll().Any()); }