Пример #1
0
        public void CommandBinderBindsToCustomComponent()
        {
            var fixture = new CreatesWinformsCommandBinding();
            var cmd     = ReactiveCommand.Create <int>(_ => { });
            var input   = new CustomClickableComponent {
            };

            Assert.True(fixture.GetAffinityForObject(input.GetType(), true) > 0);
            Assert.True(fixture.GetAffinityForObject(input.GetType(), false) > 0);
            var    commandExecuted = false;
            object ea = null;

            cmd.Subscribe(o =>
            {
                ea = o;
                commandExecuted = true;
            });

            using (fixture.BindCommandToObject(cmd, input, Observable.Return((object)5)))
            {
                input.PerformClick();

                Assert.True(commandExecuted);
                Assert.NotNull(ea);
            }
        }
Пример #2
0
        public void CommandBinderBindsToCustomControl()
        {
            var fixture = new CreatesWinformsCommandBinding();
            var cmd     = new ReactiveCommand();
            var input   = new CustomClickableControl {
            };

            Assert.True(fixture.GetAffinityForObject(input.GetType(), true) > 0);
            Assert.True(fixture.GetAffinityForObject(input.GetType(), false) > 0);
            bool   commandExecuted = false;
            object ea = null;

            cmd.Subscribe(o =>
            {
                ea = o;
                commandExecuted = true;
            });

            var disp = fixture.BindCommandToObject(cmd, input, Observable.Return((object)5));

            input.PerformClick();

            Assert.True(commandExecuted);
            Assert.NotNull(ea);
            disp.Dispose();
        }
Пример #3
0
        public void CommandBinderAffectsEnabledState()
        {
            var fixture    = new CreatesWinformsCommandBinding();
            var canExecute = new Subject <bool>();

            canExecute.OnNext(true);

            var cmd   = ReactiveCommand.Create(canExecute);
            var input = new Button {
            };

            using (var disp = fixture.BindCommandToObject(cmd, input, Observable.Return((object)5))) {
                canExecute.OnNext(true);
                Assert.True(input.Enabled);

                canExecute.OnNext(false);
                Assert.False(input.Enabled);
            }
        }
Пример #4
0
        public void CommandBinderAffectsEnabledStateForComponents()
        {
            var fixture    = new CreatesWinformsCommandBinding();
            var canExecute = new Subject <bool>();

            canExecute.OnNext(true);

            var cmd   = ReactiveCommand.Create(() => { }, canExecute);
            var input = new ToolStripButton(); // ToolStripButton is a Component, not a Control

            using (fixture.BindCommandToObject(cmd, input, Observable.Return((object)5)))
            {
                canExecute.OnNext(true);
                Assert.True(input.Enabled);

                canExecute.OnNext(false);
                Assert.False(input.Enabled);
            }
        }