コード例 #1
0
        public void TestGet()
        {
            SupportBean testEvent = new SupportBean();

            testEvent.IntPrimitive = 10;

            EventType     eventType = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            BeanEventBean eventBean = new BeanEventBean(testEvent, eventType);

            Assert.AreEqual(eventType, eventBean.EventType);
            Assert.AreEqual(testEvent, eventBean.Underlying);

            Assert.AreEqual(10, eventBean.Get("IntPrimitive"));

            // Test wrong property name
            try
            {
                eventBean.Get("dummy");
                Assert.IsTrue(false);
            }
            catch (PropertyAccessException ex)
            {
                // Expected
                Log.Debug(".TestGet Expected exception, msg=" + ex.Message);
            }

            // Test wrong event type - not possible to happen under normal use
            try
            {
                eventType = SupportEventTypeFactory.CreateBeanType(typeof(SupportBeanSimple));
                eventBean = new BeanEventBean(testEvent, eventType);
                eventBean.Get("MyString");
                Assert.IsTrue(false);
            }
            catch (PropertyAccessException ex)
            {
                // Expected
                Log.Debug(".TestGet Expected exception, msg=" + ex.Message);
            }

            var getter = eventType.GetGetter("MyString");

            try
            {
                getter.Get(new BeanEventBean(new SupportBean_A("id"), eventType));
                Assert.Fail();
            }
            catch (PropertyAccessException ex)
            {
                Assert.AreEqual("Mismatched getter instance to event bean type, expected com.espertech.esper.support.bean.SupportBeanSimple but received com.espertech.esper.support.bean.SupportBean_A", ex.Message);
            }
        }
コード例 #2
0
ファイル: TestBeanEventAdapter.cs プロジェクト: ikvm/nesper
        public void TestInterfaceProperty()
        {
            // Assert implementations have full set of properties
            ISupportDImpl theEvent = new ISupportDImpl("D", "BaseD", "BaseDBase");
            EventType     typeBean = _beanEventTypeFactory.CreateBeanType(theEvent.GetType().FullName, theEvent.GetType(), true, true, true);
            EventBean     bean     = new BeanEventBean(theEvent, typeBean);

            Assert.AreEqual("D", bean.Get("D"));
            Assert.AreEqual("BaseD", bean.Get("BaseD"));
            Assert.AreEqual("BaseDBase", bean.Get("BaseDBase"));
            Assert.AreEqual(3, bean.EventType.PropertyNames.Length);
            EPAssertionUtil.AssertEqualsAnyOrder(bean.EventType.PropertyNames,
                                                 new[] { "D", "BaseD", "BaseDBase" });

            // Assert intermediate interfaces have full set of fields
            EventType interfaceType = _beanEventTypeFactory.CreateBeanType("d", typeof(ISupportD), true, true, true);

            EPAssertionUtil.AssertEqualsAnyOrder(interfaceType.PropertyNames,
                                                 new[] { "D", "BaseD", "BaseDBase" });
        }
コード例 #3
0
        public void TestGetMethods()
        {
            SupportBeanM testEvent = new SupportBeanM();

            testEvent.SetIntPrimitive(10);

            EventType     eventType = SupportEventTypeFactory.CreateBeanType(typeof(SupportBeanM));
            BeanEventBean eventBean = new BeanEventBean(testEvent, eventType);

            Assert.AreEqual(eventType, eventBean.EventType);
            Assert.AreEqual(testEvent, eventBean.Underlying);

            Assert.AreEqual(10, eventBean.Get("IntPrimitive"));

            // Test wrong property name
            try
            {
                eventBean.Get("dummy");
                Assert.Fail();
            }
            catch (PropertyAccessException ex)
            {
                // Expected
                Log.Debug(".TestGetMethods Expected exception, msg=" + ex.Message);
            }

            // Test wrong event type - not possible to happen under normal use
            try
            {
                eventType = SupportEventTypeFactory.CreateBeanType(typeof(SupportBeanSimple));
                eventBean = new BeanEventBean(testEvent, eventType);
                eventBean.Get("MyString");
                Assert.Fail();
            }
            catch (PropertyAccessException ex)
            {
                // Expected
                Log.Debug(".TestGetMethods Expected exception, msg=" + ex.Message);
            }
        }
コード例 #4
0
ファイル: TestBeanEventType.cs プロジェクト: ikvm/nesper
        public void TestGetGetter()
        {
            Assert.AreEqual(null, _eventTypeSimple.GetGetter("Dummy"));

            var getter = _eventTypeSimple.GetGetter("MyInt");

            Assert.AreEqual(20, getter.Get(_eventSimple));
            getter = _eventTypeSimple.GetGetter("MyString");
            Assert.AreEqual("a", getter.Get(_eventSimple));

            try
            {
                // test mismatch between bean and object
                EventType type      = SupportEventAdapterService.Service.BeanEventTypeFactory.CreateBeanType(typeof(Object).FullName, typeof(Object), false, false, false);
                EventBean eventBean = new BeanEventBean(new Object(), type);
                getter.Get(eventBean);
                Assert.Fail();
            }
            catch (PropertyAccessException)
            {
                // Expected
            }
        }