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(); }); }
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(); }); }
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(); }); }
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(); }); }
/// <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>()); }
public void CanConstruct() { AsyncContext.Run(() => { var instance = new ServiceSimulation(SynchronizationContext.Current); instance.Should().NotBeNull(); }); }
/// <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); }
public void CanCallDispose() { AsyncContext.Run(() => { var instance = new ServiceSimulation(SynchronizationContext.Current); Action act = () => instance.Dispose(); act.Should().NotThrow(); }); }
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); }); }
public void CanConstructWithArguments() { AsyncContext.Run(() => { var instance = new ServiceSimulation( SynchronizationContext.Current, 1000, false, 0m, 1.3m, 0.1m, 0.1m, true); instance.Should().NotBeNull(); }); }
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(); }); }
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); }); }
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); }); }
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(); }); }
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); }); }
public SimulationController() { serviceSimulations = new ServiceSimulation(); }