public void WebPostActivity_GetDebugInputs_GivenMockEnvironment_ShouldAddDebugInputItems() { //---------------Set up test pack------------------- 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 webPostActivity = new TestWebPostActivity { Headers = new List <INameValue> { new NameValue("Header 1", "[[City]]") }, QueryString = "http://www.testing.com/[[CountryName]]", PostData = "This is post:[[Post]]" }; 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]]", "") }; webPostActivity.Outputs = serviceOutputs; var serviceXml = XmlResource.Fetch("WebService"); var service = new WebService(serviceXml) { RequestResponse = response }; webPostActivity.OutputDescription = service.GetOutputDescription(); webPostActivity.ResponseFromWeb = response; var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); webPostActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); var cat = new Mock <IResourceCatalog>(); var src = new WebSource { Address = "www.example.com" }; cat.Setup(a => a.GetResource <WebSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(src); webPostActivity.ResourceCatalog = cat.Object; //---------------Assert Precondition---------------- Assert.IsNotNull(environment); Assert.IsNotNull(webPostActivity); //---------------Execute Test ---------------------- var debugInputs = webPostActivity.GetDebugInputs(environment, 0); //---------------Test Result ----------------------- Assert.IsNotNull(debugInputs); Assert.AreEqual(4, debugInputs.Count); }
public void WebPostActivity_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 webPostActivity = new TestWebPostActivity(); webPostActivity.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]]", "") }; webPostActivity.Inputs = serviceInputs; webPostActivity.Outputs = serviceOutputs; var serviceXml = XmlResource.Fetch("WebService"); var service = new WebService(serviceXml) { RequestResponse = response }; webPostActivity.OutputDescription = service.GetOutputDescription(); webPostActivity.ResponseFromWeb = response; var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); webPostActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); webPostActivity.QueryString = ""; webPostActivity.PostData = ""; webPostActivity.SourceId = Guid.Empty; webPostActivity.Headers = new List <INameValue>(); webPostActivity.OutputDescription = new OutputDescription(); webPostActivity.OutputDescription.DataSourceShapes.Add(new DataSourceShape() { Paths = new List <IPath>() { new StringPath() { ActualPath = "[[Response]]", OutputExpression = "[[Response]]" } } }); //------------Execute Test--------------------------- webPostActivity.Execute(dataObjectMock.Object, 0); //------------Assert Results------------------------- Assert.IsNotNull(webPostActivity.OutputDescription); Assert.AreEqual(response, ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[Response]]", 0))); }
public void WebPostActivity_Execute_WithInValidWebResponse_ShouldError() { //------------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\"" + "}"; const string invalidResponse = "{\"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 webPostActivity = new TestWebPostActivity { 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]]", "") }; webPostActivity.Inputs = serviceInputs; webPostActivity.Outputs = serviceOutputs; var serviceXml = XmlResource.Fetch("WebService"); var service = new WebService(serviceXml) { RequestResponse = response }; webPostActivity.OutputDescription = service.GetOutputDescription(); webPostActivity.ResponseFromWeb = invalidResponse; var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); webPostActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); webPostActivity.QueryString = ""; webPostActivity.PostData = ""; webPostActivity.SourceId = Guid.Empty; webPostActivity.Headers = new List <INameValue>(); //------------Execute Test--------------------------- webPostActivity.Execute(dataObjectMock.Object, 0); //------------Assert Results------------------------- Assert.IsNotNull(webPostActivity.OutputDescription); Assert.AreEqual(1, environment.Errors.Count); StringAssert.Contains(environment.Errors.ToList()[0], "Invalid character after parsing property name"); }
static DataStorage.WarewolfEnvironment CreateEnvironmentWithData() { var env = new ExecutionEnvironment(); env.Assign("[[Rec(1).a]]", "1", 0); env.Assign("[[Rec(2).a]]", "2", 0); env.Assign("[[Rec(3).a]]", "3", 0); env.Assign("[[Rec(4).a]]", "2", 0); env.Assign("[[Rec(1).b]]", "a", 0); env.Assign("[[Rec(2).b]]", "b", 0); env.Assign("[[Rec(3).b]]", "c", 0); env.Assign("[[Rec(4).b]]", "c", 0); env.Assign("[[x]]", "1", 0); env.Assign("[[y]]", "y", 0); env.Assign("[[z]]", "*", 0); env.AssignJson(new AssignValue("[[@Person.Name]]", "bob"), 0); env.AssignJson(new AssignValue("[[@Person.Age]]", "22"), 0); env.AssignJson(new AssignValue("[[@Person.Spouse.Name]]", "dora"), 0); env.AssignJson(new AssignValue("[[@Person.Children(1).Name]]", "Mary"), 0); env.AssignJson(new AssignValue("[[@Person.Children(2).Name]]", "Jane"), 0); env.AssignJson(new AssignValue("[[@Person.Score(1)]]", "2"), 0); env.AssignJson(new AssignValue("[[@Person.Score(2)]]", "3"), 0); env.AssignJson(new AssignValue("[[array(1)]]", "bob"), 0); env.AssignJson(new AssignValue("[[arrayObj(1).Name]]", "bob"), 0); env.AssignJson(new AssignValue("[[arrayObj(2).Name]]", "bobe"), 0); var p = new PrivateObject(env); return((DataStorage.WarewolfEnvironment)p.GetFieldOrProperty("_env")); }
public void DsfWebDeleteActivity_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 dsfWebDeleteActivity = CreateTestDeleteActivity(); 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]]", "") }; dsfWebDeleteActivity.Inputs = serviceInputs; dsfWebDeleteActivity.Outputs = serviceOutputs; var serviceXml = XmlResource.Fetch("WebService"); var service = new WebService(serviceXml) { RequestResponse = response }; dsfWebDeleteActivity.OutputDescription = service.GetOutputDescription(); dsfWebDeleteActivity.ResponseFromWeb = response; var dataObjectMock = new Mock <IDSFDataObject>(); dataObjectMock.Setup(o => o.Environment).Returns(environment); dataObjectMock.Setup(o => o.EsbChannel).Returns(new Mock <IEsbChannel>().Object); dsfWebDeleteActivity.ResourceID = InArgument <Guid> .FromValue(Guid.Empty); dsfWebDeleteActivity.QueryString = ""; //dsfWebPostActivity.PostData = ""; dsfWebDeleteActivity.SourceId = Guid.Empty; dsfWebDeleteActivity.Headers = new List <INameValue>(); //------------Execute Test--------------------------- dsfWebDeleteActivity.Execute(dataObjectMock.Object, 0); //------------Assert Results------------------------- Assert.IsNotNull(dsfWebDeleteActivity.OutputDescription); var visibility = ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[Visibility]]", 0)); Assert.AreEqual("<greater than 7 mile(s):0>", visibility); var location = ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[weather().Location]]", 0)); Assert.AreEqual("<Paris>", location); var time = ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[weather().Time]]", 0)); Assert.AreEqual("May 29, 2013 - 09:00 AM EDT / 2013.05.29 1300 UTC", time); var wind = ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval("[[weather().Wind]]", 0)); Assert.AreEqual("from the NW (320 degrees) at 10 MPH (9 KT) (direction variable):0", wind); }
public void GivenRecSetName_ExecutionEnvironmentGetCount_ShouldReturn1() { Assert.IsNotNull(_environment); _environment.Assign("[[rec().a]]", "sanele", 0); var recordSet = _environment.GetCount("rec"); Assert.AreEqual(1, recordSet); }
public void DsfActivity_GetState() { //------------Setup for test-------------------------- var remoteResourceID = Guid.Empty; var environmentID = Guid.Empty; var env = new ExecutionEnvironment(); env.Assign("[[list().Name]]", "bob", 0); //------------Execute Test--------------------------- var Inputs = new List <IServiceInput> { new ServiceInput("Input1", "[[list(*).Name]]") }; var Outputs = new List <IServiceOutputMapping> { new ServiceOutputMapping("bob", "[[out]]", "list") }; var serializer = new Dev2JsonSerializer(); var inputs = serializer.Serialize(Inputs); var outputs = serializer.Serialize(Outputs); var remoteServerId = Guid.NewGuid(); var ServiceServer = remoteServerId; var EnvironmentID = remoteServerId; var ServiceUri = "remoteEnvironment.Connection.AppServerUri"; var ServiceName = "remote category"; var ResourceID = remoteResourceID; var ParentServiceName = "ParentServiceName"; var act = new DsfWorkflowActivity { ObjectName = "objectname", IsObject = true, Inputs = Inputs, Outputs = Outputs, IsWorkflow = false, ResourceID = new InArgument <Guid>(ResourceID), ServiceName = ServiceName, ServiceUri = ServiceUri, EnvironmentID = EnvironmentID, ServiceServer = ServiceServer, ParentServiceName = ParentServiceName }; //------------Execute Test--------------------------- var stateItems = act.GetState(); Assert.AreEqual(9, stateItems.Count()); var expectedResults = new[] { new StateVariable { Name = "Inputs", Type = StateVariable.StateType.Input, Value = inputs }, new StateVariable { Name = "Outputs", Type = StateVariable.StateType.Output, Value = outputs }, new StateVariable { Name = "ServiceServer", Type = StateVariable.StateType.Input, Value = ServiceServer.ToString() }, new StateVariable { Name = "EnvironmentID", Type = StateVariable.StateType.Input, Value = EnvironmentID.ToString() }, new StateVariable { Name = "IsWorkflow", Type = StateVariable.StateType.Input, Value = "False" }, new StateVariable { Name = "ServiceUri", Type = StateVariable.StateType.Input, Value = ServiceUri }, new StateVariable { Name = "ResourceID", Type = StateVariable.StateType.Input, Value = ResourceID.ToString() }, new StateVariable { Name = "ServiceName", Type = StateVariable.StateType.Input, Value = ServiceName }, new StateVariable { Name = "ParentServiceName", Type = StateVariable.StateType.Input, Value = ParentServiceName } }; var iter = act.GetState().Select( (item, index) => new { value = item, expectValue = expectedResults[index] } ); //------------Assert Results------------------------- foreach (var entry in iter) { Assert.AreEqual(entry.expectValue.Name, entry.value.Name); Assert.AreEqual(entry.expectValue.Type, entry.value.Type); Assert.AreEqual(entry.expectValue.Value, entry.value.Value); } }
public static DataStorage.WarewolfEnvironment CreateEnvironmentWithData() { var env = new ExecutionEnvironment(); env.Assign("[[Rec(1).a]]", "1", 0); env.Assign("[[Rec(2).a]]", "2", 0); env.Assign("[[Rec(3).a]]", "3", 0); env.Assign("[[non(3).a]]", "1", 0); env.Assign("[[non(2).a]]", "2", 0); env.Assign("[[non(1).a]]", "3", 0); env.Assign("[[Rec(1).b]]", "a", 0); env.Assign("[[Rec(2).b]]", "b", 0); env.Assign("[[Rec(3).b]]", "c", 0); env.Assign("[[escapeValue]]", "some test with a tab character\tin it", 0); env.Assign("[[esc(1).val]]", "some\tstring", 0); env.Assign("[[esc(2).val]]", "another\tstring", 0); env.Assign("[[x]]", "1", 0); env.Assign("[[y]]", "y", 0); env.AssignJson(new AssignValue("[[@Person.Name]]", "bob"), 0); env.AssignJson(new AssignValue("[[@Person.Age]]", "22"), 0); env.AssignJson(new AssignValue("[[@Person.Spouse.Name]]", "dora"), 0); env.AssignJson(new AssignValue("[[@Person.Children(1).Name]]", "Mary"), 0); env.AssignJson(new AssignValue("[[@Person.Children(2).Name]]", "Jane"), 0); env.AssignJson(new AssignValue("[[@Person.Score(1)]]", "2"), 0); env.AssignJson(new AssignValue("[[@Person.Score(2)]]", "3"), 0); env.AssignJson(new AssignValue("[[@array(1)]]", "bob"), 0); env.AssignJson(new AssignValue("[[@arrayObj(1).Name]]", "bob"), 0); env.AssignJson(new AssignValue("[[@arrayObj(2).Name]]", "bobe"), 0); var p = new Warewolf.Testing.PrivateObject(env); return((DataStorage.WarewolfEnvironment)p.GetFieldOrProperty("_env")); }