Ejemplo n.º 1
0
        public void ForwardOnChangeTest()
        {
            // two bindables of different type
            var child  = new Bindable <int>();
            var parent = new Bindable <string>();

            parent.ForwardOnChange(child);

            var counter = 0;
            BindableCallback listener = ((c, o) => { counter++; });

            // listener on parent without immediate dispatch
            parent.OnChange(listener, false);

            // dispatch on the child
            child.Dispatch();

            Assert.AreEqual(1, counter, "The OnChange should have been forwarded once to the parent");

            // remove the forwarding
            parent.RemoveForwardedOnChange(child);

            // dispatch again on the child
            child.Dispatch();

            Assert.AreEqual(1, counter, "The OnChange should not have been forwarded again.");
        }
Ejemplo n.º 2
0
        public void OnChangeRemoveOnChangeTest()
        {
            var bindable = new Bindable <int>();

            var counter = 0;

            BindableCallback listener = ((c, o) => { counter++; });

            // add without immediate dispatch
            bindable.OnChange(listener, false);

            bindable.Dispatch();
            Assert.AreEqual(1, counter, "The callback should have been called once.");

            bindable.RemoveOnChange(listener);

            bindable.Dispatch();
            Assert.AreEqual(1, counter, "The callback should have not been called again.");
        }
Ejemplo n.º 3
0
        public void ForwardOnChangeTest()
        {
            // setup
            var events = new BindableEvents(new Bindable <int>());
            var bindableToForwardFrom = new Bindable <string>();

            bindableToForwardFrom.Set("test");
            // register forward
            events.ForwardOnChange(bindableToForwardFrom);

            var counter = 0;

            events.Add((c, o) => { counter++; });
            // dispatch
            bindableToForwardFrom.Dispatch();

            Assert.AreEqual(1, counter, "The event should be forwarded once.");

            // remove the listener and dispatch again
            events.RemoveForwardedOnChange(bindableToForwardFrom);
            bindableToForwardFrom.Dispatch();

            Assert.AreEqual(1, counter, "The event should not be forwarded again.");
        }