Beispiel #1
0
        public void SerializeObjectsWithDelegateToOtherObject()
        {
            var eventHandlerInstance = new EventHandlerClass();
            var proxy =
                (DelegateHolder)generator.CreateClassProxy(typeof(DelegateHolder), new IInterceptor[] { new StandardInterceptor() });

            proxy.DelegateMember    = new EventHandler(eventHandlerInstance.TestHandler);
            proxy.ComplexTypeMember = new ArrayList(new[] { 1, 2, 3 });
            proxy.ComplexTypeMember.Add(eventHandlerInstance);

            Assert.IsNotNull(proxy.DelegateMember);
            Assert.IsNotNull(proxy.DelegateMember.Target);

            Assert.IsNotNull(proxy.ComplexTypeMember);
            Assert.AreEqual(4, proxy.ComplexTypeMember.Count);
            Assert.AreEqual(1, proxy.ComplexTypeMember[0]);
            Assert.AreEqual(2, proxy.ComplexTypeMember[1]);
            Assert.AreEqual(3, proxy.ComplexTypeMember[2]);
            Assert.AreSame(proxy.ComplexTypeMember[3], proxy.DelegateMember.Target);

            var otherProxy = (SerializeAndDeserialize(proxy));

            Assert.IsNotNull(otherProxy.DelegateMember);
            Assert.IsNotNull(otherProxy.DelegateMember.Target);

            Assert.IsNotNull(otherProxy.ComplexTypeMember);
            Assert.AreEqual(4, otherProxy.ComplexTypeMember.Count);
            Assert.AreEqual(1, otherProxy.ComplexTypeMember[0]);
            Assert.AreEqual(2, otherProxy.ComplexTypeMember[1]);
            Assert.AreEqual(3, otherProxy.ComplexTypeMember[2]);
            Assert.AreSame(otherProxy.ComplexTypeMember[3], otherProxy.DelegateMember.Target);
        }
Beispiel #2
0
        public void TestCompositeEvents()
        {
            this.PerformTestInAppDomain(() =>
            {
                var composite = this.NewPlainComposite <TestComposite <String> >();

                var handler             = new EventHandlerClass();
                composite.GenericEvent += new Func <string, string>(handler.composite_GenericEvent);
                composite.NormalEvent  += new Action <string>(handler.composite_NormalEvent);
                composite.TypicalEvent += new EventHandler <EventArgs>(handler.composite_TypicalEvent);

                _genericEventInvoked = false;
                String result        = composite.FireGenericEvent(EVENT_STRING_PARAM);
                Assert.IsTrue(_genericEventInvoked, "Generic event must've been invoked.");
                Assert.AreEqual(EVENT_STRING_PARAM + EVENT_STRING_PARAM_SUFFIX, result);

                _normalEventInvoked = false;
                composite.FireNormalEvent(EVENT_STRING_PARAM);
                Assert.IsTrue(_normalEventInvoked, "Normal event must've been invoked.");

                _typicalEventInvoked = false;
                composite.FireTypicalEvent(null);
                Assert.IsTrue(_typicalEventInvoked, "Typical event must've been invoked.");
            });
        }
Beispiel #3
0
        protected void TestInvokeAllRethrowDefaultWithReturnType(Boolean testWeak)
        {
            TestComposite <String> composite = this.NewPlainComposite <TestComposite <String> >();
            EventHandlerClass      handler   = new EventHandlerClass();

            // "NoThrow" is remnant of old API, it really supposed to throw AggregateException

            _eventWithReturnTypeReturnInvoked              = false;
            _eventWithReturnTypeThrowInvoked               = false;
            composite.InvokeAllEventNoThrowWithReturnType += new Func <String>(handler.EventWithReturnTypeThrow);
            composite.InvokeAllEventNoThrowWithReturnType += new Func <String>(handler.EventWithReturnTypeReturn);
            AggregateException aExc = Assert.Throws <AggregateException>(() => Assert.AreEqual(EVENT_STRING_PARAM, composite.FireInvokeAllEventNoThrowWithReturnTypeEvent()));

            Assert.AreEqual(1, aExc.InnerExceptions.Count);
            Assert.AreEqual(typeof(Exception), aExc.InnerExceptions[0].GetType());
            Assert.IsTrue(_eventWithReturnTypeReturnInvoked);
            Assert.IsTrue(_eventWithReturnTypeThrowInvoked);

            if (testWeak)
            {
                handler = null;
                _eventWithReturnTypeReturnInvoked = false;
                _eventWithReturnTypeThrowInvoked  = false;
                PerformGC();
                Assert.Throws <InvalidOperationException>(() => composite.FireInvokeAllEventNoThrowWithReturnTypeEvent());
                Assert.IsFalse(_eventWithReturnTypeReturnInvoked);
                Assert.IsFalse(_eventWithReturnTypeThrowInvoked);
            }
        }
Beispiel #4
0
        protected void TestInvokeAllRethrowCustomWithReturnType(Boolean testWeak)
        {
            TestComposite <String> composite = this.NewPlainComposite <TestComposite <String> >();
            EventHandlerClass      handler   = new EventHandlerClass();

            _eventWithReturnTypeReturnInvoked              = false;
            _eventWithReturnTypeThrowInvoked               = false;
            composite.InvokeAllEventRethrowWithReturnType += new Func <String>(handler.EventWithReturnTypeThrow);
            composite.InvokeAllEventRethrowWithReturnType += new Func <String>(handler.EventWithReturnTypeReturn);
            MyException exc = Assert.Throws <MyException>(() => Assert.AreEqual(EVENT_STRING_PARAM, composite.FireInvokeAllEventRethrowWithReturnTypeEvent()));

            Assert.AreEqual(1, exc.Exceptions.Length);
            Assert.AreEqual(typeof(Exception), exc.Exceptions[0].GetType());
            Assert.IsTrue(_eventWithReturnTypeReturnInvoked);
            Assert.IsTrue(_eventWithReturnTypeThrowInvoked);

            if (testWeak)
            {
                handler = null;
                _eventWithReturnTypeReturnInvoked = false;
                _eventWithReturnTypeThrowInvoked  = false;
                PerformGC();
                Assert.Throws <InvalidOperationException>(() => composite.FireInvokeAllEventRethrowWithReturnTypeEvent());
                Assert.IsFalse(_eventWithReturnTypeReturnInvoked);
                Assert.IsFalse(_eventWithReturnTypeThrowInvoked);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Document the event order. Cannot assume the order based on the order
        /// of the event declarations.
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="headingLevel">The heading level.</param>
        /// <param name="indent">The indent level.</param>
        private void DocumentEventOrder(List <AutoDocumentation.ITag> tags, int headingLevel, int indent)
        {
            // The strategy here is to create an instance of clock and call it's
            // timestep method (OnDoCommence) for two days. WE will subscribe to
            // all the clock methods via a method (Handler) in an instance of an
            // EventHanderClass. This method will then sort out what is a event
            // from the daily time step, what is an event from before the timestep
            // and post timestep events.
            var clock              = new Clock();
            var methodInfo         = typeof(EventHandlerClass).GetMethod("Handler", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
            var preTimestepEvents  = new List <string>();
            var timestepEvents     = new List <string>();
            var postTimestepEvents = new List <string>();

            foreach (var eventMember in clock.GetType().GetEvents())
            {
                var handlerInstance = new EventHandlerClass()
                {
                    EventName          = eventMember.Name,
                    PreTimestepEvents  = preTimestepEvents,
                    TimestepEvents     = timestepEvents,
                    PostTimestepEvents = postTimestepEvents
                };
                var handler =
                    Delegate.CreateDelegate(eventMember.EventHandlerType,
                                            handlerInstance,
                                            methodInfo);
                eventMember.AddEventHandler(
                    clock,
                    handler);
            }

            clock.Start = new DateTime(1900, 1, 1);
            clock.End   = new DateTime(1900, 1, 2);

            var commenceMethod = clock.GetType().GetMethod("OnDoCommence", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            commenceMethod.Invoke(clock, new object[] { clock, new CommenceArgs() });

            var table = new DataTable();

            tags.Add(new AutoDocumentation.Heading("Pre-timestep events (in order)", headingLevel));
            DataTableUtilities.AddColumn(table, "Events", preTimestepEvents.ToArray());
            tags.Add(new AutoDocumentation.Table(table, indent));

            var table2 = new DataTable();

            tags.Add(new AutoDocumentation.Heading("Timestep events (in order)", headingLevel));
            DataTableUtilities.AddColumn(table2, "Events", timestepEvents.ToArray());
            tags.Add(new AutoDocumentation.Table(table2, indent));

            var table3 = new DataTable();

            tags.Add(new AutoDocumentation.Heading("Post-timestep events (in order)", headingLevel));
            DataTableUtilities.AddColumn(table3, "Events", postTimestepEvents.ToArray());
            tags.Add(new AutoDocumentation.Table(table3, indent));
        }
Beispiel #6
0
 public void BeforeTest()
 {
     //Arrange
     evm     = new EventViewModel();
     ehc     = new EventHandlerClass(evm);
     eventt  = new Event("Name", "Type", "Description", DateTime.Parse("2018.02.08 12:00"), "Location");
     ecs     = new EventCatalogSingleton();
     getItem = new PersistancyService();
     getItem.EventsCatalog = new ObservableCollection <Event>();
     dateTimeCon           = new DataTimeConvertor();
 }
Beispiel #7
0
 public EventViewModel()
 {
     EventCatalogSingleton = EventCatalogSingleton.GetInstance();
     Events                = EventCatalogSingleton.GetCollection();
     EventHandler          = new EventHandlerClass(this);
     _selectedEvent        = new Event();
     AddCommand            = new RelayCommand(EventHandler.CreateEvent);
     DeleteCommand         = new RelayCommand(EventHandler.DeleteEvent);
     SearchCommand         = new RelayCommand(DoSearch);
     BackCommand           = new RelayCommand(DoBackToLogin);
     GoToCreatePageCommand = new RelayCommand(NavigateToCreateEventPage);
     _frameNavigation      = new FrameNavigationClass();
 }
Beispiel #8
0
        protected void TestDirectInvokeEvent(Boolean testWeak)
        {
            TestComposite <String> composite = this.NewPlainComposite <TestComposite <String> >();
            EventHandlerClass      handler   = new EventHandlerClass();

            _eventWithoutReturnTypeReturnInvoked = false;
            _eventWithoutReturnTypeThrowInvoked  = false;
            composite.DirectInvokeEvent         += new Action <String>(handler.EventWithoutReturnTypeReturn);
            composite.DirectInvokeEvent         += new Action <String>(handler.EventWithoutReturnTypeThrow);
            Assert.Throws <Exception>(() => composite.FireDirectInvokeEvent(EVENT_STRING_PARAM));
            Assert.IsTrue(_eventWithoutReturnTypeReturnInvoked);
            Assert.IsTrue(_eventWithoutReturnTypeThrowInvoked);

            if (testWeak)
            {
                handler = null;
                _eventWithoutReturnTypeReturnInvoked = false;
                _eventWithoutReturnTypeThrowInvoked  = false;
                PerformGC();
                composite.FireDirectInvokeEvent(EVENT_STRING_PARAM);
                Assert.IsFalse(_eventWithoutReturnTypeReturnInvoked);
                Assert.IsFalse(_eventWithoutReturnTypeThrowInvoked);
            }
        }
		public void SerializeObjectsWithDelegateToOtherObject ()
		{
			ProxyObjectReference.ResetScope ();

			EventHandlerClass eventHandlerInstance = new EventHandlerClass();
			DelegateHolder proxy = (DelegateHolder) generator.CreateClassProxy (typeof (DelegateHolder), new IInterceptor[] {new StandardInterceptor ()});

			proxy.DelegateMember = new EventHandler(eventHandlerInstance.TestHandler);
			proxy.ComplexTypeMember = new ArrayList (new int[] { 1, 2, 3 });
			proxy.ComplexTypeMember.Add (eventHandlerInstance);

			Assert.IsNotNull (proxy.DelegateMember);
			Assert.IsNotNull (proxy.DelegateMember.Target);

			Assert.IsNotNull (proxy.ComplexTypeMember);
			Assert.AreEqual (4, proxy.ComplexTypeMember.Count);
			Assert.AreEqual (1, proxy.ComplexTypeMember[0]);
			Assert.AreEqual (2, proxy.ComplexTypeMember[1]);
			Assert.AreEqual (3, proxy.ComplexTypeMember[2]);
			Assert.AreSame (proxy.ComplexTypeMember[3], proxy.DelegateMember.Target);

			DelegateHolder otherProxy = (DelegateHolder) (SerializeAndDeserialize (proxy));

			Assert.IsNotNull (otherProxy.DelegateMember);
			Assert.IsNotNull (otherProxy.DelegateMember.Target);

			Assert.IsNotNull (otherProxy.ComplexTypeMember);
			Assert.AreEqual (4, otherProxy.ComplexTypeMember.Count);
			Assert.AreEqual (1, otherProxy.ComplexTypeMember[0]);
			Assert.AreEqual (2, otherProxy.ComplexTypeMember[1]);
			Assert.AreEqual (3, otherProxy.ComplexTypeMember[2]);
			Assert.AreSame (otherProxy.ComplexTypeMember[3], otherProxy.DelegateMember.Target);
		}