public void ObservableCanExecuteShouldShowUpInCommand()
        {
            var input = new[] {true, false, false, true, false, true};
            var result = (new TestScheduler()).With(sched => {
                var can_execute = new Subject<bool>();
                var fixture = new ReactiveCommand(can_execute, null);
                var changes_as_observable = new ListObservable<bool>(fixture.CanExecuteObservable);

                int change_event_count = 0;
                fixture.CanExecuteChanged += (o, e) => { change_event_count++; };
                input.Run(x => {
                    can_execute.OnNext(x);
                    sched.Run();
                    Assert.AreEqual(x, fixture.CanExecute(null));
                });

                // N.B. We check against '5' instead of 6 because we're supposed to
                // suppress changes that aren't actually changes i.e. false => false
                can_execute.OnCompleted();
                sched.Run();
                Assert.AreEqual(5, change_event_count);

                return changes_as_observable;
            });

            input.AssertAreEqual(result.ToList());
        }
        public void ObservableCanExecuteShouldShowUpInCommand()
        {
            var can_execute = new Subject<bool>();
            var fixture = new ReactiveCommand(can_execute, null);
            var changes_as_observable = new ListObservable<bool>(fixture.CanExecuteObservable);

            var input = new[] { true, false, false, true, false, true };

            int change_event_count = 0;
            fixture.CanExecuteChanged += (o, e) => { change_event_count++; };
            input.Run(x => {
                can_execute.OnNext(x);
                Assert.AreEqual(x, fixture.CanExecute(null));
            });

            // N.B. We check against '5' instead of 6 because we're supposed to
            // suppress changes that aren't actually changes i.e. false => false
            can_execute.OnCompleted();
            Assert.AreEqual(5, change_event_count);

            input.Zip(changes_as_observable.ToList(), (expected, actual) => new { expected, actual })
                 .Do(Console.WriteLine)
                 .Run(x => Assert.AreEqual(x.expected, x.actual));
        }
        public void CompletelyDefaultReactiveCommandShouldFire()
        {
            var sched = new TestScheduler();
            var fixture = new ReactiveCommand(null, sched);
            Assert.IsTrue(fixture.CanExecute(null));

            string result = null;
            fixture.Subscribe(x => result = x as string);

            fixture.Execute("Test");
            sched.Run();
            Assert.AreEqual("Test", result);
            fixture.Execute("Test2");
            sched.Run();
            Assert.AreEqual("Test2", result);
        }
        public void ObservableCanExecuteFuncShouldShowUpInCommand()
        {
            int counter = 1;
            var fixture = new ReactiveCommand(_ => (++counter % 2 == 0), null);
            var changes_as_observable = new ListObservable<bool>(fixture.CanExecuteObservable);

            int change_event_count = 0;
            fixture.CanExecuteChanged += (o, e) => { change_event_count++; };
            Enumerable.Range(0, 6).Run(x => {
                Assert.AreEqual(x % 2 == 0, fixture.CanExecute(null));
            });

            Assert.AreEqual(6, change_event_count);
        }