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