コード例 #1
0
        public void When_TriggerIsTrueButWasNotSetSinceLastExecute_Should_NotEmitResponse()
        {
            // Arrange: New (invalid) node
            var node = new WebRequestNode(TestNodeContext.Create());

            node.Trigger.Value = true;
            node.ExecuteAndWait(200); // Should emit error, since no URL is set
            node.URL.Value           = "http://localhost:12345/";
            node.ErrorCode.ValueSet += (object sender, ValueChangedEventArgs e) =>
            {
                Assert.Fail(); // Must not be called
            };
            node.ErrorMessage.ValueSet += (object sender, ValueChangedEventArgs e) =>
            {
                Assert.Fail(); // Must not be called
            };
            node.Response.ValueSet += (object sender, ValueChangedEventArgs e) =>
            {
                Assert.Fail(); // Must not be called
            };
            // Warning! This simulates the behaviour of the Logic Engine:
            node.Trigger.WasSet = false;
            // Act: Set proper URL and execute again:
            node.ExecuteAndWait(200);
            // Assert: Most has been asserted in the callbacks above, additionally assert that all Outputs must not be set:
            Assert.IsFalse(node.Response.HasValue);
            Assert.IsFalse(node.ErrorCode.HasValue);
            Assert.IsFalse(node.ErrorMessage.HasValue);
        }
コード例 #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:
        }
        public void When_UrlContainsTwentyVariables_Should_ShowTwentyVariableParametersWithVariableNames()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set URL without variable placeholder
            node.URL.Value = "http://www.google.de/?q={Variable1}+{Variable2}+{Variable3}+{Variable4}+{Variable5}+{Variable6}+{Variable7}+{Variable8}+{Variable9}+{Variable10}+{Variable11}+{Variable12}+{Variable13}+{Variable14}+{Variable15}+{Variable16}+{Variable17}+{Variable18}+{Variable19}+{Variable20}";
            // Assert: One Variable-Parameter must be visible
            Assert.AreEqual(20, node.Variables.Count);
            Assert.AreEqual("Variable1", node.Variables[0].Name);
            Assert.AreEqual("Variable2", node.Variables[1].Name);
            Assert.AreEqual("Variable3", node.Variables[2].Name);
            Assert.AreEqual("Variable4", node.Variables[3].Name);
            Assert.AreEqual("Variable5", node.Variables[4].Name);
            Assert.AreEqual("Variable6", node.Variables[5].Name);
            Assert.AreEqual("Variable7", node.Variables[6].Name);
            Assert.AreEqual("Variable8", node.Variables[7].Name);
            Assert.AreEqual("Variable9", node.Variables[8].Name);
            Assert.AreEqual("Variable10", node.Variables[9].Name);
            Assert.AreEqual("Variable11", node.Variables[10].Name);
            Assert.AreEqual("Variable12", node.Variables[11].Name);
            Assert.AreEqual("Variable13", node.Variables[12].Name);
            Assert.AreEqual("Variable14", node.Variables[13].Name);
            Assert.AreEqual("Variable15", node.Variables[14].Name);
            Assert.AreEqual("Variable16", node.Variables[15].Name);
            Assert.AreEqual("Variable17", node.Variables[16].Name);
            Assert.AreEqual("Variable18", node.Variables[17].Name);
            Assert.AreEqual("Variable19", node.Variables[18].Name);
            Assert.AreEqual("Variable20", node.Variables[19].Name);
        }
コード例 #4
0
        public void When_RestrictedHeadersAreUsedAndBodyIsSet_Should_SendAllRestrictedHeaders()
        {
            // Arrange: New node with echo URL
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "http://localhost:12345/foo";
            // Act: Set all supported restricted headers, set Trigger and Execute:
            // The list of restricted headers has been taken from https://stackoverflow.com/questions/239725/cannot-set-some-http-headers-when-using-system-net-webrequest
            // since I could not find an official source. Some restricted headers are excluded,
            // because they are too complicated to implement and not worth the trouble.
            node.Method.Value     = "POST";
            node.Body.Value       = "{dummy: 1}";
            node.HeaderMode.Value = "HeaderMode.8";
            node.Headers[0].Value = "Accept: text/html";
            node.Headers[1].Value = "Connection: Upgrade";
            node.Headers[2].Value = $"Content-Length: {node.Body.Value.Length}";
            node.Headers[3].Value = "Date: Fri, 22 Jan 2010 04:00:00 GMT";
            node.Headers[4].Value = "Host: localhost";
            node.Headers[5].Value = "If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT";
            node.Headers[6].Value = "Referer: gira.de";
            node.Headers[7].Value = "User-Agent: Gira";
            node.Trigger.Value    = true;
            node.ExecuteAndWait();
            // Assert: Must include the expected Response
            Assert.AreEqual("text/html", lastRequest.Headers.Get("Accept"));
            Assert.AreEqual("Upgrade", lastRequest.Headers.Get("Connection"));
            Assert.AreEqual($"{node.Body.Value.Length}", lastRequest.Headers.Get("Content-Length"));
            Assert.AreEqual("Fri, 22 Jan 2010 04:00:00 GMT", lastRequest.Headers.Get("Date"));
            Assert.AreEqual("localhost", lastRequest.Headers.Get("Host"));
            Assert.AreEqual("Sat, 29 Oct 1994 19:43:31 GMT", lastRequest.Headers.Get("If-Modified-Since"));
            Assert.AreEqual("gira.de", lastRequest.Headers.Get("Referer"));
            Assert.AreEqual("Gira", lastRequest.Headers.Get("User-Agent"));
        }
コード例 #5
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);
        }
        public void When_ParametersAreDefault_Should_NotShowBodyAndContentType()
        {
            // Arrange: New node with default parameters
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Nothing
            // Assert: Body and ContentType must not be visible
            Assert.IsNull(node.Body);
            Assert.IsNull(node.ContentType);
        }
コード例 #7
0
        public void When_NumberOfHeadersIsZero_Should_NotShowHeaderParameters()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set number of headers to 0
            node.HeaderMode.Value = "HeaderMode.0";
            // Assert: List of Headers is empty
            Assert.AreEqual(0, node.Headers.Count);
        }
        public void When_UrlContainsNoVariables_Should_NotShowVariableParameters()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set URL without variable placeholder
            node.URL.Value = "http://www.google.de/";
            // Assert: No Variable-Parameters must be visible
            Assert.AreEqual(0, node.Variables.Count);
        }
コード例 #9
0
        public void When_MethodIsNotGet_Should_ShowContentType()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set Method to somethig other than GET
            node.Method.Value = "PUT";
            // Assert: ContentType is available
            Assert.IsNotNull(node.ContentType);
        }
        public void When_MethodIsPost_Should_ShowBodyAndContentTypeParameter()
        {
            // Arrange: New node with Method set to POST
            var node = new WebRequestNode(TestNodeContext.Create());

            node.Method.Value = "POST";
            // Act: Nothing
            // Assert: The Parameter Body and ContentType must be visible
            Assert.IsNotNull(node.Body);
            Assert.IsNotNull(node.ContentType);
        }
        public void When_UrlContainsOneVariableShouldShowOneVariableParameterWithVariableName()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set URL without variable placeholder
            node.URL.Value = "http://www.google.de/?q={Variable1}";
            // Assert: One Variable-Parameter must be visible
            Assert.AreEqual(1, node.Variables.Count);
            Assert.AreEqual("Variable1", node.Variables[0].Name);
        }
        public void When_AuthTypeIsBasic_Should_HaveTokenInput_But_NoUserNameAndPasswordInputs()
        {
            // Arrange: New node with simple URL
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set AuthType to BasicAuth
            node.AuthType.Value = AuthCredentials.AuthType.BearerToken.ToString();
            // Assert:
            Assert.IsNotNull(node.AuthToken);
            Assert.IsNull(node.AuthUserName);
            Assert.IsNull(node.AuthPassword);
        }
        public void When_MethodIsGet_Should_HideBodyAndContentTypeParameters()
        {
            // Arrange: New node with default parameters
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Switch Method to POST and then back to GET
            node.Method.Value = "POST";
            node.Method.Value = "GET";
            // Assert: Parameter Body and ContentType must not be visible.
            Assert.IsNull(node.Body);
            Assert.IsNull(node.ContentType);
        }
        public void When_UrlContainsMalformedVariables_Should_HaveNoVariables()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set url with valid variable placeholder first
            node.URL.Value = "http://www.google.de/?q={Variable1}";
            // Then update URL with invalid placeholder
            node.URL.Value = "http://www.google.de/?q={{}}+{12asdasd}+{_asdf}+{Asdf_Foo}+{Asdf-Foo}+{Asdf?}+{Über}";
            // Assert: No Variable-Parameter must be visible
            Assert.AreEqual(0, node.Variables.Count);
        }
        public void When_ParametersAreDefault_Should_ShowParametersTriggerAndMethodAndUrlAndHeaderMode()
        {
            // Arrange: New node with default parameters
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Nothing
            // Assert: The Parameters Trigger, Method, Url and HeaderMode must be visible and have the appropriate default values.
            Assert.IsFalse(node.Trigger.HasValue);
            Assert.AreEqual("GET", node.Method.Value);
            Assert.IsFalse(node.URL.HasValue);
            Assert.AreEqual("HeaderMode.0", node.HeaderMode.Value);
        }
コード例 #16
0
        public void When_ProtocolIsNotSupported_Should_OutputError()
        {
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "rsync://localhost:12346/200";
            // Act: Execute request
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: ErrorCode is set to 999, ErrorMessage contains a message and Response must not be set
            Assert.AreEqual(997, node.ErrorCode.Value);
            Assert.IsNotNull(node.ErrorMessage.Value);
            Assert.IsFalse(node.Response.HasValue);
        }
コード例 #17
0
        public void When_MethodIsGet_Should_NotShowContentType()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Nothig
            // Assert: ContentType is not available
            Assert.IsNull(node.ContentType);
            // Act: Set Method to GET
            node.Method.Value = "GET";
            // Assert: ContentType is still not available
            Assert.IsNull(node.ContentType);
        }
コード例 #18
0
        public void When_MethodIsChanged_Should_NotResetContentType()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set Method to somethig other than GET and change ContentType
            node.Method.Value      = "PUT";
            node.ContentType.Value = "application/json";
            // Act: Change Method to something else, except GET
            node.Method.Value = "DELETE";
            // Assert: The previously ContentType is not reset
            Assert.AreEqual("application/json", node.ContentType.Value);
        }
コード例 #19
0
        public void When_TriggerIsSet_Should_EmitResponse()
        {
            // Arrange: New node with simple URL
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "http://localhost:12345/";
            // Act: Set Trigger and Execute:
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: Must include the expected Response
            Assert.AreEqual(dummyResponse, node.Response.Value);
            Assert.AreEqual("GET", lastRequest.HttpMethod);
        }
コード例 #20
0
        public void When_UsingFTP_Should_FailWithErrorCode()
        {
            // Arrange: Create web request with FTP URI
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "ftp://192.168.178.1";
            // Act: Execute node
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: Error code 997 with corresponding error message must be replied
            Assert.AreEqual(997, node.ErrorCode.Value);
            Assert.IsTrue(node.ErrorMessage.HasValue);
        }
        public void When_AuthTypeIsNone_Should_NotSendAuthorizationHeader()
        {
            // Arrange: New node with simple URL
            var node = new WebRequestNode(TestNodeContext.Create());

            node.AuthType.Value = AuthCredentials.AuthType.NoAuth.ToString();
            node.URL.Value      = "http://localhost:12345/";
            // Act: Set Trigger and Execute:
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: Must include the expected Response
            Assert.IsNull(lastRequest.Headers.Get("Authorization"));
        }
        public void When_UrlContainsVariablesWithSameName_Should_AddVariableOnlyOnce()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set URL with multiple occurances of the same variables
            node.URL.Value = "http://www.google.de/?q={Variable1}+{Variable1}+{Variable3}+{Variable1}+{Variable2}";
            // Assert: Every variable occurs only once
            Assert.AreEqual(3, node.Variables.Count);
            Assert.AreEqual("Variable1", node.Variables[0].Name);
            Assert.AreEqual("Variable3", node.Variables[1].Name);
            Assert.AreEqual("Variable2", node.Variables[2].Name);
        }
コード例 #23
0
        public void When_ResposeReturns3xxCodeAndRedirectLocationFails_Should_OutputError()
        {
            // Arrange: Create request to a redirecting endpoint
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "http://localhost:12346/302";
            // Act: Execute request
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: ErrorCode is set to 404, ErrorMessage contains status code 404 and Response must not be set
            Assert.AreEqual(404, node.ErrorCode.Value);
            Assert.AreEqual("{statusCode: 404}", node.ErrorMessage.Value);
            Assert.IsFalse(node.Response.HasValue);
        }
コード例 #24
0
        public void When_ResposeReturns2xxCode_Should_OutputResponse()
        {
            // Arrange: Create request with 202 response code
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "http://localhost:12346/202";
            // Act: Execute request
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: Response contains response body and Error* must not be set
            Assert.AreEqual("{statusCode: 202}", node.Response.Value);
            Assert.IsFalse(node.ErrorMessage.HasValue);
            Assert.IsFalse(node.ErrorCode.HasValue);
        }
コード例 #25
0
        public void When_ResposeReturns3xxCode_Should_FollowRedirect_And_OutputResponse()
        {
            // Arrange: Create request to a redirecting endpoint
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "http://localhost:12346/301";
            // Act: Execute request
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: Response contains response body from the redirected location, and Error* must not be set
            Assert.AreEqual("{redirect: 200}", node.Response.Value);
            Assert.IsFalse(node.ErrorMessage.HasValue);
            Assert.IsFalse(node.ErrorCode.HasValue);
        }
        public void When_BodyContainsThreeVariables_Should_ShowThreeVariablesWithVariableNames()
        {
            // Arrange: New node
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Set Body with variables
            node.Method.Value = "POST";
            node.Body.Value   = "{data: {Data}, value: {Value}, order: {Order}}";
            // Assert: The variables should be available
            Assert.AreEqual(3, node.Variables.Count);
            Assert.AreEqual("Data", node.Variables[0].Name);
            Assert.AreEqual("Value", node.Variables[1].Name);
            Assert.AreEqual("Order", node.Variables[2].Name);
        }
コード例 #27
0
        public void When_ResposeReturns500Code_Should_OutputError()
        {
            // Arrange: Create request to a 500 response
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "http://localhost:12346/500";
            // Act: Execute request
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: ErrorCode is set to 500, ErrorMessage contains status code 500 and Response must not be set
            Assert.AreEqual(500, node.ErrorCode.Value);
            Assert.AreEqual("{statusCode: 500}", node.ErrorMessage.Value);
            Assert.IsFalse(node.Response.HasValue);
        }
コード例 #28
0
        public void When_ParametersAreDefault_Should_ShowOutputsResponseAndResponseErrorCodeAndResponseErrorCodeMessage()
        {
            // Arrange: New node with default parameters
            var node = new WebRequestNode(TestNodeContext.Create());

            // Act: Nothing
            // Assert: The Outputs Response, ResponseErrorCode and ResponseErrorMessage must be visible
            Assert.IsNotNull(node.Response);
            Assert.IsNotNull(node.ErrorCode);
            Assert.IsNotNull(node.ErrorMessage);
            Assert.IsFalse(node.Response.HasValue);
            Assert.IsFalse(node.ErrorCode.HasValue);
            Assert.IsFalse(node.ErrorMessage.HasValue);
        }
コード例 #29
0
        public void When_UrlIsMisformed_Should_OutputClientSideError()
        {
            // Arrange: Create node pointing to a malformed URL
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "http://*****:*****@foo-bar@blah$$$dollar/200";
            // Act: Execute request
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: ErrorCode is set to 999, ErrorMessage contains a message and Response must not be set
            Assert.AreEqual(999, node.ErrorCode.Value);
            Assert.IsNotNull(node.ErrorMessage.Value);
            Assert.IsFalse(node.Response.HasValue);
        }
コード例 #30
0
        public void When_RequestSucceeds_Should_OutputRespose()
        {
            // Arrange: Create node pointing to a 200 response code
            var node = new WebRequestNode(TestNodeContext.Create());

            node.URL.Value = "http://localhost:12346/200";
            // Act: Execute request
            node.Trigger.Value = true;
            node.ExecuteAndWait();
            // Assert: Response body must include status code and Error* outputs are not set
            Assert.AreEqual("{statusCode: 200}", node.Response.Value);
            Assert.IsFalse(node.ErrorCode.HasValue);
            Assert.IsFalse(node.ErrorMessage.HasValue);
        }