Exemplo n.º 1
0
        public void OnPowerChangeEnablesIfNotEnabled()
        {
            //arrange
            var fs = Substitute.For <IFileSystem>();

            fs.Read("/sys/class/gpio/gpio123/direction").Returns("in");
            var pinInterface = new LinuxPinInterface(123, fs);

            //act
            pinInterface.OnPowerChange(null);

            //assert
            fs.Received().Write("/sys/class/gpio/export", "123");
        }
Exemplo n.º 2
0
        public void OnPowerChangePerformsAction()
        {
            //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);
            var called       = false;

            //act
            pinInterface.OnPowerChange(() => called = true);

            //assert
            Assert.True(called);
        }