public void ArrayElementJsonWriterTest() { this.CombinatorialEngineProvider.RunCombinations( valuesTestCases, new bool[] { false, true }, new ODataFormat[] { ODataFormat.Json }, (testCase, indent, format) => { StringWriter stringWriter = new StringWriter(); JsonWriterTestWrapper jsonWriter = new JsonWriterTestWrapper(stringWriter, indent, format); jsonWriter.StartArrayScope(); testCase.Write(jsonWriter); jsonWriter.EndArrayScope(); jsonWriter.Flush(); string actualOutput = stringWriter.GetStringBuilder().ToString(); var variables = new Dictionary <string, string>() { { "InternalNewLine", indent ? Environment.NewLine : string.Empty }, { "Indent", indent ? " " : string.Empty }, { "NL", indent ? "$(InternalNewLine)$(Indent)" : string.Empty }, }; string expectedOutput = "[$(InternalNewLine)$(Indent)" + testCase.ExpectedOutput + "$(InternalNewLine)]"; expectedOutput = StringUtils.ResolveVariables(expectedOutput, variables); this.Assert.AreEqual(expectedOutput, actualOutput, "Unexpected output from the writer."); }); }
public void ObjectPropertyValueJsonWriterTest() { this.CombinatorialEngineProvider.RunCombinations( valuesTestCases, (testCase) => { StringWriter stringWriter = new StringWriter(); JsonWriterTestWrapper jsonWriter = new JsonWriterTestWrapper(stringWriter); jsonWriter.StartObjectScope(); jsonWriter.WriteName("propname"); testCase.Write(jsonWriter); jsonWriter.EndObjectScope(); jsonWriter.Flush(); string actualOutput = stringWriter.GetStringBuilder().ToString(); var variables = new Dictionary <string, string>() { { "InternalNewLine", string.Empty }, { "Indent", string.Empty }, { "NL", string.Empty }, }; string expectedOutput = "{$(InternalNewLine)$(Indent)\"propname\":" + testCase.ExpectedOutput + "$(InternalNewLine)}"; expectedOutput = StringUtils.ResolveVariables(expectedOutput, variables); this.Assert.AreEqual(expectedOutput, actualOutput, "Unexpected output from the writer."); }); }
public void BasicJsonWriterTest() { DateTimeOffset positiveOffSet = new DateTimeOffset(DateTime.Today).ToUniversalTime(); string expectedPositiveOffsetISOFormat = XmlConvert.ToString(positiveOffSet); DateTimeOffset negativeOffSet = new DateTimeOffset(DateTime.Now.AddDays(-3)).ToUniversalTime(); string expectedNegativeOffsetISOFormat = XmlConvert.ToString(negativeOffSet); var testCases = new JsonWriterTestCase[] { new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)$(NL)}" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.WriteName("foo"); writer.WriteValue("bar"); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)\"foo\":\"bar\"$(NL)}" }, new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.WriteName("foo"); writer.WriteValue("bar"); writer.WriteName("var1"); writer.WriteValue("value1"); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)\"foo\":\"bar\",\"var1\":\"value1\"$(NL)}" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.WriteValue("bar"); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)\"bar\"$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.WriteValue("bar"); writer.WriteValue((int)42); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)\"bar\",42$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.WriteValue("DateTimeOffset"); writer.WriteValue((DateTimeOffset)positiveOffSet); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)\"DateTimeOffset\",\"" + expectedPositiveOffsetISOFormat + "\"$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.WriteValue("DateTimeOffset"); writer.WriteValue((DateTimeOffset)negativeOffSet); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)\"DateTimeOffset\",\"" + expectedNegativeOffsetISOFormat + "\"$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.WriteName("foo"); writer.WriteValue("bar"); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)\"foo\":\"bar\"$(NL)}" }, new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.WriteName("results"); writer.StartArrayScope(); writer.WriteValue(1); writer.WriteValue(2); writer.EndArrayScope(); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)\"results\":[$(NL)$(Indent)$(Indent)1,2$(NL)$(Indent)]$(NL)}" }, }; this.CombinatorialEngineProvider.RunCombinations( testCases, new bool[] { false, true }, new ODataFormat[] { ODataFormat.Json }, (testCase, indent, format) => { var variables = new Dictionary <string, string>() { { "NL", indent ? Environment.NewLine : string.Empty } }; StringWriter stringWriter = new StringWriter(); JsonWriterTestWrapper jsonWriter = new JsonWriterTestWrapper(stringWriter, indent, format); testCase.Write(jsonWriter); jsonWriter.Flush(); string actualOutput = stringWriter.GetStringBuilder().ToString(); variables["Indent"] = indent ? " " : string.Empty; string expectedOutput = StringUtils.ResolveVariables(testCase.ExpectedOutput, variables); this.Assert.AreEqual(expectedOutput, actualOutput, "Unexpected output from the writer."); }); }
public void BasicJsonWriterTest() { DateTimeOffset positiveOffSet = new DateTimeOffset(DateTime.Today).ToUniversalTime(); string expectedPositiveOffsetISOFormat = XmlConvert.ToString(positiveOffSet); DateTimeOffset negativeOffSet = new DateTimeOffset(DateTime.Now.AddDays(-3)).ToUniversalTime(); string expectedNegativeOffsetISOFormat = XmlConvert.ToString(negativeOffSet); var testCases = new JsonWriterTestCase[] { new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)$(NL)}" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.WriteName("foo"); writer.WriteValue("bar"); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)\"foo\":\"bar\"$(NL)}" }, new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.WriteName("foo"); writer.WriteValue("bar"); writer.WriteName("var1"); writer.WriteValue("value1"); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)\"foo\":\"bar\",\"var1\":\"value1\"$(NL)}" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.WriteValue("bar"); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)\"bar\"$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.WriteValue("bar"); writer.WriteValue((int)42); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)\"bar\",42$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.WriteValue("DateTimeOffset"); writer.WriteValue((DateTimeOffset)positiveOffSet); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)\"DateTimeOffset\",\""+expectedPositiveOffsetISOFormat+"\"$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartArrayScope(); writer.WriteValue("DateTimeOffset"); writer.WriteValue((DateTimeOffset)negativeOffSet); writer.EndArrayScope(); }, ExpectedOutput = "[$(NL)$(Indent)\"DateTimeOffset\",\""+expectedNegativeOffsetISOFormat+"\"$(NL)]" }, new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.WriteName("foo"); writer.WriteValue("bar"); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)\"foo\":\"bar\"$(NL)}" }, new JsonWriterTestCase { Write = (writer) => { writer.StartObjectScope(); writer.WriteName("results"); writer.StartArrayScope(); writer.WriteValue(1); writer.WriteValue(2); writer.EndArrayScope(); writer.EndObjectScope(); }, ExpectedOutput = "{$(NL)$(Indent)\"results\":[$(NL)$(Indent)$(Indent)1,2$(NL)$(Indent)]$(NL)}" }, }; this.CombinatorialEngineProvider.RunCombinations( testCases, new bool[] { false, true }, new ODataFormat[] { ODataFormat.Json}, (testCase, indent, format) => { var variables = new Dictionary<string, string>() { { "NL", indent ? Environment.NewLine : string.Empty } }; StringWriter stringWriter = new StringWriter(); JsonWriterTestWrapper jsonWriter = new JsonWriterTestWrapper(stringWriter, indent, format); testCase.Write(jsonWriter); jsonWriter.Flush(); string actualOutput = stringWriter.GetStringBuilder().ToString(); variables["Indent"] = indent ? " " : string.Empty; string expectedOutput = StringUtils.ResolveVariables(testCase.ExpectedOutput, variables); this.Assert.AreEqual(expectedOutput, actualOutput, "Unexpected output from the writer."); }); }
public void ArrayElementJsonWriterTest() { this.CombinatorialEngineProvider.RunCombinations( valuesTestCases, new bool[] { false, true }, new ODataFormat[] { ODataFormat.Json}, (testCase, indent, format) => { StringWriter stringWriter = new StringWriter(); JsonWriterTestWrapper jsonWriter = new JsonWriterTestWrapper(stringWriter, indent, format); jsonWriter.StartArrayScope(); testCase.Write(jsonWriter); jsonWriter.EndArrayScope(); jsonWriter.Flush(); string actualOutput = stringWriter.GetStringBuilder().ToString(); var variables = new Dictionary<string, string>() { { "InternalNewLine", indent ? Environment.NewLine : string.Empty }, { "Indent", indent ? " " : string.Empty }, { "NL", indent ? "$(InternalNewLine)$(Indent)" : string.Empty }, }; string expectedOutput = "[$(InternalNewLine)$(Indent)" + testCase.ExpectedOutput + "$(InternalNewLine)]"; expectedOutput = StringUtils.ResolveVariables(expectedOutput, variables); this.Assert.AreEqual(expectedOutput, actualOutput, "Unexpected output from the writer."); }); }