예제 #1
0
        public void Publish_Args <T>(T value)
        {
            var result = default(T);
            var ev     = new RelayEvent <T>();

            ev.Subscribe(x => { result = x; });
            ev.Publish(value);
            Assert.That(result, Is.EqualTo(value));
        }
예제 #2
0
        public void Publish_Subscribe()
        {
            var count = 0;
            var ev    = new RelayEvent();

            ev.Subscribe(() => ++ count);
            ev.Publish();
            ev.Publish();
            ev.Publish();
            Assert.That(count, Is.EqualTo(3));
        }
예제 #3
0
        public void Unsubscribe()
        {
            var count      = 0;
            var ev         = new RelayEvent();
            var disposable = ev.Subscribe(() => count++);

            ev.Publish();
            ev.Publish();
            disposable.Dispose();
            disposable.Dispose(); // ignore
            ev.Publish();
            Assert.That(count, Is.EqualTo(2));
        }
예제 #4
0
        public void Unsubscribe_Args(int value)
        {
            var count      = 0;
            var ev         = new RelayEvent <int>();
            var disposable = ev.Subscribe(n => count += n);

            ev.Publish(value);
            ev.Publish(value);
            disposable.Dispose();
            disposable.Dispose(); // ignore
            ev.Publish(value);
            Assert.That(count, Is.EqualTo(value * 2));
        }