public async Task TurnOnWillTimeout()
        {
            bool cancelled = false;

            this.powerService
            .Setup(x => x.PowerOn(It.IsAny <CancellationToken>()))
            .Returns <CancellationToken>(async(t) =>
            {
                while (!t.IsCancellationRequested)
                {
                    await Task.Delay(100);
                }

                cancelled = t.IsCancellationRequested;
            });

            var instance = new MachineOffCheckViewModel(
                this.powerService.Object,
                this.policyProvider.Object);

            instance.Activator.Activate();

            ((ICommand)instance.TurnOn).Execute(null);

            await Task.Delay(2000);

            cancelled.Should().BeTrue();
        }
        public void CanConstruct()
        {
            var instance = new MachineOffCheckViewModel(
                this.powerService.Object,
                this.policyProvider.Object);

            instance.Should().NotBeNull();
        }
        public void HasDefaultValues()
        {
            var instance = new MachineOffCheckViewModel(
                this.powerService.Object,
                this.policyProvider.Object);

            instance.PoweredOn.Should().BeFalse();
            instance.CanExecuteTurnOn.Should().BeFalse();
        }
        public async Task CannotTurnOffPower()
        {
            var instance = new MachineOffCheckViewModel(
                this.powerService.Object,
                this.policyProvider.Object);

            instance.Activator.Activate();

            ((ICommand)instance.TurnOn).Execute(null);
            await Task.Delay(200);

            ((ICommand)instance.TurnOn).CanExecute(null).Should().BeFalse();
        }
        public void CanGetPoweredOn()
        {
            var subject = new BehaviorSubject <bool>(false);

            this.powerService.Setup(x => x.PoweredOn).Returns(subject);
            var instance = new MachineOffCheckViewModel(
                this.powerService.Object,
                this.policyProvider.Object);

            instance.Activator.Activate();

            subject.OnNext(true);
            instance.PoweredOn.Should().BeTrue();
        }