public void default_settings_configurator_should_not_alter_settings() { var wrapped = new Mock <IBsonWriter>().Object; var mockElements = new Mock <IEnumerable <BsonElement> >(); mockElements.Setup(m => m.GetEnumerator()).Returns(Enumerable.Empty <BsonElement>().GetEnumerator()); Action <BsonWriterSettings> settingsConfigurator = s => { }; var subject = new ElementAppendingBsonWriter(wrapped, mockElements.Object, settingsConfigurator); var configurator = subject._settingsConfigurator(); var frozenSettings = new BsonBinaryWriterSettings().Freeze(); configurator(frozenSettings); // would throw if configurator tried to alter any settings }
public void WriteEndDocument_should_not_write_elements_when_nested_WriteEndDocument_is_called() { var mockWriter = new Mock <IBsonWriter>(); var elements = new[] { new BsonElement("a", 1) }; var subject = new ElementAppendingBsonWriter(mockWriter.Object, elements, null); subject.WriteStartDocument(); subject.WriteStartDocument(); subject.WriteEndDocument(); mockWriter.Verify(m => m.WriteStartDocument(), Times.Exactly(2)); mockWriter.Verify(m => m.WriteEndDocument(), Times.Once); mockWriter.Verify(m => m.WriteName(It.IsAny <string>()), Times.Never); }
public void WriteEndDocument_should_push_settings_and_write_elements_when_depth_becomes_zero() { var mockWriter = new Mock <IBsonWriter>(); var elements = new[] { new BsonElement("a", 1) }; Action <BsonWriterSettings> configurator = s => { }; var subject = new ElementAppendingBsonWriter(mockWriter.Object, elements, configurator); subject.WriteStartDocument(); subject.WriteEndDocument(); mockWriter.Verify(m => m.WriteStartDocument(), Times.Once); mockWriter.Verify(m => m.PushSettings(configurator), Times.Once); mockWriter.Verify(m => m.WriteName("a"), Times.Once); mockWriter.Verify(m => m.WriteInt32(1), Times.Once); mockWriter.Verify(m => m.PopSettings(), Times.Once); mockWriter.Verify(m => m.WriteEndDocument(), Times.Once); }
public static Action <BsonWriterSettings> _settingsConfigurator(this ElementAppendingBsonWriter obj) { var fieldInfo = typeof(ElementAppendingBsonWriter).GetField("_settingsConfigurator", BindingFlags.NonPublic | BindingFlags.Instance); return((Action <BsonWriterSettings>)fieldInfo.GetValue(obj)); }
public static List <BsonElement> _elements(this ElementAppendingBsonWriter obj) { var fieldInfo = typeof(ElementAppendingBsonWriter).GetField("_elements", BindingFlags.NonPublic | BindingFlags.Instance); return((List <BsonElement>)fieldInfo.GetValue(obj)); }
public static int _depth(this ElementAppendingBsonWriter obj) { var fieldInfo = typeof(ElementAppendingBsonWriter).GetField("_depth", BindingFlags.NonPublic | BindingFlags.Instance); return((int)fieldInfo.GetValue(obj)); }