Esempio n. 1
0
        public void CanCallPowerOff()
        {
            AsyncContext.Run(async() =>
            {
                bool powerOffCalled   = false;
                var cancellationToken = CancellationToken.None;

                var instance = new ServiceSimulation(
                    SynchronizationContext.Current,
                    1000,
                    true,
                    0m,
                    1.3m,
                    0.0m,
                    0.0m,
                    false);

                instance.PoweredOn.Subscribe(x =>
                {
                    if (!x)
                    {
                        powerOffCalled = true;
                    }
                });
                await instance.PowerOff(cancellationToken);
                powerOffCalled.Should().BeTrue();
            });
        }
Esempio n. 2
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. 3
0
        public void CannotCallResetProtectionTooHighTemperature()
        {
            AsyncContext.Run(async() =>
            {
                bool resetCalled      = false;
                var cancellationToken = CancellationToken.None;

                var instance = new ServiceSimulation(
                    SynchronizationContext.Current,
                    1000,
                    true,
                    140m,
                    1.3m,
                    0.0m,
                    0.0m,
                    true);

                instance.Protection.Subscribe(x =>
                {
                    if (!x)
                    {
                        resetCalled = true;
                    }
                });

                Func <Task> act = () => instance.ResetProtection(cancellationToken);

                await act.Should().ThrowAsync <BoilerException>();
                resetCalled.Should().BeFalse();
            });
        }
Esempio n. 4
0
        public void CanCallResetProtection()
        {
            AsyncContext.Run(async() =>
            {
                bool resetCalled = false;

                var cancellationToken = CancellationToken.None;

                var instance = new ServiceSimulation(
                    SynchronizationContext.Current,
                    1000,
                    true,
                    0m,
                    1.3m,
                    0.0m,
                    0.0m,
                    true);

                instance.Protection.Subscribe(x =>
                {
                    if (!x)
                    {
                        resetCalled = true;
                    }
                });

                await instance.ResetProtection(cancellationToken);
                resetCalled.Should().BeTrue();
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Sets up dependency injection for the bUnit tests.
        /// </summary>
        /// <param name="services">The services to set up.</param>
        /// <param name="serviceSimulation">The service simulation to use.</param>
        public static void SetupDependencyInjection(IServiceCollection services, ServiceSimulation serviceSimulation = null)
        {
            if (services is null)
            {
                throw new System.ArgumentNullException(nameof(services));
            }

            if (serviceSimulation == null)
            {
                serviceSimulation = new ServiceSimulation(SynchronizationContext.Current, 10, false, 0m, 1.2m, 0m, 0m, false);
            }

            services.AddSingleton <ICommandPolicyProvider>(s
                                                           => new DelegateCommandPolicyProvider(() => Policy.TimeoutAsync(3)));

            // Register app-specific services
            services.AddBlazorise(options =>
            {
                options.ChangeTextOnKeyPress = true;
            })
            .AddBootstrapProviders()
            .AddFontAwesomeIcons();

            services.AddSingleton <ITitleService, TitleService>();
            services.AddSingleton <NavigationManager, TestableNavigationManager>();
            services.AddSingleton <HeaderViewModel>();
            services.AddSingleton <MachineOffCheckViewModel>();
            services.AddSingleton <BoilerViewModel>();
            services.AddSingleton(serviceSimulation);
            services.AddSingleton <IPowerService>(s => s.GetRequiredService <ServiceSimulation>());
            services.AddSingleton <IBoilerService>(s => s.GetRequiredService <ServiceSimulation>());
        }
Esempio n. 6
0
 public void CanConstruct()
 {
     AsyncContext.Run(() =>
     {
         var instance = new ServiceSimulation(SynchronizationContext.Current);
         instance.Should().NotBeNull();
     });
 }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestContextFixture"/> class.
        /// </summary>
        /// <param name="serviceSimulation">The service simulation to use.</param>
        public TestContextFixture(ServiceSimulation serviceSimulation = null)
        {
            this.TestContext = new TestContext();

            this.TestContext.JSInterop.Mode = JSRuntimeMode.Loose;

            SetupDependencyInjection(this.TestContext.Services, serviceSimulation);
        }
Esempio n. 8
0
 public void CanCallDispose()
 {
     AsyncContext.Run(() =>
     {
         var instance = new ServiceSimulation(SynchronizationContext.Current);
         Action act   = () => instance.Dispose();
         act.Should().NotThrow();
     });
 }
Esempio n. 9
0
        public void CanCallSetTargetPressure()
        {
            AsyncContext.Run(async() =>
            {
                decimal actualTargetPressure = 0m;
                var targetPressure           = 1.4m;

                var instance = new ServiceSimulation(SynchronizationContext.Current);

                instance.TargetPressure.Subscribe(tp => actualTargetPressure = tp);

                await instance.SetTargetPressure(targetPressure, CancellationToken.None);
                actualTargetPressure.Should().Be(targetPressure);
            });
        }
Esempio n. 10
0
 public void CanConstructWithArguments()
 {
     AsyncContext.Run(() =>
     {
         var instance = new ServiceSimulation(
             SynchronizationContext.Current,
             1000,
             false,
             0m,
             1.3m,
             0.1m,
             0.1m,
             true);
         instance.Should().NotBeNull();
     });
 }
Esempio n. 11
0
        public void CannotCallSetTemperatureOffsetTooHigh()
        {
            AsyncContext.Run(async() =>
            {
                bool offsetCalled;
                var instance = new ServiceSimulation(SynchronizationContext.Current);
                instance.Temperature.Subscribe(_ => offsetCalled = true);

                // reset offsetCalled because it's a behaviorsubject that will always trigger.
                offsetCalled = false;

                Func <Task> act = () => instance.SetTemperatureOffset(5m, CancellationToken.None);

                await act.Should().ThrowAsync <ArgumentOutOfRangeException>();
                offsetCalled.Should().BeFalse();
            });
        }
Esempio n. 12
0
        public void CanCallSetTemperatureOffset()
        {
            AsyncContext.Run(async() =>
            {
                var instance = new ServiceSimulation(SynchronizationContext.Current);

                decimal actualOffset = 0m;

                instance.TemperatureOffset.Subscribe(o => actualOffset = o);

                var targetOffset      = 0.5m;
                var cancellationToken = CancellationToken.None;

                await instance.SetTemperatureOffset(targetOffset, cancellationToken);
                actualOffset.Should().Be(targetOffset);
            });
        }
Esempio n. 13
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. 14
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. 15
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);
            });
        }
Esempio n. 16
0
 public SimulationController()
 {
     serviceSimulations = new ServiceSimulation();
 }