Ejemplo n.º 1
0
        public void When_ButtonUpOrDownReleasedAfterPresedLong_ShouldStopDimming(int upOrDown)
        {
            // Arrange: Create node
            var schedMock = new MockSchedulerService();
            var node      = new DimmerNode(TestNodeContext.Create(), schedMock);

            node.Mode.Value = DimmerNode.MODE_TWO_BUTTON_DIMMING;
            var testCases = new Tuple <BoolValueObject, double>[] {
                new Tuple <BoolValueObject, double>(node.ButtonDimUp, 100.0d),
                new Tuple <BoolValueObject, double>(node.ButtonDimDown, -100.0d)
            };

            // Act Phase 2: Press button and release button
            testCases[upOrDown].Item1.Value = true;
            node.Execute();
            schedMock.MockInvokeNow();
            // Assert Phase 1: Light should not be switched on or off, but dimming should be started
            Assert.IsFalse(node.SwitchOnOff.HasValue);
            Assert.AreEqual(testCases[upOrDown].Item2, node.Dim.Value);
            // Act Phase 2: Release button after 800ms
            testCases[upOrDown].Item1.Value = false;
            schedMock.Now = schedMock.Now + TimeSpan.FromMilliseconds(800);
            node.Execute();
            // Assert: Light should not be switched on or off, and dimming should be stoped
            Assert.IsNull(schedMock.InvokeInAction); // No start dimming action should be scheduled
            Assert.IsFalse(node.SwitchOnOff.HasValue);
            Assert.AreEqual(0.0d, node.Dim.Value);
        }
Ejemplo n.º 2
0
        public void When_PressedButtonUpOrDownLongWithoutReleaseAfterTimeout_ShouldStopDimmingAfterTimeout(int upOrDown, int startDimDelay, int dimPercent, int expectedDimPercent)
        {
            // Arrange: Create node
            var schedMock = new MockSchedulerService();
            var node      = new DimmerNode(TestNodeContext.Create(), schedMock);

            node.Mode.Value          = DimmerNode.MODE_TWO_BUTTON_DIMMING;
            node.StartDimDelay.Value = startDimDelay;
            node.DimPercent.Value    = dimPercent;
            var testCases = new[] {
                node.ButtonDimUp,
                node.ButtonDimDown
            };

            // Act 1: Press button
            testCases[upOrDown].Value = true;
            int callCounter = 0;

            schedMock.InvokeInObserver = (delay) => {
                ++callCounter;
                Assert.AreEqual(new TimeSpan(0, 0, 0, 0, startDimDelay), delay);
            };
            node.Execute();
            // Assert 1: The correct timeout is applied
            Assert.AreEqual(1, callCounter); // InvokeIn must be called exactly once.
            // Act 2:
            schedMock.MockInvokeNow();
            Assert.AreEqual((double)expectedDimPercent, node.Dim.Value);
            schedMock.Now             = schedMock.Now.AddMilliseconds(startDimDelay + 100);
            testCases[upOrDown].Value = false;
            node.Execute();
            // Assert 2:
        }
Ejemplo n.º 3
0
        public void When_ButtonUpOrDownPressedLong_ShouldStartDimmingUpOrDown(int upOrDOwn)
        {
            // Arrange: Create node
            var schedMock = new MockSchedulerService();
            var node      = new DimmerNode(TestNodeContext.Create(), schedMock);

            node.Mode.Value = DimmerNode.MODE_TWO_BUTTON_DIMMING;
            var testCases = new Tuple <BoolValueObject, double>[] {
                new Tuple <BoolValueObject, double>(node.ButtonDimUp, 100.0d),
                new Tuple <BoolValueObject, double>(node.ButtonDimDown, -100.0d)
            };

            // Act: Press button and release button
            testCases[upOrDOwn].Item1.Value = true;
            node.Execute();
            schedMock.MockInvokeNow();
            // Assert: Light should not be switched on or off, but dimming should be started
            Assert.IsFalse(node.SwitchOnOff.HasValue);
            Assert.AreEqual(testCases[upOrDOwn].Item2, node.Dim.Value);
        }