Esempio n. 1
0
        public void WillTriggerProtection()
        {
            AsyncContext.Run(async() =>
            {
                var instance = new ServiceSimulation(
                    SynchronizationContext.Current,
                    1000,
                    true,
                    150m,
                    1.2m,
                    0m,
                    0m,
                    false);
                bool protection = false;

                instance.Protection.Subscribe(p => protection = p);

                // test
                await instance.PowerOn(CancellationToken.None);

                // wait at least a tick for the protection to kick in.
                await Task.Delay(1200);

                // assert
                protection.Should().BeTrue();
            });
        }
Esempio n. 2
0
        public void IsRunning()
        {
            AsyncContext.Run(async() =>
            {
                var instance = new ServiceSimulation(SynchronizationContext.Current);
                int tick     = 0;

                instance.Tick.Subscribe(p => tick = p);

                // test
                await instance.PowerOn(CancellationToken.None);

                // wait at least a tick for the heater to turn on.
                await Task.Delay(1200);

                // assert
                tick.Should().BeGreaterThan(0);
            });
        }
Esempio n. 3
0
        public void CanCallPowerOn()
        {
            AsyncContext.Run(async() =>
            {
                bool powerOnCalled    = false;
                var cancellationToken = CancellationToken.None;

                var instance = new ServiceSimulation(SynchronizationContext.Current);

                instance.PoweredOn.Subscribe(x =>
                {
                    if (x)
                    {
                        powerOnCalled = true;
                    }
                });
                await instance.PowerOn(cancellationToken);
                powerOnCalled.Should().BeTrue();
            });
        }
Esempio n. 4
0
        public void CanGetHeating()
        {
            AsyncContext.Run(async() =>
            {
                var instance = new ServiceSimulation(SynchronizationContext.Current);
                bool heating = false;

                instance.Heating.Subscribe(h => heating = h);

                // pre-check
                heating.Should().BeFalse();

                // test
                await instance.PowerOn(CancellationToken.None);

                // wait at least a tick for the heater to turn on.
                await Task.Delay(1200);

                // assert
                heating.Should().BeTrue();
            });
        }
Esempio n. 5
0
        public void CanGetPowerInWatts()
        {
            AsyncContext.Run(async() =>
            {
                var instance         = new ServiceSimulation(SynchronizationContext.Current);
                decimal powerInWatts = 0m;

                instance.PowerInWatts.Subscribe(p => powerInWatts = p);

                // pre-check
                powerInWatts.Should().BeInRange(0m, 2m);

                // test
                await instance.PowerOn(CancellationToken.None);

                // wait at least a tick for the heater to turn on.
                await Task.Delay(1200);

                // assert
                powerInWatts.Should().BeInRange(1700m, 1900m);
            });
        }