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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }