示例#1
0
        public void TestNestedMap()
        {
            IDictionary <String, Object> levelThree = new Dictionary <String, Object>();

            levelThree["simpleThree"]   = typeof(long);
            levelThree["objThree"]      = typeof(SupportBean_D);
            levelThree["nodefmapThree"] = typeof(Map);

            IDictionary <String, Object> levelTwo = new Dictionary <String, Object>();

            levelTwo["simpleTwo"]   = typeof(float);
            levelTwo["objTwo"]      = typeof(SupportBean_C);
            levelTwo["nodefmapTwo"] = typeof(Map);
            levelTwo["mapTwo"]      = levelThree;

            IDictionary <String, Object> levelOne = new Dictionary <String, Object>();

            levelOne["simpleOne"]   = typeof(int);
            levelOne["objOne"]      = typeof(SupportBean_B);
            levelOne["nodefmapOne"] = typeof(Map);
            levelOne["mapOne"]      = levelTwo;

            IDictionary <String, Object> levelZero = new Dictionary <String, Object>();

            levelZero["simple"]   = typeof(double);
            levelZero["obj"]      = typeof(SupportBean_A);
            levelZero["nodefmap"] = typeof(Map);
            levelZero["map"]      = levelOne;

            var mapType = new MapEventType(null, "M1", 1, _eventAdapterService, levelZero, null, null, null);
            IDictionary <String, Object> testData = GetTestData();
            var theEvent = new MapEventBean(testData, mapType);

            var expected = new[]
            {
                new object[] { "map.mapOne.simpleTwo", typeof(float?), 300f },
                new object[] { "nodefmap.item?", typeof(object), "|nodefmap.item|" },
                new object[] { "map.objOne", typeof(SupportBean_B), new SupportBean_B("B1") },
                new object[] { "map.simpleOne", typeof(int?), 20 },
                new object[] { "map.mapOne", typeof(Map), ((Map)testData.Get("map")).Get("mapOne") },
                new object[] { "map.mapOne.objTwo", typeof(SupportBean_C), new SupportBean_C("C1") },
                new object[] { "map.mapOne.mapTwo", typeof(Map), ((Map)((Map)testData.Get("map")).Get("mapOne")).Get("mapTwo") },
                new object[] { "map.mapOne.mapTwo.simpleThree", typeof(long?), 4000L },
                new object[] { "map.mapOne.mapTwo.objThree", typeof(SupportBean_D), new SupportBean_D("D1") },
                new object[] { "simple", typeof(double), 1d },
                new object[] { "obj", typeof(SupportBean_A), new SupportBean_A("A1") },
                new object[] { "nodefmap", typeof(Map), testData.Get("nodefmap") },
                new object[] { "map", typeof(Map), testData.Get("map") },
            };

            // assert getter available for all properties
            for (int i = 0; i < expected.Length; i++)
            {
                var propName = (String)expected[i][0];
                Assert.NotNull(mapType.GetGetter(propName), "failed for property:" + propName);
            }

            // assert property types
            for (int i = 0; i < expected.Length; i++)
            {
                var propName = (String)expected[i][0];
                var propType = (Type)expected[i][1];
                Assert.AreEqual(propType, mapType.GetPropertyType(propName), "failed for property:" + propName);
            }

            // assert property names
            var            expectedPropNames = new[] { "simple", "obj", "map", "nodefmap" };
            IList <string> receivedPropNames = mapType.PropertyNames;

            EPAssertionUtil.AssertEqualsAnyOrder(expectedPropNames, receivedPropNames);

            // assert get value through (1) type getter  (2) event-get
            for (int i = 0; i < expected.Length; i++)
            {
                var    propName      = (String)expected[i][0];
                Object valueExpected = expected[i][2];
                Assert.AreEqual(valueExpected, mapType.GetGetter(propName).Get(theEvent),
                                "failed for property type-getter:" + propName);
                Assert.AreEqual(valueExpected, theEvent.Get(propName),
                                "failed for property event-getter:" + propName);
            }

            // assert access to objects nested within
            expected = new[]
            {
                new object[] { "map.objOne.Id", typeof(string), "B1" },
                new object[] { "map.mapOne.objTwo.Id", typeof(string), "C1" },
                new object[] { "obj.Id", typeof(string), "A1" },
            };
            for (int i = 0; i < expected.Length; i++)
            {
                var    propName            = (String)expected[i][0];
                var    propType            = (Type)expected[i][1];
                object valueExpected       = expected[i][2];
                EventPropertyGetter getter = mapType.GetGetter(propName);
                Assert.AreEqual(propType, mapType.GetPropertyType(propName),
                                "failed for property:" + propName);
                Assert.AreEqual(valueExpected, getter.Get(theEvent),
                                "failed for property type-getter:" + propName);
                Assert.AreEqual(valueExpected, theEvent.Get(propName),
                                "failed for property event-getter:" + propName);
            }
        }