public void OnPowerOnPerformsAction() { //arrange var fs = Substitute.For <IFileSystem>(); fs.Read("/sys/class/gpio/gpio123/direction").Returns("in"); fs.When(f => f.Watch(Arg.Any <string>(), Arg.Any <Func <bool> >(), Arg.Any <Action>())).Do(c => { if (c.Arg <Func <bool> >().Invoke()) { c.Arg <Action>().Invoke(); } }); var pinInterface = new LinuxPinInterface(123, fs) { Power = PowerValue.On }; var called = false; //act pinInterface.OnPowerOn(() => called = true); //assert Assert.True(called); }
public void OnPowerOnEnablesIfNotEnabled() { //arrange var fs = Substitute.For <IFileSystem>(); fs.Read("/sys/class/gpio/gpio123/direction").Returns("in"); var pinInterface = new LinuxPinInterface(123, fs); //act pinInterface.OnPowerOn(null); //assert fs.Received().Write("/sys/class/gpio/export", "123"); }