Beispiel #1
0
        public async Task TestBroadcasterWithPayload_Object_Unsubscribe()
        {
            var         b        = new TestViewModel();
            int         oneFired = 0;
            TestPayload payload  = null;
            var         token    = b.BroadcasterPayloadObject.Get <TestEvent>().Listen(async arg =>
            {
                oneFired++;
                payload = arg;
            });
            var toSend = new TestPayload();
            await b.Broadcast(toSend);

            Assert.AreEqual(1, oneFired);
            Assert.AreSame(toSend, payload);
            payload = null;
            await b.Broadcast(toSend);

            Assert.AreEqual(2, oneFired);
            Assert.AreSame(toSend, payload);
            token.Dispose();

            await b.Broadcast(toSend);

            Assert.AreEqual(2, oneFired);
            Assert.AreSame(toSend, payload);
        }
Beispiel #2
0
        public async Task TestBroadcasterWithPayload_Enum_Unsubscribe()
        {
            var    b        = new TestViewModel();
            int    oneFired = 0;
            object payload  = null;
            var    token    = b.ListenerWithPayload.Listen(TestViewModel.Simple.Two, async arg =>
            {
                oneFired++;
                payload = arg;
            });
            var toSend = new object();
            await b.Broadcast(TestViewModel.Simple.Two, toSend);

            Assert.AreEqual(1, oneFired);
            Assert.AreSame(toSend, payload);
            payload = null;
            await b.Broadcast(TestViewModel.Simple.Two, toSend);

            Assert.AreEqual(2, oneFired);
            Assert.AreSame(toSend, payload);
            token.Dispose();

            await b.Broadcast(TestViewModel.Simple.Two, toSend);

            Assert.AreEqual(2, oneFired);
            Assert.AreSame(toSend, payload);
        }
Beispiel #3
0
        public async Task TestBroadcaster()
        {
            var b        = new TestViewModel();
            int oneFired = 0;
            var token    = b.Listener.Listen(TestViewModel.Simple.One, async() => oneFired++);
            await b.Broadcast(TestViewModel.Simple.One);

            Assert.AreEqual(1, oneFired);
            await b.Broadcast(TestViewModel.Simple.One);

            Assert.AreEqual(2, oneFired);

            await b.Broadcast(TestViewModel.Simple.Two);

            Assert.AreEqual(2, oneFired);
            token.Dispose();
        }