Ejemplo n.º 1
0
        public void DsfWebGetActivity_Execute_ErrorResponse_ShouldSetVariables()
        {
            //------------Setup for test--------------------------
            const string response    = "{\"Message\":\"Error\"}";
            var          environment = new ExecutionEnvironment();

            var dsfWebGetActivity = new TestDsfWebGetActivity();

            dsfWebGetActivity.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)));
        }
Ejemplo n.º 2
0
        public void DsfWebGetActivity_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 TestDsfWebGetActivity
                {
                    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]);
            }
        }
Ejemplo n.º 3
0
        public void DsfWebGetActivity_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 TestDsfWebGetActivity();

            dsfWebGetActivity.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)));
        }
Ejemplo n.º 4
0
        public void DsfWebGetActivity_ExecutionImpl_ResponseManager_PushResponseIntoEnvironment_GivenJsonResponse_MappedToRecodSet_ShouldSucess()
        {
            //-----------------------Arrange-------------------------
            const string json                  = "{\"Messanger\":\"jSon response from the request\"}";
            var          response              = Convert.ToBase64String(json.ToBytesArray());
            const string mappingFrom           = "mapFrom";
            const string recordSet             = "recset";
            const string mapTo                 = "mapTo";
            const string variableNameMappingTo = "[[recset().mapTo]]";

            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 TestDsfWebGetActivity
                {
                    OutputDescription = service.GetOutputDescription(),
                    ResourceID        = InArgument <Guid> .FromValue(Guid.Empty),
                    QueryString       = "test Query",
                    Headers           = new List <INameValue>(),
                    ResponseFromWeb   = response,
                    IsObject          = false,
                    Outputs           = new List <IServiceOutputMapping>
                    {
                        {
                            new ServiceOutputMapping
                            {
                                MappedFrom    = mappingFrom,
                                MappedTo      = mapTo,
                                RecordSetName = recordSet
                            }
                        }
                    }
                };
                //-----------------------Act-----------------------------
                dsfWebGetActivity.TestExecutionImpl(mockEsbChannel.Object, mockDSFDataObject.Object, "Test Inputs", "Test Outputs", out errorResultTO, 0);
                //-----------------------Assert--------------------------
                Assert.IsFalse(errorResultTO.HasErrors());

                //assert first DataSourceShapes
                var resourceManager   = dsfWebGetActivity.ResponseManager;
                var outputDescription = resourceManager.OutputDescription;
                var dataShapes        = outputDescription.DataSourceShapes;
                var paths             = dataShapes.First().Paths;
                Assert.IsNotNull(outputDescription);
                Assert.AreEqual("Messanger", paths.First().ActualPath);
                Assert.AreEqual("Messanger", paths.First().DisplayPath);
                Assert.AreEqual(variableNameMappingTo, paths.First().OutputExpression);
                Assert.AreEqual("jSon response from the request", paths.First().SampleData);

                //assert execution environment
                var envirVariable = environment.Eval(recordSet, 0);
                var ress          = envirVariable as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult;
                Assert.IsNotNull(envirVariable);
                Assert.IsFalse(ress.Item.IsNothing, "Item should contain the recset mapped to the messanger key");
            }
        }