Ejemplo n.º 1
0
        public void Switch_Notifies_When_ToggledOff()
        {
            // arrange
            SwitchState          state          = SwitchState.On;
            ExternalSwitchMemory externalSwitch = new ExternalSwitchMemory(state);
            SwitchReader         reader         = new SwitchReader(externalSwitch);

            reader.OnSwitchChanged = (s) => state = s;

            // act
            externalSwitch.CurrentState = SwitchState.Off;

            // assert
            Assert.AreEqual(SwitchState.Off, state);
        }
Ejemplo n.º 2
0
        public void Switch_NotifiesOnlyOnce_When_ToggledOnTwice()
        {
            // arrange
            int toggleCount = 0;
            ExternalSwitchMemory externalSwitch = new ExternalSwitchMemory(SwitchState.Off);
            SwitchReader         reader         = new SwitchReader(externalSwitch);

            reader.OnSwitchChanged = (s) => toggleCount++;

            // act
            externalSwitch.CurrentState = SwitchState.On;
            externalSwitch.CurrentState = SwitchState.On;

            // assert
            Assert.AreEqual(1, toggleCount);
        }
Ejemplo n.º 3
0
        public void Switch_DoesNotNotify_When_ToggledOn_And_AlreadyOn()
        {
            // arrange
            int toggleCount = 0;
            ExternalSwitchMemory externalSwitch = new ExternalSwitchMemory(SwitchState.On);
            SwitchReader         reader         = new SwitchReader(externalSwitch);

            externalSwitch.CurrentState = SwitchState.On;
            reader.OnSwitchChanged      = (s) => toggleCount++;

            // act
            externalSwitch.CurrentState = SwitchState.On;

            // assert
            Assert.AreEqual(0, toggleCount);
        }