public BsonJsonWriter( TextWriter writer, BsonJsonWriterSettings settings ) { this.textWriter = writer; this.settings = settings; context = new BsonJsonWriterContext(null, BsonWriteState.Initial, ""); }
public void TestDateTime() { DateTime jan_1_2010 = new DateTime(2010, 1, 1); BsonDocument document = new BsonDocument() { { "date", jan_1_2010 } }; var settings = new BsonJsonWriterSettings { OutputMode = BsonJsonOutputMode.Strict }; string json = document.ToJson(settings); string expected = "{ \"date\" : { \"$date\" : 1262322000000 } }"; Assert.AreEqual(expected, json); settings = new BsonJsonWriterSettings { OutputMode = BsonJsonOutputMode.JavaScript }; json = document.ToJson(settings); expected = "{ \"date\" : Date(1262322000000) }"; Assert.AreEqual(expected, json); }
public static BsonWriter Create( TextWriter writer, BsonJsonWriterSettings settings ) { return new BsonJsonWriter(writer, settings); }
public void TestRegex() { var query = Query.Matches("name", new BsonRegularExpression("acme.*corp", "i")); var expected = "{ \"name\" : /acme.*corp/i }"; BsonJsonWriterSettings settings = new BsonJsonWriterSettings { OutputMode = BsonJsonOutputMode.JavaScript }; var actual = query.ToJson(settings); Assert.AreEqual(expected, actual); }
public void TestIndentedTwoElements() { BsonDocument document = new BsonDocument() { { "a", "x" }, { "b", "y" } }; var settings = new BsonJsonWriterSettings { Indent = true }; string json = document.ToJson(settings); string expected = "{\r\n \"a\" : \"x\",\r\n \"b\" : \"y\"\r\n}"; Assert.AreEqual(expected, json); }
public void TestIndentedOneElement() { BsonDocument document = new BsonDocument() { { "name", "value" } }; var settings = new BsonJsonWriterSettings { Indent = true }; string json = document.ToJson(settings); string expected = "{\r\n \"name\" : \"value\"\r\n}"; Assert.AreEqual(expected, json); }
public void TestIndentedEmptyDocument() { BsonDocument document = new BsonDocument(); var settings = new BsonJsonWriterSettings { Indent = true }; string json = document.ToJson(settings); string expected = "{ }"; Assert.AreEqual(expected, json); }
public void TestIndentedEmbeddedDocument() { BsonDocument document = new BsonDocument() { { "doc", new BsonDocument { { "a", 1 }, { "b", 2 } } } }; var settings = new BsonJsonWriterSettings { Indent = true }; string json = document.ToJson(settings); string expected = "{\r\n \"doc\" : {\r\n \"a\" : 1,\r\n \"b\" : 2\r\n }\r\n}"; Assert.AreEqual(expected, json); }