public void Add_AlreadyContainsGateWithSameGatenr_ThrowsArgumentException() { // Arrange var someNonuniqueGatenr = 3263827; var dut = new GateStates(); dut.Add(NewGate(), someNonuniqueGatenr); // Act var actual = Assert.Throws <ArgumentException>(() => dut.Add(NewGate(), someNonuniqueGatenr)); // Assert actual.Message.Should() .Contain($"{someNonuniqueGatenr}"); }
public void Add_ContainsOtherGates_CanBeRetrievedByGatenr() { // Arrange var mockGate = new Mock <IGateState>(); var someGatenr = 2187; var dut = new GateStates(); // Add other gates - gate numbers are not significant, except that they be unique. dut.Add(NewGate(), 1138); dut.Add(NewGate(), 4711); var expected = mockGate.Object; // Act dut.Add(expected, someGatenr); var actual = dut.GetStateOf(someGatenr); // Assert Assert.Same(expected, actual); }
public void Add_Empty_CanBeRetrievedByGatenr() { // Arrange var mockGate = new Mock <IGateState>(); var someGatenr = 4711; var dut = new GateStates(); var expected = mockGate.Object; // Act dut.Add(expected, someGatenr); var actual = dut.GetStateOf(someGatenr); // Assert Assert.Same(expected, actual); }
public async Task InitializeHardware() { if (LightningProvider.IsLightningEnabled) { LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); var pmwProvider = LightningPwmProvider.GetPwmProvider(); // var pwmControllers = await Windows.Devices.Pwm.PwmController.GetControllersAsync(pmwProvider); var pwmControllers = Windows.Devices.Pwm.PwmController.GetControllersAsync(pmwProvider).GetAwaiter().GetResult(); var pwmController = pwmControllers[1]; // the on-device controller // This seems to go bad //pwmController.SetDesiredFrequency(100); _gpioController = await GpioController.GetDefaultAsync(); IPin GetInputPin(int pinNr) { return(new GpioPinWrapper(_gpioController.OpenPin(pinNr, GpioSharingMode.Exclusive), GpioPinDriveMode.InputPullUp)); } _gateStates = new GateStates(); _gateStates.Add( // Center switches (on bread board) new GateState( // Yellow button, Closed GetInputPin(27), // Red button, Open GetInputPin(22)), 1); _gateStates.Add( // Top switches (on bread board) new GateState( // Yellow button, Closed GetInputPin(4), // Red button, Open GetInputPin(17)), 2); IPwmPin GetPwmPin(int pinNr) { //var pin = _gpioController.OpenPin(pinNr); //pin.SetDriveMode(GpioPinDriveMode.Output); return(new PwmPinWrapper(pwmController.OpenPin(pinNr))); } GateController = new GateController( // TODO : pins in settings, selector: 6, 13, 19 new Selector(GetOutputPins(6, 13, 19)), new PwmController( // TODO : pins in settings: 20, 21 GetPwmPin(20), GetPwmPin(21), // TODO : steps per change in settings 3), _gateStates); // TODO : pins in settings: 24 _heartBeatPin = GetOutputPins(24).First(); _heartBeatTimer = new Timer(HandleHeartBeat, _heartBeatState, 100, Timeout.Infinite); } }