Exemplo n.º 1
0
        public CookingActivityViewModel(
            CookingActivity activity)
        {
            _model = activity;

            _model.WhenAnyValue(x => x.RemainingTime)
            .Subscribe(onNext: t => UpdateRemainingTime(t));

            _model.WhenAnyValue(x => x.RemainingTime)
            .Subscribe(onNext: t => IsOverdue = t < TimeSpan.Zero);

            var isActive    = _model.WhenAnyValue(x => x.IsActive);
            var isNotActive = isActive.Select(x => !x);

            var isTicking    = _model.WhenAnyValue(x => x.IsActive);
            var isNotTicking = isTicking.Select(x => !x);

            _startCommand = ReactiveCommand.Create(() => StartCooking(), isNotTicking);
            _pauseCommand = ReactiveCommand.Create(() => PauseCooking(), isTicking);
            _stopCommand  = ReactiveCommand.Create(() => FinishCooking());
            _resetCommand = ReactiveCommand.Create(() => FinishCooking());

            isTicking.CombineLatest(isActive, (a, b) => a && b)
            .Subscribe(onNext: value => IsCountingDown = value);

            ResetTimer();
        }
Exemplo n.º 2
0
        private void AddActivity()
        {
            int r        = new Random().Next(1, 10);
            var activity = new CookingActivity
            {
                Name      = string.Format("Cook the baboon for {0}s. ", r),
                TotalTime = TimeSpan.FromSeconds(r)
            };

            _model.Activities.Add(activity);
        }
Exemplo n.º 3
0
        public void ActivityOverdue()
        {
            var scheduler = new TestScheduler();

            var activity = new CookingActivity(scheduler)
            {
                TotalTime = TimeSpan.FromSeconds(5)
            };

            var vm = new CookingActivityViewModel(activity);

            vm.StartCommand.Execute(null);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(2).Ticks);

            Assert.IsFalse(vm.IsOverdue);
            StringAssert.DoesNotContain("-", vm.RemainingTime);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);

            Assert.IsTrue(vm.IsOverdue);
            StringAssert.Contains("-", vm.RemainingTime);
        }