Пример #1
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)));
        }
Пример #2
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)));
        }