public async Task CheckHealth_ReturnsExpectedFromStatus(bool running, HealthStatus expectedStatus) { var ctx = new HealthCheckContext(); var status = new IrrigationProcessorStatus(); status.Running = running; var check = new IrrigationProcessorHealthCheck(status); var result = await check.CheckHealthAsync(ctx, CancellationToken.None); Assert.Equal(expectedStatus, result.Status); }
public IrrigationProcessorTests() { _channel = Channel.CreateUnbounded <IrrigationJob>( new UnboundedChannelOptions() { AllowSynchronousContinuations = false, SingleWriter = true, SingleReader = true }); _gpioDriver = new MemoryGpioDriver(pinCount: 50); var gpioController = new GpioController(PinNumberingScheme.Logical, _gpioDriver); _stopper = new IrrigationStopper(); _config = new IrrigationConfig { MasterControlValveGpio = 1, PressureBleedTime = TimeSpan.Zero, ZoneSwitchDelay = TimeSpan.Zero, Valves = new List <PinMapping> { new PinMapping { GpioPin = 2, ValveNumber = 1 }, new PinMapping { GpioPin = 3, ValveNumber = 2 }, new PinMapping { GpioPin = 4, ValveNumber = 3 } } }; var pins = (_config.Valves.Select(v => v.GpioPin).Union(new[] { _config.MasterControlValveGpio })).ToArray(); var relayBoard = new RelayBoard(RelayType.NormallyOpen, gpioController, pins); var irrigationOptionsMock = new Mock <IOptions <IrrigationConfig> >(); irrigationOptionsMock.SetupGet(x => x.Value).Returns(_config); _loggerMock = new Mock <ILogger <IrrigationProcessor> >(); _status = new IrrigationProcessorStatus(); _processor = new IrrigationProcessor(_channel.Reader, relayBoard, _stopper, _status, irrigationOptionsMock.Object, _loggerMock.Object); //before the Microsoft GPIO controller can be used, the pins must be opened and set to the desired input/output state //run our initializer code to make that happen var pinInitializer = new PinInitializer(relayBoard, irrigationOptionsMock.Object); pinInitializer.StartAsync(CancellationToken.None).Wait(); }
public IrrigationProcessorHealthCheck(IrrigationProcessorStatus status) { _status = status; }