Ejemplo n.º 1
0
        public void TestThread1()
        {
            var ev  = new TestEvent1();
            var tid = Thread.CurrentThread.ManagedThreadId;

            ev.Prepare  += e => Assert.Equal(tid, Thread.CurrentThread.ManagedThreadId);
            ev.Execute  += e => Assert.NotEqual(tid, Thread.CurrentThread.ManagedThreadId);
            ev.Success  += e => Assert.NotEqual(tid, Thread.CurrentThread.ManagedThreadId);
            ev.Complete += e => Assert.NotEqual(tid, Thread.CurrentThread.ManagedThreadId);

            ev.Trigger(manager);
            ev.Wait();
        }
Ejemplo n.º 2
0
        public void TestAbort2()
        {
            var ev = new TestEvent1();

            ev.Execute += e => throw new PEventCancelException();

            ev.Trigger(manager);
            ev.Wait();

            Assert.Equal(1, ev.executeCounter);
            Assert.Equal(0, ev.successCounter);
            Assert.Equal(0, ev.errorCounter);
            Assert.Equal(1, ev.completeCounter);
        }
Ejemplo n.º 3
0
        public void TestException1()
        {
            var ev = new TestEvent1();

            ev.Execute += e => throw new Exception("test");
            ev.Error   += (e, ex) => Assert.Equal("test", ex.Message);

            ev.Trigger(manager);
            ev.Wait();

            Assert.Equal(1, ev.prepareCounter);
            Assert.Equal(1, ev.executeCounter);
            Assert.Equal(0, ev.successCounter);
            Assert.Equal(1, ev.errorCounter);
            Assert.Equal(1, ev.completeCounter);
        }
Ejemplo n.º 4
0
        public void TestBasic1()
        {
            var ev = new TestEvent1();

            ev.Prepare  += e => e.prepareCounter++;
            ev.Execute  += e => e.executeCounter++;
            ev.Success  += e => e.successCounter++;
            ev.Error    += (e, ex) => e.errorCounter++;
            ev.Complete += e => e.completeCounter++;

            ev.Trigger(manager);
            ev.Wait();

            Assert.Equal(2, ev.prepareCounter);
            Assert.Equal(2, ev.executeCounter);
            Assert.Equal(2, ev.successCounter);
            Assert.Equal(0, ev.errorCounter);
            Assert.Equal(2, ev.completeCounter);
        }
Ejemplo n.º 5
0
        public void TestAbort1()
        {
            var ev = new TestEvent1();

            ev.Execute += e => { while (true)
                                 {
                                     e.executeCounter++;
                                 }
            };

            ev.Trigger(manager);

            Thread.Sleep(10);
            ev.Abort();

            Assert.True(ev.executeCounter > 1);
            Assert.Equal(0, ev.successCounter);
            Assert.Equal(0, ev.errorCounter);
            Assert.Equal(0, ev.completeCounter);
        }