Пример #1
0
        public void DeregisteredClassSubscribersShouldNotBeCalledOnEventPost()
        {
            EventHub.Instance.Deregister(b);
            int testData = 1;
            var obj      = new ObjectClass {
                SubData = testData
            };

            EventHub.Instance.Post(obj);
            Task.Delay(100).Wait();
            Assert.That(a.SubMethodHit, Is.EqualTo(true), $"'{obj.GetType().FullName}' subscriber wasn't hit in '{a.GetType().FullName}'");

            Assert.That(b.SupMethodHit, Is.Not.EqualTo(true), $"'{obj.GetType().FullName}' subscriber was hit in '{b.GetType().FullName}'");
        }
Пример #2
0
        public void SeperateInstancesOfTheRegisteredClassShouldBeCalledOnEventPost()
        {
            A newA = new A();

            EventHub.Instance.Register(newA);
            int testData = 1;
            var obj      = new ObjectClass {
                SubData = testData
            };

            EventHub.Instance.Post(obj);
            Task.Delay(100).Wait();
            Assert.That(a.SubMethodHit, Is.EqualTo(true), $"'{obj.GetType().FullName}' subscriber wasn't hit in 'First instance'");

            Assert.That(newA.SubMethodHit, Is.EqualTo(true), $"'{obj.GetType().FullName}' subscriber wasn't hit in 'Second instance'");
            EventHub.Instance.Deregister(newA);
        }
Пример #3
0
        public void MultipleClassSubscribersAreCalledOnEventPost()
        {
            int testData = 1;
            var obj      = new ObjectClass {
                SubData = testData
            };

            EventHub.Instance.Post(obj);
            Task.Delay(100).Wait();
            Assert.That(b.SupMethodHit, Is.EqualTo(true), $"'{obj.GetType().FullName}' subscriber wasn't hit in '{b.GetType().FullName}'");
            Assert.That(b.supObj, Is.EqualTo(obj), $"Data wasn't changed in '{b.GetType().FullName}'");
            Assert.That(b.supObj.SubData, Is.EqualTo(testData), $"Data property wasn't changed in '{b.GetType().FullName}'");

            Assert.That(a.SubMethodHit, Is.EqualTo(true), $"'{obj.GetType().FullName}' subscriber wasn't hit in '{a.GetType().FullName}'");
            Assert.That(a.obj, Is.EqualTo(obj), $"Data wasn't changed in '{a.GetType().FullName}'");
            Assert.That(a.obj.SubData, Is.EqualTo(testData), $"Data property wasn't changed in '{a.GetType().FullName}'");
        }
Пример #4
0
        public void SuperClassEventSubscriberCanRecieveSubClassEvent()
        {
            int testData = 1;
            var obj      = new ObjectClass {
                SubData = testData
            };

            EventHub.Instance.Post(obj);
            Task.Delay(100).Wait();
            Assert.That(d.MethodHit, Is.EqualTo(true), $"'{obj.GetType().FullName}' subscriber wasn't hit in '{d.GetType().FullName}'");
            Assert.That(d.obj, Is.EqualTo(obj), $"Data wasn't changed in '{d.GetType().FullName}'");
            Assert.DoesNotThrow(() => { var g = (ObjectClass)d.obj; }, "SuperClass object can't be casted to SubClass");
        }
Пример #5
0
        public void PartialClassEventSubscriberShouldRecieveEvent()
        {
            var p = new P();

            EventHub.Instance.Register(p);
            int testData = 1;
            var obj      = new ObjectClass {
                SubData = testData
            };

            EventHub.Instance.Post(obj);
            Task.Delay(100).Wait();
            Assert.That(p.MethodHit, Is.EqualTo(true), $"'{obj.GetType().FullName}' subscriber wasn't hit in '{p.GetType().FullName}'");
            Assert.That(p.obj, Is.EqualTo(obj), $"Data wasn't changed in '{p.GetType().FullName}'");
        }
Пример #6
0
        public void SubscriberInheritenceTest()
        {
            B   v        = new V();
            int testData = 1;
            var obj      = new ObjectClass {
                SubData = testData
            };
            var supObj = new SuperClass {
                SuperData = testData
            };

            EventHub.Instance.Deregister(a);
            EventHub.Instance.Deregister(b);
            EventHub.Instance.Register(v);
            EventHub.Instance.Post(obj);
            EventHub.Instance.Post(supObj);
            Task.Delay(100).Wait();
            Assert.That(((V)v).NewMethodHit, Is.EqualTo(true), $"'{obj.GetType().FullName}' subscriber wasn't hit in '{v.GetType().FullName}'");
            Assert.That(((V)v).VirtualMethodHit, Is.EqualTo(true), $"'{supObj.GetType().FullName}' subscriber wasn't hit in '{v.GetType().FullName}'");

            Assert.That(((V)v).SupMethodHit, Is.Not.EqualTo(true), $"'{obj.GetType().FullName}' subscriber was hit in '{typeof(B).FullName}'");
            Assert.That(((V)v).UlMethodHit, Is.Not.EqualTo(true), $"'{supObj.GetType().FullName}' subscriber was hit in '{typeof(B).FullName}'");
            EventHub.Instance.Deregister(v);
        }
Пример #7
0
        public void CancelledEventsMustNotBeCalled()
        {
            C c = new C();

            EventHub.Instance.Deregister(a);
            EventHub.Instance.Deregister(b);
            EventHub.Instance.Register(c);
            int testData = 1;
            var obj      = new ObjectClass {
                SubData = testData
            };

            EventHub.Instance.Post(obj);
            Task.Delay(100).Wait();
            EventHub.Instance.Cancel(obj);
            Assert.That(c.SubMethodHit, Is.Not.EqualTo(true), $"'{obj.GetType().FullName}' subscriber was hit in '{c.GetType().FullName}'");
            EventHub.Instance.Deregister(c);
        }