コード例 #1
0
        public void WebGetActivity_ExecutionImpl_ErrorResultTO_ReturnErrors_ToActivity_Success()
        {
            //-----------------------Arrange-------------------------
            const string response    = "{\"Message\":\"TEST Error\"}";
            var          environment = new ExecutionEnvironment();

            var mockEsbChannel           = new Mock <IEsbChannel>();
            var mockDSFDataObject        = new Mock <IDSFDataObject>();
            var mockExecutionEnvironment = new Mock <IExecutionEnvironment>();

            var errorResultTO = new ErrorResultTO();

            using (var service = new WebService(XmlResource.Fetch("WebService"))
            {
                RequestResponse = response
            })
            {
                mockDSFDataObject.Setup(o => o.Environment).Returns(environment);
                mockDSFDataObject.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object);

                var dsfWebGetActivity = new TestWebGetActivity {
                    OutputDescription = service.GetOutputDescription(),
                    ResourceID        = InArgument <Guid> .FromValue(Guid.Empty),
                    QueryString       = "test Query",
                    Headers           = new List <INameValue>(),
                    ResponseFromWeb   = response,
                    HadErrorMessage   = "Some error"
                };
                //-----------------------Act-----------------------------
                dsfWebGetActivity.TestExecutionImpl(mockEsbChannel.Object, mockDSFDataObject.Object, "Test Inputs", "Test Outputs", out errorResultTO, 0);
                //-----------------------Assert--------------------------
                Assert.AreEqual(1, errorResultTO.FetchErrors().Count);
                Assert.AreEqual("Some error", errorResultTO.FetchErrors()[0]);
            }
        }
コード例 #2
0
        public void WebGetActivity_Execute_ErrorResponse_ShouldSetVariables()
        {
            //------------Setup for test--------------------------
            const string response    = "{\"Message\":\"Error\"}";
            var          environment = new ExecutionEnvironment();

            var dsfWebGetActivity = new TestWebGetActivity
            {
                ResourceCatalog = new Mock <IResourceCatalog>().Object
            };

            var serviceOutputs = new List <IServiceOutputMapping> {
                new ServiceOutputMapping("Message", "[[Message]]", "")
            };

            dsfWebGetActivity.Outputs = serviceOutputs;

            var serviceXml = XmlResource.Fetch("WebService");
            var service    = new WebService(serviceXml)
            {
                RequestResponse = response
            };

            dsfWebGetActivity.OutputDescription = service.GetOutputDescription();
            dsfWebGetActivity.ResponseFromWeb   = response;
            dsfWebGetActivity.ResourceID        = InArgument <Guid> .FromValue(Guid.Empty);

            dsfWebGetActivity.QueryString = "Error";

            var dataObjectMock = new Mock <IDSFDataObject>();

            dataObjectMock.Setup(o => o.Environment).Returns(environment);
            dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object);

            dsfWebGetActivity.SourceId          = Guid.Empty;
            dsfWebGetActivity.Headers           = new List <INameValue>();
            dsfWebGetActivity.OutputDescription = new OutputDescription();
            dsfWebGetActivity.OutputDescription.DataSourceShapes.Add(new DataSourceShape()
            {
                Paths = new List <IPath>()
                {
                    new StringPath()
                    {
                        ActualPath = "[[Response]]", OutputExpression = "[[Response]]"
                    }
                }
            });

            //------------Execute Test---------------------------
            dsfWebGetActivity.Execute(dataObjectMock.Object, 0);
            //------------Assert Results-------------------------
            Assert.AreEqual(response, ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[Message]]", 0)));
        }
コード例 #3
0
        public void WebGetActivity_ExecutionImpl_IsResponseBase64_True_And_IsObject_False_Html_WebGetResponse_ExpectHtmlBase64String()
        {
            //-----------------------Arrange-------------------------
            const string htmlData    = @"<!DOCTYPE html>\r\n<html lang=\""en\"">\r\n  <head>\r\n   <title>Img Align Attribute<\\/title>\r\n <\\/head>\r\n<body>\r\n  <p>This is an example. <img src=\""image.png\"" alt=\""Image\"" align=\""middle\""> More text right here\r\n  <img src=\""image.png\"" alt=\""Image\"" width=\""100\""\\/>\r\n  <\\/body>\r\n<\\/html>";
            var          htmlBytes   = htmlData.Base64StringToByteArray();
            string       response    = htmlBytes.ToBase64String();
            var          environment = new ExecutionEnvironment();

            var mockEsbChannel    = new Mock <IEsbChannel>();
            var mockDSFDataObject = new Mock <IDSFDataObject>();

            var errorResultTO = new ErrorResultTO();

            using (var service = new WebService(XmlResource.Fetch("WebService"))
            {
                RequestResponse = response
            })
            {
                mockDSFDataObject.Setup(o => o.Environment).Returns(environment);
                mockDSFDataObject.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object);

                var dsfWebGetActivity = new TestWebGetActivity
                {
                    OutputDescription = service.GetOutputDescription(),
                    ResourceID        = InArgument <Guid> .FromValue(Guid.Empty),
                    QueryString       = "test Query",
                    Headers           = new List <INameValue>(),
                    ResponseFromWeb   = response,
                    IsResponseBase64  = true,
                    Outputs           = new List <IServiceOutputMapping>
                    {
                        new ServiceOutputMapping {
                            MappedTo = "[[response]]"
                        }
                    },
                };
                //-----------------------Act-----------------------------
                dsfWebGetActivity.TestExecutionImpl(mockEsbChannel.Object, mockDSFDataObject.Object, "Test Inputs", "Test Outputs", out errorResultTO, 0);
                //-----------------------Assert--------------------------
                var actualResponseWWJson = environment.Eval("[[response]]", 0) as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult;
                var actualResponse       = (actualResponseWWJson.Item as DataStorage.WarewolfAtom.DataString).Item;

                Assert.IsFalse(errorResultTO.HasErrors());
                Assert.AreEqual(response, actualResponse);
            }
        }
コード例 #4
0
        public void WebGetActivity_ExecutionImpl_IsResponseBase64_False_And_IsObject_True_Json_WebGetResponse_ExpectJsonBase64()
        {
            //-----------------------Arrange-------------------------
            var    jsonData    = "{color: \"red\",value: \"#f00\"}";
            var    jsonBytes   = jsonData.Base64StringToByteArray();
            string response    = jsonBytes.ToBase64String();
            var    environment = new ExecutionEnvironment();

            var mockEsbChannel    = new Mock <IEsbChannel>();
            var mockDSFDataObject = new Mock <IDSFDataObject>();

            var errorResultTO = new ErrorResultTO();

            using (var service = new WebService(XmlResource.Fetch("WebService"))
            {
                RequestResponse = response
            })
            {
                mockDSFDataObject.Setup(o => o.Environment).Returns(environment);
                mockDSFDataObject.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object);

                var dsfWebGetActivity = new TestWebGetActivity {
                    OutputDescription = service.GetOutputDescription(),
                    ResourceID        = InArgument <Guid> .FromValue(Guid.Empty),
                    QueryString       = "test Query",
                    Headers           = new List <INameValue>(),
                    ResponseFromWeb   = response,
                    IsResponseBase64  = false,
                    IsObject          = true,
                    ObjectName        = "[[@response]]"
                };
                //-----------------------Act-----------------------------
                dsfWebGetActivity.TestExecutionImpl(mockEsbChannel.Object, mockDSFDataObject.Object, "Test Inputs", "Test Outputs", out errorResultTO, 0);
                //-----------------------Assert--------------------------
                var actualResponseWWJson = environment.EvalForJson("[[@response]]") as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult;
                var actualResponse       = (actualResponseWWJson.Item as DataStorage.WarewolfAtom.JsonObject).Item;

                Assert.IsFalse(errorResultTO.HasErrors());
                Assert.AreEqual(JToken.Parse(jsonData).ToString(), actualResponse.ToString());
            }
        }
コード例 #5
0
        public void WebGetActivity_Execute_WithValidTextResponse_ShouldSetVariables()
        {
            //------------Setup for test--------------------------
            const string response = "{\"Location\": \"Paris\",\"Time\": \"May 29, 2013 - 09:00 AM EDT / 2013.05.29 1300 UTC\"," +
                                    "\"Wind\": \"from the NW (320 degrees) at 10 MPH (9 KT) (direction variable):0\"," +
                                    "\"Visibility\": \"greater than 7 mile(s):0\"," +
                                    "\"Temperature\": \"59 F (15 C)\"," +
                                    "\"DewPoint\": \"41 F (5 C)\"," +
                                    "\"RelativeHumidity\": \"51%\"," +
                                    "\"Pressure\": \"29.65 in. Hg (1004 hPa)\"," +
                                    "\"Status\": \"Success\"" +
                                    "}";
            var environment = new ExecutionEnvironment();

            environment.Assign("[[City]]", "PMB", 0);
            environment.Assign("[[CountryName]]", "South Africa", 0);
            var dsfWebGetActivity = new TestWebGetActivity
            {
                ResourceCatalog = new Mock <IResourceCatalog>().Object
            };
            var serviceInputs = new List <IServiceInput> {
                new ServiceInput("CityName", "[[City]]"), new ServiceInput("Country", "[[CountryName]]")
            };
            var serviceOutputs = new List <IServiceOutputMapping> {
                new ServiceOutputMapping("Response", "[[Response]]", "")
            };

            dsfWebGetActivity.Inputs  = serviceInputs;
            dsfWebGetActivity.Outputs = serviceOutputs;
            var serviceXml = XmlResource.Fetch("WebService");
            var service    = new WebService(serviceXml)
            {
                RequestResponse = response
            };

            dsfWebGetActivity.OutputDescription = service.GetOutputDescription();
            dsfWebGetActivity.ResponseFromWeb   = response;
            var dataObjectMock = new Mock <IDSFDataObject>();

            dataObjectMock.Setup(o => o.Environment).Returns(environment);
            dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object);
            dsfWebGetActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty);

            dsfWebGetActivity.QueryString = "";

            dsfWebGetActivity.SourceId          = Guid.Empty;
            dsfWebGetActivity.Headers           = new List <INameValue>();
            dsfWebGetActivity.OutputDescription = new OutputDescription();
            dsfWebGetActivity.OutputDescription.DataSourceShapes.Add(new DataSourceShape()
            {
                Paths = new List <IPath>()
                {
                    new StringPath()
                    {
                        ActualPath = "[[Response]]", OutputExpression = "[[Response]]"
                    }
                }
            });

            //------------Execute Test---------------------------
            dsfWebGetActivity.Execute(dataObjectMock.Object, 0);
            //------------Assert Results-------------------------
            Assert.IsNotNull(dsfWebGetActivity.OutputDescription);
            Assert.AreEqual(response, ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[Response]]", 0)));
        }