public void DsfWebPostActivity_Execute_ErrorResponse_ShouldSetVariables() { //------------Setup for test-------------------------- const string response = "{\"Message\":\"Error\"}"; var environment = new ExecutionEnvironment(); var dsfWebPostActivity = new TestDsfWebPostActivity(); dsfWebPostActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); var mockResourceCatalog = new Mock <IResourceCatalog>(); var webSource = new WebSource(); webSource.Address = "http://TFSBLD.premier.local:9910/api/"; webSource.AuthenticationType = AuthenticationType.Anonymous; mockResourceCatalog.Setup(resCat => resCat.GetResource <WebSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(webSource); dsfWebPostActivity.ResourceCatalog = mockResourceCatalog.Object; var serviceOutputs = new List <IServiceOutputMapping> { new ServiceOutputMapping("Message", "[[Message]]", "") }; dsfWebPostActivity.Outputs = serviceOutputs; var serviceXml = XmlResource.Fetch("WebService"); var service = new WebService(serviceXml) { RequestResponse = response }; dsfWebPostActivity.OutputDescription = service.GetOutputDescription(); dsfWebPostActivity.ResponseFromWeb = response; dsfWebPostActivity.QueryString = "Error"; dsfWebPostActivity.SourceId = Guid.Empty; dsfWebPostActivity.Headers = new List <INameValue>(); var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); dsfWebPostActivity.SourceId = Guid.Empty; dsfWebPostActivity.Headers = new List <INameValue>(); dsfWebPostActivity.OutputDescription = new OutputDescription(); dsfWebPostActivity.OutputDescription.DataSourceShapes.Add(new DataSourceShape() { Paths = new List <IPath>() { new StringPath() { ActualPath = "[[Response]]", OutputExpression = "[[Response]]" } } }); //------------Execute Test--------------------------- dsfWebPostActivity.Execute(dataObjectMock.Object, 0); //------------Assert Results------------------------- Assert.AreEqual(response, ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[Message]]", 0))); }
public void DsfWebPostActivity_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 dsfWebPostActivity = new TestDsfWebPostActivity { Headers = new List <INameValue> { new NameValue("Header 1", "[[City]]") }, QueryString = "http://www.testing.com/[[CountryName]]", PostData = "This is post:[[Post]]" }; dsfWebPostActivity.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]]", "") }; dsfWebPostActivity.Outputs = serviceOutputs; var serviceXml = XmlResource.Fetch("WebService"); var service = new WebService(serviceXml) { RequestResponse = response }; dsfWebPostActivity.OutputDescription = service.GetOutputDescription(); dsfWebPostActivity.ResponseFromWeb = response; var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); dsfWebPostActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); //------------Assert Preconditions------------------- Assert.AreEqual(1, dsfWebPostActivity.Headers.Count); Assert.AreEqual("Header 1", dsfWebPostActivity.Headers.ToList()[0].Name); Assert.AreEqual("[[City]]", dsfWebPostActivity.Headers.ToList()[0].Value); Assert.AreEqual("http://www.testing.com/[[CountryName]]", dsfWebPostActivity.QueryString); Assert.AreEqual("This is post:[[Post]]", dsfWebPostActivity.PostData); //------------Execute Test--------------------------- dsfWebPostActivity.Execute(dataObjectMock.Object, 0); //------------Assert Results------------------------- Assert.AreEqual("PMB", dsfWebPostActivity.Head.ToList()[0].Value); Assert.AreEqual("http://www.testing.com/South Africa", dsfWebPostActivity.QueryRes); Assert.AreEqual("This is post:Some data", dsfWebPostActivity.PostValue); }
public void DsfWebPostActivity_Execute_WithValidXmlEscaped_ShouldSetVariables() { //------------Setup for test-------------------------- const string response = "<CurrentWeather>" + "<Location><Paris></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><greater than 7 mile(s):0></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 dsfWebPostActivity = new TestDsfWebPostActivity(); dsfWebPostActivity.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]]", "") }; dsfWebPostActivity.Inputs = serviceInputs; dsfWebPostActivity.Outputs = serviceOutputs; var serviceXml = XmlResource.Fetch("WebService"); var service = new WebService(serviceXml) { RequestResponse = response }; dsfWebPostActivity.OutputDescription = service.GetOutputDescription(); dsfWebPostActivity.ResponseFromWeb = response; var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); dsfWebPostActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); dsfWebPostActivity.QueryString = ""; dsfWebPostActivity.PostData = ""; dsfWebPostActivity.SourceId = Guid.Empty; dsfWebPostActivity.Headers = new List <INameValue>(); //------------Execute Test--------------------------- dsfWebPostActivity.Execute(dataObjectMock.Object, 0); //------------Assert Results------------------------- Assert.IsNotNull(dsfWebPostActivity.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))); }
public void DsfWebPostActivity_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 dsfWebPostActivity = new TestDsfWebPostActivity(); dsfWebPostActivity.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]]", "") }; dsfWebPostActivity.Inputs = serviceInputs; dsfWebPostActivity.Outputs = serviceOutputs; dsfWebPostActivity.ResponseFromWeb = response; var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); dsfWebPostActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); dsfWebPostActivity.QueryString = ""; dsfWebPostActivity.PostData = ""; dsfWebPostActivity.SourceId = Guid.Empty; dsfWebPostActivity.Headers = new List <INameValue>(); //------------Execute Test--------------------------- dsfWebPostActivity.Execute(dataObjectMock.Object, 0); //------------Assert Results------------------------- Assert.IsNull(dsfWebPostActivity.OutputDescription); }
public void DsfWebPostActivity_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 dsfWebPostActivity = new TestDsfWebPostActivity(); dsfWebPostActivity.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]]", "") }; dsfWebPostActivity.Inputs = serviceInputs; dsfWebPostActivity.Outputs = serviceOutputs; var serviceXml = XmlResource.Fetch("WebService"); var service = new WebService(serviceXml) { RequestResponse = response }; dsfWebPostActivity.OutputDescription = service.GetOutputDescription(); dsfWebPostActivity.ResponseFromWeb = response; var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); dsfWebPostActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); dsfWebPostActivity.QueryString = ""; dsfWebPostActivity.PostData = ""; dsfWebPostActivity.SourceId = Guid.Empty; dsfWebPostActivity.Headers = new List <INameValue>(); dsfWebPostActivity.OutputDescription = new OutputDescription(); dsfWebPostActivity.OutputDescription.DataSourceShapes.Add(new DataSourceShape() { Paths = new List <IPath>() { new StringPath() { ActualPath = "[[Response]]", OutputExpression = "[[Response]]" } } }); //------------Execute Test--------------------------- dsfWebPostActivity.Execute(dataObjectMock.Object, 0); //------------Assert Results------------------------- Assert.IsNotNull(dsfWebPostActivity.OutputDescription); Assert.AreEqual(response, ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[Response]]", 0))); }