public void testArrayWithfunction()
        {
            string classname = "TestClassName";
            string json = @"{@class:'" + classname+ @"',
             id:'123',
            objectListPropA:null,
            intListPropB:    _a_([3, 4, 5])  }";
            var mocks = new MockRepository();
            var theMock = mocks.StrictMock<JsonExploreListener>();
            RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
            Console.WriteLine("***testArrayWithfunction json: " + json);

            using (mocks.Ordered())
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("@class", classname, true);
                theMock.JsonLeaf("id", "123", true);
                theMock.JsonLeaf("objectListPropA", null, false);
                theMock.JsonStartFunction("_a_", json.IndexOf("("), "intListPropB" );
                theMock.JsonStartArray(null, json.IndexOf("["));
                theMock.JsonLeaf(null, "3", false);
                theMock.JsonLeaf(null, "4", false);
                theMock.JsonLeaf(null, "5", false);
                theMock.JsonEndArray(json.IndexOf("]"));
                theMock.JsonEndFunction(json.IndexOf(")"));
                theMock.JsonEndObject(json.IndexOf("}"));
            }
            theMock.Replay();

            JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();
            jsonExplorerImpl.explore(json, theMock);

            //todo - verify expectations
        }
Esempio n. 2
0
        public void testEmbeddedFunction()
        {
            string functionName = "funcA";
            string propertyName = "propA";
            string json         = "{ " + propertyName + ":" + functionName + "({ a:3, b:\"a b c\" }) }";

            var mocks   = new MockRepository();
            var theMock = mocks.StrictMock <JsonExploreListener>();

            RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
            Console.WriteLine("***testEmbeddedFunction json: " + json);
            using (mocks.Ordered())
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonStartFunction(functionName, json.IndexOf(functionName) + functionName.Length, propertyName);
                theMock.JsonStartObject(null, json.LastIndexOf("{"));
                theMock.JsonLeaf("a", "3", false);
                theMock.JsonLeaf("b", "a b c", true);
                theMock.JsonEndObject(json.IndexOf("}"));
                theMock.JsonEndFunction(json.IndexOf(")"));
                theMock.JsonEndObject(json.Length - 1);
            }
            theMock.Replay();

            JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();

            jsonExplorerImpl.explore(json, theMock);
            theMock.VerifyAllExpectations();
        }
Esempio n. 3
0
        public void testArray()
        {
            string json    = "{ propB:[1,2,3, \"abc\"]}";
            var    mocks   = new MockRepository();
            var    theMock = mocks.StrictMock <JsonExploreListener>();

            RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
            Console.WriteLine("***testArray json: " + json);
            using (mocks.Ordered())
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonStartArray("propB", json.IndexOf("["));
                theMock.JsonLeaf(null, "1", false);
                theMock.JsonLeaf(null, "2", false);
                theMock.JsonLeaf(null, "3", false);
                theMock.JsonLeaf(null, "abc", true);
                theMock.JsonEndArray(json.LastIndexOf("]"));
                theMock.JsonEndObject(json.Length - 1);
            }
            theMock.Replay();
            JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();

            jsonExplorerImpl.explore(json, theMock);
            theMock.VerifyAllExpectations();
        }
Esempio n. 4
0
        public void testEmptyObject()
        {
            string json    = "{ }";
            var    mocks   = new MockRepository();
            var    theMock = mocks.StrictMock <JsonExploreListener>();

            RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
            using (mocks.Ordered())
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonEndObject(2);
            }
            theMock.Replay();

            JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();

            jsonExplorerImpl.explore(json, theMock);
            theMock.VerifyAllExpectations();
        }
Esempio n. 5
0
        public void testJsonExplorationParameterised(string json, int expectedStartCount, int expectedEndCount, int expectedLeafCount, LeafEvent[] expectedLeafEvents = null)
        {
            Console.WriteLine(String.Format("json: {0}", json));
            JSONExplorerImpl        jsonExplorerImpl = new JSONExplorerImpl();
            ExplorationTestListener etl = new ExplorationTestListener();

            jsonExplorerImpl.explore(json, etl);
            Assert.AreEqual(expectedStartCount, etl.startCount, String.Format("expected {0} object start", expectedStartCount));
            Assert.AreEqual(expectedEndCount, etl.endCount, String.Format("expected {0} object end", expectedEndCount));
            Assert.AreEqual(expectedLeafCount, etl.leafCount, String.Format("expected {0} leaves", expectedLeafCount));
            if (expectedLeafEvents != null)
            {
                for (int done = 0; done < expectedLeafEvents.Length; done++)
                {
                    Assert.AreEqual(expectedLeafEvents[done].propertyName, etl.actualLeafEvents[done].propertyName, String.Format("leaf name {0}", done));
                    Assert.AreEqual(expectedLeafEvents[done].value, etl.actualLeafEvents[done].value, String.Format("leaf value {0}", done));
                    Assert.AreEqual(expectedLeafEvents[done].isQuoted, etl.actualLeafEvents[done].isQuoted, String.Format("leaf isQuoted {0} ", done));
                }
            }
        }
 public void testArray()
 {
     string json = "{ propB:[1,2,3, \"abc\"]}";
     var mocks = new MockRepository();
     var theMock = mocks.StrictMock<JsonExploreListener>();
     RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
     Console.WriteLine("***testArray json: " + json);
     using (mocks.Ordered())
     {
         theMock.JsonStartObject(null, 0);
         theMock.JsonStartArray("propB", json.IndexOf("["));
         theMock.JsonLeaf(null, "1", false);
         theMock.JsonLeaf(null, "2", false);
         theMock.JsonLeaf(null, "3", false);
         theMock.JsonLeaf(null, "abc", true);
         theMock.JsonEndArray(json.LastIndexOf("]"));
         theMock.JsonEndObject(json.Length - 1);
     }
     theMock.Replay();
     JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();
     jsonExplorerImpl.explore(json, theMock);
     theMock.VerifyAllExpectations();
 }
Esempio n. 7
0
        public void testArrayWithfunction()
        {
            string classname = "TestClassName";
            string json      = @"{@class:'" + classname + @"',
 id:'123', 
objectListPropA:null, 
intListPropB:    _a_([3, 4, 5])  }";
            var    mocks     = new MockRepository();
            var    theMock   = mocks.StrictMock <JsonExploreListener>();

            RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
            Console.WriteLine("***testArrayWithfunction json: " + json);

            using (mocks.Ordered())
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("@class", classname, true);
                theMock.JsonLeaf("id", "123", true);
                theMock.JsonLeaf("objectListPropA", null, false);
                theMock.JsonStartFunction("_a_", json.IndexOf("("), "intListPropB");
                theMock.JsonStartArray(null, json.IndexOf("["));
                theMock.JsonLeaf(null, "3", false);
                theMock.JsonLeaf(null, "4", false);
                theMock.JsonLeaf(null, "5", false);
                theMock.JsonEndArray(json.IndexOf("]"));
                theMock.JsonEndFunction(json.IndexOf(")"));
                theMock.JsonEndObject(json.IndexOf("}"));
            }
            theMock.Replay();

            JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();

            jsonExplorerImpl.explore(json, theMock);

            //todo - verify expectations
        }
 public void testJsonExplorationParameterised(string json, int expectedStartCount, int expectedEndCount, int expectedLeafCount, LeafEvent[] expectedLeafEvents = null)
 {
     Console.WriteLine(String.Format("json: {0}", json));
     JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();
     ExplorationTestListener etl = new ExplorationTestListener();
     jsonExplorerImpl.explore(json, etl);
     Assert.AreEqual(expectedStartCount, etl.startCount, String.Format("expected {0} object start", expectedStartCount));
     Assert.AreEqual(expectedEndCount, etl.endCount, String.Format("expected {0} object end", expectedEndCount));
     Assert.AreEqual(expectedLeafCount, etl.leafCount, String.Format("expected {0} leaves", expectedLeafCount));
     if (expectedLeafEvents!=null)
     {
       for ( int done=0; done<expectedLeafEvents.Length; done++)
          {
              Assert.AreEqual(expectedLeafEvents[done].propertyName, etl.actualLeafEvents[done].propertyName, String.Format("leaf name {0}", done));
              Assert.AreEqual(expectedLeafEvents[done].value, etl.actualLeafEvents[done].value, String.Format("leaf value {0}", done));
              Assert.AreEqual(expectedLeafEvents[done].isQuoted, etl.actualLeafEvents[done].isQuoted, String.Format("leaf isQuoted {0} ", done));
          }
     }
 }
        public void testEmptyObject()
        {
            string json = "{ }";
            var mocks = new MockRepository();
            var theMock = mocks.StrictMock<JsonExploreListener>();
            RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
            using (mocks.Ordered())
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonEndObject(2);
            }
            theMock.Replay();

            JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();
            jsonExplorerImpl.explore(json, theMock);
            theMock.VerifyAllExpectations();
        }
        public void testEmbeddedFunction()
        {
            string functionName = "funcA";
            string propertyName = "propA";
            string json = "{ " + propertyName + ":" + functionName + "({ a:3, b:\"a b c\" }) }";

            var mocks = new MockRepository();
            var theMock = mocks.StrictMock<JsonExploreListener>();
            RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
            Console.WriteLine("***testEmbeddedFunction json: " + json);
            using (mocks.Ordered())
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonStartFunction(functionName, json.IndexOf(functionName) + functionName.Length, propertyName);
                theMock.JsonStartObject(null, json.LastIndexOf("{"));
                theMock.JsonLeaf("a", "3", false);
                theMock.JsonLeaf("b", "a b c", true);
                theMock.JsonEndObject(json.IndexOf("}"));
                theMock.JsonEndFunction(json.IndexOf(")"));
                theMock.JsonEndObject(json.Length - 1);
            }
            theMock.Replay();

            JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();
            jsonExplorerImpl.explore(json, theMock);
            theMock.VerifyAllExpectations();
        }