public void WebPutActivity_GetDebugInputs_GivenMockEnvironment_And_IsPutDataBase64_False_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 DsfWebPutActivity = new TestWebPutActivity { Headers = new List <INameValue> { new NameValue("Header 1", "[[City]]") }, QueryString = "http://www.testing.com/[[CountryName]]", PutData = "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]]", "") }; 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); 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); DsfWebPutActivity.ResourceCatalog = cat.Object; //---------------Assert Precondition---------------- Assert.IsNotNull(environment); Assert.IsNotNull(DsfWebPutActivity); //---------------Execute Test ---------------------- var debugInputs = DsfWebPutActivity.GetDebugInputs(environment, 0); //---------------Test Result ----------------------- Assert.IsNotNull(debugInputs); Assert.AreEqual(4, debugInputs.Count); } }
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); } }
public void WebPutActivity_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 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))); } }
public void WebPutActivity_GetDebugInputs_GivenEnvironmentIsNull_ShouldReturnZeroDebugInputs() { //---------------Set up test pack------------------- var DsfWebPutActivity = new TestWebPutActivity(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var debugInputs = DsfWebPutActivity.GetDebugInputs(null, 0); //---------------Test Result ----------------------- Assert.AreEqual(0, debugInputs.Count); }
public void WebPutActivity_GetFindMissingType_GivenWebPostActivity_ShouldReturnMissingTypeDataGridAcitvity() { //---------------Set up test pack------------------- var DsfWebPutActivity = new TestWebPutActivity(); //---------------Assert Precondition---------------- Assert.IsNotNull(DsfWebPutActivity.Type); Assert.IsNotNull(DsfWebPutActivity); //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.AreEqual(enFindMissingType.DataGridActivity, DsfWebPutActivity.GetFindMissingType()); }
public void WebPutActivity_Constructer_GivenHasInstance_ShouldHaveType() { //---------------Set up test pack------------------- var DsfWebPutActivity = new TestWebPutActivity(); //---------------Assert Precondition---------------- Assert.IsNotNull(DsfWebPutActivity); //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsNotNull(DsfWebPutActivity.Type); }
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); }
public void WebPutActivity_CreateClient_GivenNoHeaders_ShouldHaveTwoHeaders() { //---------------Set up test pack------------------- var DsfWebPutActivity = new TestWebPutActivity { QueryString = "http://www.testing.com/[[CountryName]]", PutData = "This is post:[[Post]]" }; //---------------Assert Precondition---------------- Assert.IsNotNull(DsfWebPutActivity); //---------------Execute Test ---------------------- var httpClient = DsfWebPutActivity.CreateClient(null, String.Empty, TestUtils.CreateWebSourceWithCredentials()); //---------------Test Result ----------------------- var actualHeaderCount = httpClient.DefaultRequestHeaders.Count(); Assert.AreEqual(1, actualHeaderCount); }
public void WebPutActivity_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 TestWebPutActivity { OutputDescription = service.GetOutputDescription(), ResourceID = InArgument <Guid> .FromValue(Guid.Empty), QueryString = "test Query", Headers = new List <INameValue>(), ResponseFromWeb = response, HasErrorMessage = "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]); } }
public void WebPutActivity_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 TestWebPutActivity { 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(variableNameMappingTo, 0); var resultItem = (envirVariable as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult).Item; Assert.IsNotNull(envirVariable); if (resultItem.First() is DataStorage.WarewolfAtom.DataString firstItem) { Assert.AreEqual("jSon response from the request", firstItem.Item); } else { Assert.Fail("expected jSon response from the request"); } } }
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))); } }