Exemplo n.º 1
0
        public void FromEventPattern()
        {
            var tester = new EventTester();

            {
                var list = new List<int>();
                var d = Observable.FromEventPattern<EventHandler<MyEventArgs>, MyEventArgs>((h) => h.Invoke, h => tester.genericEventHandler += h, h => tester.genericEventHandler -= h)
                    .Subscribe(xx =>
                    {
                        list.Add(xx.EventArgs.MyProperty);
                        Observable.Return(xx.EventArgs.MyProperty)
                            .Do(x => { if (x == 1) throw new Exception(); })
                            .Subscribe(x => list.Add(x));
                    });

                try { tester.Fire(5); } catch { }
                try { tester.Fire(1); } catch { }
                try { tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }
        }
Exemplo n.º 2
0
        public void testEventHandlerT()
        {
            var flag = false;
            var flag2 = false;
            AssertFalse("flag must not yet be set", flag);
            AssertFalse("flag2 must not yet be set", flag2);

            var tester = new EventTester<EventArgs>();
            tester.MyEvent += (s, x) => { flag = true; };
            tester.MyEvent += (s, x) => { flag2 = true; };
            tester.OnMyEvent(EventArgs.Empty);
			
            AssertTrue("flag must be set", flag);
            AssertTrue("flag2 must be set", flag2);
        }
Exemplo n.º 3
0
        public void WasFired()
        {
            Expect.Once.On(this.testInterface).EventAdd("MyEvent");
            using (EventTester eventHelper = new EventTester(this.testInterface, "MyEvent"))
            {
                this.mockery.VerifyAllExpectationsHaveBeenMet();

                Assert.IsFalse(eventHelper.WasFired, "Was fires was true before the event was fired.");
                Fire.On(this.testInterface).Event("MyEvent").With(null, EventArgs.Empty);
                Assert.IsTrue(eventHelper.WasFired, "Was fires was false after the event was fired.");

                Expect.Once.On(this.testInterface).EventRemove("MyEvent");
            }

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemplo n.º 4
0
        public void testEventHandler3()
        {
            var flag = false;
            var flag2 = false;
            AssertFalse("flag must not yet be set", flag);
            AssertFalse("flag2 must not yet be set", flag2);

            var tester = new EventTester();
            tester.MyEvent += (s, x) => { flag = true; };
            EventHandler handler = (s, x) => { flag2 = true; };
            tester.MyEvent += handler;
            tester.MyEvent -= handler;
            tester.OnMyEvent();

            AssertTrue("flag must be set", flag);
            AssertFalse("flag2 must not be set", flag2);
        }
Exemplo n.º 5
0
        public void AssertInvocationCountAutomaticExceptionGeneric()
        {
            Expect.Once.On(this.testInterfaceGeneric).EventAdd("MyEvent");
            var eventTester = new EventTester<EventArgs>(this.testInterfaceGeneric, "MyEvent", 1);

            this.mockery.VerifyAllExpectationsHaveBeenMet();

            Fire.On(this.testInterfaceGeneric).Event("MyEvent").With(null, EventArgs.Empty);
            Fire.On(this.testInterfaceGeneric).Event("MyEvent").With(null, EventArgs.Empty);

            Expect.Once.On(this.testInterfaceGeneric).EventRemove("MyEvent");

            Assert.Throws<EventTesterException>(
                () => eventTester.Dispose());

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemplo n.º 6
0
        public void WasNotFiredWhenEventMatcherDidNotMatch()
        {
            Expect.Once.On(this.testInterfaceGeneric).EventAdd("MyEvent");

            using (EventTester<EventArgs> eventHelper = new EventTester<EventArgs>(this.testInterfaceGeneric, "MyEvent", (s, e) => false, "nothing"))
            {
                this.mockery.VerifyAllExpectationsHaveBeenMet();

                Assert.IsFalse(eventHelper.WasFired, "Was fires was true before the event was fired.");
                Fire.On(this.testInterface).Event("MyEvent").With(null, EventArgs.Empty);
                Assert.IsFalse(eventHelper.WasFired, "Was fires was true after the event was fired.");

                Expect.Once.On(this.testInterfaceGeneric).EventRemove("MyEvent");
            }

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemplo n.º 7
0
        public void InvocationCountGeneric()
        {
            Expect.Once.On(this.testInterfaceGeneric).EventAdd("MyEvent");
            using (EventTester<EventArgs> eventHelper = new EventTester<EventArgs>(this.testInterfaceGeneric, "MyEvent"))
            {
                this.mockery.VerifyAllExpectationsHaveBeenMet();

                // 0 invocations have orrured
                Assert.AreEqual(0, eventHelper.InvocationCount);

                // Check that the invocation count increases with each invocation
                for (int i = 1; i < 10; i++)
                {
                    Fire.On(this.testInterfaceGeneric).Event("MyEvent").With(null, EventArgs.Empty);
                    Assert.AreEqual(i, eventHelper.InvocationCount);
                }

                Expect.Once.On(this.testInterfaceGeneric).EventRemove("MyEvent");
            }

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemplo n.º 8
0
        public void AssertInvocationCountGeneric()
        {
            Expect.Once.On(this.testInterfaceGeneric).EventAdd("MyEvent");
            Expect.Once.On(this.testInterfaceGeneric).EventRemove("MyEvent");

            using (EventTester<EventArgs> eventHelper = new EventTester<EventArgs>(this.testInterfaceGeneric, "MyEvent"))
            {
                eventHelper.AssertInvocationCount(0);
                Assert.Throws<EventTesterException>(() => eventHelper.AssertInvocationCount(1));

                Fire.On(this.testInterfaceGeneric).Event("MyEvent").With(null, EventArgs.Empty);
                Assert.Throws<EventTesterException>(() => eventHelper.AssertInvocationCount(0));
                eventHelper.AssertInvocationCount(1);
                Assert.Throws<EventTesterException>(() => eventHelper.AssertInvocationCount(2));

                Fire.On(this.testInterfaceGeneric).Event("MyEvent").With(null, EventArgs.Empty);
                Assert.Throws<EventTesterException>(() => eventHelper.AssertInvocationCount(1));
                eventHelper.AssertInvocationCount(2);
                Assert.Throws<EventTesterException>(() => eventHelper.AssertInvocationCount(3));
            }

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemplo n.º 9
0
 public void FromEventUnity()
 {
     SetScehdulerForImport();
     var tester = new EventTester();
     {
         var list = new List<int>();
         var d = Observable.FromEvent<int>(h => tester.intAction += h, h => tester.intAction -= h)
             .Subscribe(xx =>
             {
                 list.Add(xx);
                 Observable.Return(xx)
                     .Do(x => { if (x == 1) throw new Exception(); })
                     .Subscribe(x => list.Add(x));
             });
         try { tester.Fire(5); } catch { }
         try { tester.Fire(1); } catch { }
         try { tester.Fire(10); } catch { }
         list.IsCollection(5, 5, 1, 10, 10);
         d.Dispose();
         tester.Fire(1000);
         list.Count.Is(5);
     }
     {
         var i = 0;
         var list = new List<int>();
         var d = Observable.FromEvent(h => tester.unitAction += h, h => tester.unitAction -= h)
             .Subscribe(xx =>
             {
                 list.Add(i);
                 Observable.Return(i)
                     .Do(x => { if (x == 1) throw new Exception(); })
                     .Subscribe(x => list.Add(i));
             });
         try { i = 5; tester.Fire(5); } catch { }
         try { i = 1; tester.Fire(1); } catch { }
         try { i = 10; tester.Fire(10); } catch { }
         list.IsCollection(5, 5, 1, 10, 10);
         d.Dispose();
         tester.Fire(1000);
         list.Count.Is(5);
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }
Exemplo n.º 10
0
        public void AssertWasFiredGeneric()
        {
            Expect.Once.On(this.testInterfaceGeneric).EventAdd("MyEvent");
            Expect.Once.On(this.testInterfaceGeneric).EventRemove("MyEvent");

            using (EventTester<EventArgs> eventHelper = new EventTester<EventArgs>(this.testInterfaceGeneric, "MyEvent"))
            {
                // Check if an EventTesterException is thrown if the event has not occurred.
                Assert.Throws<EventTesterException>(eventHelper.AssertWasFired);

                // After the event was fired no exception occurs anymore
                Fire.On(this.testInterfaceGeneric).Event("MyEvent").With(null, EventArgs.Empty);
                eventHelper.AssertWasFired();

                // Another invocation can occur and still no execption is thrown
                Fire.On(this.testInterfaceGeneric).Event("MyEvent").With(null, EventArgs.Empty);
                eventHelper.AssertWasFired();
            }

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemplo n.º 11
0
    public void GenericChildClassFromMultiType()
    {
        var instance = testResult.GetInstance("AssemblyWithBaseInDifferentModule.MultiTypes.ChildClass");

        EventTester.TestProperty(instance, false);
    }
Exemplo n.º 12
0
    public void WithDependsOnAndDoNotNotify()
    {
        var instance = assembly.GetInstance("ClassWithDependsOnAndDoNotNotify");

        EventTester.TestProperty(instance, true);
    }
Exemplo n.º 13
0
    public void WithNotifyInBase()
    {
        var instance = assembly.GetInstance("ClassWithNotifyInBase");

        EventTester.TestProperty(instance, true);
    }
Exemplo n.º 14
0
    public void WithPropertyImpOfAbstractProperty()
    {
        var instance = assembly.GetInstance("ClassWithPropertyImp");

        EventTester.TestProperty(instance, false);
    }
Exemplo n.º 15
0
    public virtual void WithGenericAndLambda()
    {
        var instance = assembly.GetInstance("ClassWithGenericAndLambdaImp");

        EventTester.TestProperty(instance, false);
    }
Exemplo n.º 16
0
    public void WithLogicInSet()
    {
        var instance = assembly.GetInstance("ClassWithLogicInSet");

        EventTester.TestProperty(instance, false);
    }
Exemplo n.º 17
0
    public void Child2()
    {
        var instance = assembly.GetInstance("ComplexHierarchy.ClassChild2");

        EventTester.TestProperty(instance, false);
    }
Exemplo n.º 18
0
        public void FromEventUnityLike()
        {
            var tester = new EventTester();

            {
                var list = new List<int>();
                var d = Observable.FromEvent<LikeUnityAction<int>, int>(h => new LikeUnityAction<int>(h), h => tester.intUnityAction += h, h => tester.intUnityAction -= h)
                    .Subscribe(xx =>
                    {
                        list.Add(xx);
                        Observable.Return(xx)
                            .Do(x => { if (x == 1) throw new Exception(); })
                            .Subscribe(x => list.Add(x));
                    });

                try { tester.Fire(5); } catch { }
                try { tester.Fire(1); } catch { }
                try { tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }

            {
                var i = 0;
                var list = new List<int>();
                var d = Observable.FromEvent<LikeUnityAction>(h => new LikeUnityAction(h), h => tester.unityAction += h, h => tester.unityAction -= h)
                    .Subscribe(xx =>
                    {
                        list.Add(i);
                        Observable.Return(i)
                            .Do(x => { if (x == 1) throw new Exception(); })
                            .Subscribe(x => list.Add(i));
                    });

                try { i = 5; tester.Fire(5); } catch { }
                try { i = 1; tester.Fire(1); } catch { }
                try { i = 10; tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }
        }
Exemplo n.º 19
0
    public void DirectChildClass()
    {
        var instance = testResult.GetInstance("AssemblyWithBaseInDifferentModule.DirectGeneric.ChildClass");

        EventTester.TestProperty(instance, false);
    }