public void RequestStop_RaisesStopEvent(bool wireEvent, bool expectedRaised) { var stopRaised = false; void OnStop(object sender, EventArgs e) { stopRaised = true; } var stopper = new IrrigationStopper(); if (wireEvent) { stopper.StopRequested += OnStop; } stopper.RequestStop(); Assert.Equal(expectedRaised, stopRaised); }
public async Task Processor_TerminatesEarly_ForStopSignal() { //create a ridiculously long job for purposes of this unit test var job = new IrrigationJob { Duration = TimeSpan.FromMinutes(5), Valve = 1 }; //queue it for execution await _channel.Writer.WriteAsync(job); await _processor.StartAsync(CancellationToken.None); //give it a little bit to kick off await Task.Delay(TimeSpan.FromSeconds(1)); _stopper.RequestStop(); //give it a few seconds to wrap up await Task.Delay(TimeSpan.FromSeconds(1)); Assert.Equal(PinValue.High, _gpioDriver.Pins[1].Value); //master control valve should be off Assert.Equal(PinValue.High, _gpioDriver.Pins[2].Value); //irrigation valve should be off }