public void testMandatory() { OrderingTestObject te = new OrderingTestObject(); DataContractJsonSerializer ser = new DataContractJsonSerializer(te.GetType()); Stream stream; string json; object returnValue; Exception exception; json = "{ one:2 }"; TestUtil.run(out returnValue, out exception, () => { stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); te = (OrderingTestObject)ser.ReadObject(stream); return(te); } ); Assert.AreEqual(typeof(SerialisationException), exception.GetType(), "should fail w exception"); DataContractMandatoryEnforcementListener dcListener = new DataContractMandatoryEnforcementListener(); TestUtil.run(out returnValue, out exception, () => { Json2Object j2O = new Json2Object(); j2O.Add(dcListener); te = (OrderingTestObject)j2O.toObject(json, typeof(OrderingTestObject)); return(te); } ); Assert.AreEqual(typeof(SerialisationException), exception.GetType(), "should fail w exception"); //check the enforcement listener is not giving a false positive ! Dictionary <string, object> propertyMap = dcListener.Object2PropertyValues.First().Value; Assert.AreEqual(propertyMap.Count, 1, "enforcement data exists"); Assert.AreEqual(propertyMap["one"], "2", "enforcment data contains a correct value"); }
public void testOrdering() { OrderingTestObject orderingTestObject = new OrderingTestObject(); orderingTestObject.four = "4"; orderingTestObject.three = "3"; orderingTestObject.one = "1"; orderingTestObject.two = "2"; var mocks = new MockRepository(); var theMock = mocks.StrictMock <JsonExploreListener>(); RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out); Object2Json o2j = new Object2Json(); o2j.NodeExpander = new DataContractFieldNodeExpander(); string json = o2j.toJson(orderingTestObject); System.Console.WriteLine("json:" + json); Console.WriteLine("***testArray json: " + json); using (mocks.Ordered()) { theMock.JsonStartObject(null, 0); theMock.JsonLeaf("one", "1", true); theMock.JsonLeaf("two", "2", true); theMock.JsonLeaf("three", "3", true); theMock.JsonLeaf("four", "4", true); theMock.JsonEndObject(json.Length - 1); } theMock.Replay(); JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl(); jsonExplorerImpl.explore(json, theMock); theMock.VerifyAllExpectations(); }
public void testMandatory() { OrderingTestObject te = new OrderingTestObject(); DataContractJsonSerializer ser = new DataContractJsonSerializer(te.GetType()); Stream stream; string json; object returnValue; Exception exception; json = "{ one:2 }"; TestUtil.run(out returnValue, out exception, () => { stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); te = (OrderingTestObject)ser.ReadObject(stream); return te; } ); Assert.AreEqual(typeof(SerialisationException), exception.GetType(), "should fail w exception"); DataContractMandatoryEnforcementListener dcListener = new DataContractMandatoryEnforcementListener(); TestUtil.run(out returnValue, out exception, () => { Json2Object j2O = new Json2Object(); j2O.Add(dcListener); te = (OrderingTestObject) j2O.toObject(json, typeof(OrderingTestObject)); return te; } ); Assert.AreEqual(typeof(SerialisationException), exception.GetType(), "should fail w exception"); //check the enforcement listener is not giving a false positive ! Dictionary<string, object> propertyMap = dcListener.Object2PropertyValues.First().Value; Assert.AreEqual(propertyMap.Count, 1, "enforcement data exists"); Assert.AreEqual(propertyMap["one"], "2", "enforcment data contains a correct value"); }
public void testOrdering() { OrderingTestObject orderingTestObject = new OrderingTestObject(); orderingTestObject.four = "4"; orderingTestObject.three = "3"; orderingTestObject.one = "1"; orderingTestObject.two = "2"; var mocks = new MockRepository(); var theMock = mocks.StrictMock<JsonExploreListener>(); RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out); Object2Json o2j = new Object2Json(); o2j.NodeExpander = new DataContractFieldNodeExpander(); string json = o2j.toJson(orderingTestObject); System.Console.WriteLine("json:" + json); Console.WriteLine("***testArray json: " + json); using (mocks.Ordered()) { theMock.JsonStartObject(null, 0); theMock.JsonLeaf("one", "1", true); theMock.JsonLeaf("two", "2", true); theMock.JsonLeaf("three", "3", true); theMock.JsonLeaf("four", "4", true); theMock.JsonEndObject(json.Length - 1); } theMock.Replay(); JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl(); jsonExplorerImpl.explore(json, theMock); theMock.VerifyAllExpectations(); }