public void testEmitDefaultFalse() { EmitDefaultTest o = new EmitDefaultTest(); o.zero = null; o.one = null; o.two = 0; o.three = 0; o.four = 0.0; o.five = 0.0; o.bSix = false; o.bSeven = false; o.nine = 0; o.ten = null; o.eleven = null; o.twelve = 0; o.thirteen = 0; o.forteen = 0; JsonExpectationBlock jsonExpectationBlock = (theMock, json) => { theMock.JsonStartObject(null, 0); theMock.JsonLeaf("one", null, false); theMock.JsonLeaf("three", "0", false); theMock.JsonLeaf("five", "0", false); theMock.JsonLeaf("bSeven", "false", false); theMock.JsonLeaf("nine", "0", false); theMock.JsonLeaf("eleven", null, false); theMock.JsonLeaf("twelve", "0", false); theMock.JsonLeaf("forteen", "0", false); theMock.JsonEndObject(json.Length - 1); }; testInBuiltAndNativeJson(o, jsonExpectationBlock, "test EmitDefault s"); }
public void testDataContractAttribute() { TestDataContract o = new TestDataContract(); o.field1 = 321; JsonExpectationBlock jsonExpectation = (theMock, json) => { theMock.JsonStartObject(null, 0); theMock.JsonLeaf("field1", "" + o.field1, false); theMock.JsonEndObject(json.Length - 1); }; testInBuiltAndNativeJson(o, jsonExpectation, "test test Data Contract Attributes"); }
public void testProperties() { TestPropertyContainer o = new TestPropertyContainer(); o.StringA = "abcd"; JsonExpectationBlock jsonExpectation = (theMock, json) => { theMock.JsonStartObject(null, 0); theMock.JsonLeaf("StringA", o.StringA, true); theMock.JsonEndObject(json.Length - 1); }; testInBuiltAndNativeJson(o, jsonExpectation, "test Data Member Properties"); }
protected void testInBuiltAndNativeJson(Object o, JsonExpectationBlock jsonExpectation, string testDescription) { System.Console.WriteLine("starting " + testDescription + " ************"); MemoryStream stream1 = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(o.GetType()); ser.WriteObject(stream1, o); StreamReader sr = new StreamReader(stream1); stream1.Position = 0; string strBuiltInJson = sr.ReadToEnd(); var mocks = new MockRepository(); JsonExploreListener theMock = null; RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out); Object2Json o2j = new Object2Json(); o2j.NodeExpander = new DataContractFieldNodeExpander(); o2j.isDefaultLeafValue = DataContractDefaultUtil.isDefaultLeafValue; o2j.OmitDefaultLeafValuesInJs = true; string nativejson = o2j.toJson(o); JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl(); string json = null; Func <string> runWithMocks = () => { theMock = mocks.StrictMock <JsonExploreListener>(); using (mocks.Ordered()) { jsonExpectation(theMock, json); } theMock.Replay(); jsonExplorerImpl.explore(json, theMock); theMock.VerifyAllExpectations(); return(null); }; Console.WriteLine("testing inbuilt json=" + strBuiltInJson); json = strBuiltInJson; runWithMocks(); Console.WriteLine("testing json=" + nativejson); json = nativejson; runWithMocks(); System.Console.WriteLine("completed " + testDescription + " ************"); }
public static void testJsonStructure(string json, JsonExpectationBlock expectation, string testname) { RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out); System.Console.WriteLine("test: " + testname + "testing json=" + json); var mocks = new MockRepository(); JsonExploreListener theMock = mocks.StrictMock<JsonExploreListener>(); using (mocks.Ordered()) { expectation(theMock, json); } theMock.Replay(); (new JSONExplorerImpl()).explore(json, theMock); theMock.VerifyAllExpectations(); }
public static void testJsonStructure(string json, JsonExpectationBlock expectation, string testname) { RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out); System.Console.WriteLine("test: " + testname + "testing json=" + json); var mocks = new MockRepository(); JsonExploreListener theMock = mocks.StrictMock <JsonExploreListener>(); using (mocks.Ordered()) { expectation(theMock, json); } theMock.Replay(); (new JSONExplorerImpl()).explore(json, theMock); theMock.VerifyAllExpectations(); }
public void testNested() { TestContainer o = new TestContainer(); o.subObject = new TestSubObject(); o.subObject.strField1 = "hello"; JsonExpectationBlock jsonExpectation = (theMock, json) => { theMock.JsonStartObject(null, 0); int startSubObject = json.IndexOf('{', 1); theMock.JsonStartObject("subObject", startSubObject); theMock.JsonLeaf("strField1", o.subObject.strField1, true); int endSubObject = json.IndexOf('}', startSubObject); theMock.JsonEndObject(endSubObject); theMock.JsonEndObject(json.Length - 1); }; testInBuiltAndNativeJson(o, jsonExpectation, "test nested json"); }
protected void testInBuiltAndNativeJson(Object o, JsonExpectationBlock jsonExpectation, string testDescription) { System.Console.WriteLine("starting " + testDescription + " ************"); MemoryStream stream1 = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer( o.GetType()); ser.WriteObject(stream1, o); StreamReader sr = new StreamReader(stream1); stream1.Position = 0; string strBuiltInJson = sr.ReadToEnd(); var mocks = new MockRepository(); JsonExploreListener theMock = null; RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out); Object2Json o2j = new Object2Json(); o2j.NodeExpander = new DataContractFieldNodeExpander(); o2j.isDefaultLeafValue = DataContractDefaultUtil.isDefaultLeafValue; o2j.OmitDefaultLeafValuesInJs = true; string nativejson = o2j.toJson(o); JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl(); string json = null; Func<string> runWithMocks = () => { theMock = mocks.StrictMock<JsonExploreListener>(); using (mocks.Ordered()) { jsonExpectation(theMock, json); } theMock.Replay(); jsonExplorerImpl.explore(json, theMock); theMock.VerifyAllExpectations(); return null; }; Console.WriteLine("testing inbuilt json=" + strBuiltInJson); json = strBuiltInJson; runWithMocks(); Console.WriteLine("testing json=" + nativejson); json = nativejson; runWithMocks(); System.Console.WriteLine("completed " + testDescription + " ************"); }