Exemple #1
0
        public void WebPutActivity_Execute_WithValidXmlEscaped_ShouldSetVariables()
        {
            //------------Setup for test--------------------------
            const string response = "<CurrentWeather>" +
                                    "<Location>&lt;Paris&gt;</Location>" +
                                    "<Time>May 29, 2013 - 09:00 AM EDT / 2013.05.29 1300 UTC</Time>" +
                                    "<Wind>from the NW (320 degrees) at 10 MPH (9 KT) (direction variable):0</Wind>" +
                                    "<Visibility>&lt;greater than 7 mile(s):0&gt;</Visibility>" +
                                    "<Temperature> 59 F (15 C)</Temperature>" +
                                    "<DewPoint> 41 F (5 C)</DewPoint>" +
                                    "<RelativeHumidity> 51%</RelativeHumidity>" +
                                    "<Pressure> 29.65 in. Hg (1004 hPa)</Pressure>" +
                                    "<Status>Success</Status>" +
                                    "</CurrentWeather>";
            var environment = new ExecutionEnvironment();

            environment.Assign("[[City]]", "PMB", 0);
            environment.Assign("[[CountryName]]", "South Africa", 0);
            var DsfWebPutActivity = new TestWebPutActivity
            {
                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("Location", "[[weather().Location]]", "weather"), new ServiceOutputMapping("Time", "[[weather().Time]]", "weather"), new ServiceOutputMapping("Wind", "[[weather().Wind]]", "weather"), new ServiceOutputMapping("Visibility", "[[Visibility]]", "")
            };

            DsfWebPutActivity.Inputs  = serviceInputs;
            DsfWebPutActivity.Outputs = serviceOutputs;
            var serviceXml = XmlResource.Fetch("WebService");

            using (var service = new WebService(serviceXml)
            {
                RequestResponse = response
            })
            {
                DsfWebPutActivity.OutputDescription = service.GetOutputDescription();
                DsfWebPutActivity.ResponseFromWeb   = response;
                var dataObjectMock = new Mock <IDSFDataObject>();
                dataObjectMock.Setup(o => o.Environment).Returns(environment);
                dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object);
                DsfWebPutActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty);

                DsfWebPutActivity.QueryString = "";
                DsfWebPutActivity.PutData     = "";
                DsfWebPutActivity.SourceId    = Guid.Empty;
                DsfWebPutActivity.Headers     = new List <INameValue>();
                //------------Execute Test---------------------------
                DsfWebPutActivity.Execute(dataObjectMock.Object, 0);
                //------------Assert Results-------------------------
                Assert.IsNotNull(DsfWebPutActivity.OutputDescription);
                Assert.AreEqual("<greater than 7 mile(s):0>", ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[Visibility]]", 0)));
                Assert.AreEqual("<Paris>", ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[weather().Location]]", 0)));
                Assert.AreEqual("May 29, 2013 - 09:00 AM EDT / 2013.05.29 1300 UTC", ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[weather().Time]]", 0)));
                Assert.AreEqual("from the NW (320 degrees) at 10 MPH (9 KT) (direction variable):0", ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[weather().Wind]]", 0)));
            }
        }
Exemple #2
0
        public void WebPutActivity_Execute_WithInputVariables_ShouldEvalVariablesBeforeExecutingWebRequest()
        {
            //------------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);
            environment.Assign("[[Post]]", "Some data", 0);
            var DsfWebPutActivity = new TestWebPutActivity
            {
                Headers = new List <INameValue> {
                    new NameValue("Header 1", "[[City]]")
                },
                QueryString     = "http://www.testing.com/[[CountryName]]",
                PutData         = "This is post:[[Post]]",
                ResourceCatalog = new Mock <IResourceCatalog>().Object
            };
            var serviceOutputs = new List <IServiceOutputMapping> {
                new ServiceOutputMapping("Location", "[[weather().Location]]", "weather"), new ServiceOutputMapping("Time", "[[weather().Time]]", "weather"), new ServiceOutputMapping("Wind", "[[weather().Wind]]", "weather"), new ServiceOutputMapping("Visibility", "[[Visibility]]", "")
            };

            DsfWebPutActivity.Outputs = serviceOutputs;
            var serviceXml = XmlResource.Fetch("WebService");

            using (var service = new WebService(serviceXml)
            {
                RequestResponse = response
            })
            {
                DsfWebPutActivity.OutputDescription = service.GetOutputDescription();
                DsfWebPutActivity.ResponseFromWeb   = response;
                var dataObjectMock = new Mock <IDSFDataObject>();
                dataObjectMock.Setup(o => o.Environment).Returns(environment);
                dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object);
                DsfWebPutActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty);

                //------------Assert Preconditions-------------------
                Assert.AreEqual(1, DsfWebPutActivity.Headers.Count);
                Assert.AreEqual("Header 1", DsfWebPutActivity.Headers.ToList()[0].Name);
                Assert.AreEqual("[[City]]", DsfWebPutActivity.Headers.ToList()[0].Value);
                Assert.AreEqual("http://www.testing.com/[[CountryName]]", DsfWebPutActivity.QueryString);
                Assert.AreEqual("This is post:[[Post]]", DsfWebPutActivity.PutData);
                //------------Execute Test---------------------------
                DsfWebPutActivity.Execute(dataObjectMock.Object, 0);
                //------------Assert Results-------------------------
                Assert.AreEqual("PMB", DsfWebPutActivity.Head.ToList()[0].Value);
                Assert.AreEqual("http://www.testing.com/South Africa", DsfWebPutActivity.QueryRes);
                Assert.AreEqual("This is post:Some data", DsfWebPutActivity.PostValue);
            }
        }
Exemple #3
0
        public void WebPutActivity_Execute_WithNoOutputDescription_ShouldAddError()
        {
            //------------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 DsfWebPutActivity = new TestWebPutActivity
            {
                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("Location", "[[weather().Location]]", "weather"), new ServiceOutputMapping("Time", "[[weather().Time]]", "weather"), new ServiceOutputMapping("Wind", "[[weather().Wind]]", "weather"), new ServiceOutputMapping("Visibility", "[[Visibility]]", "")
            };

            DsfWebPutActivity.Inputs          = serviceInputs;
            DsfWebPutActivity.Outputs         = serviceOutputs;
            DsfWebPutActivity.ResponseFromWeb = response;
            var dataObjectMock = new Mock <IDSFDataObject>();

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

            DsfWebPutActivity.QueryString = "";
            DsfWebPutActivity.PutData     = "";
            DsfWebPutActivity.SourceId    = Guid.Empty;
            DsfWebPutActivity.Headers     = new List <INameValue>();
            //------------Execute Test---------------------------
            DsfWebPutActivity.Execute(dataObjectMock.Object, 0);
            //------------Assert Results-------------------------
            Assert.IsNull(DsfWebPutActivity.OutputDescription);
        }
Exemple #4
0
        public void WebPutActivity_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 DsfWebPutActivity = new TestWebPutActivity
            {
                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]]", "")
            };

            DsfWebPutActivity.Inputs  = serviceInputs;
            DsfWebPutActivity.Outputs = serviceOutputs;
            var serviceXml = XmlResource.Fetch("WebService");

            using (var service = new WebService(serviceXml)
            {
                RequestResponse = response
            })
            {
                DsfWebPutActivity.OutputDescription = service.GetOutputDescription();
                DsfWebPutActivity.ResponseFromWeb   = response;
                var dataObjectMock = new Mock <IDSFDataObject>();
                dataObjectMock.Setup(o => o.Environment).Returns(environment);
                dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object);
                DsfWebPutActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty);

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

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