public void ExecutionDtoExtensions_CreateResponseWriter_WasInternalService_And_ExecuteMessageXML_PayLoadIsNullOrEmpty_Success() { //-------------------------------Arrange---------------------------------- var mockDataObject = new Mock <IDSFDataObject>(); mockDataObject.Setup(o => o.Environment.HasErrors()).Returns(false); var esbExecuteRequestMessage = "<xml>test message</xml>"; var jsonSerializer = new Dev2JsonSerializer(); var serExecuteMessage = jsonSerializer.Serialize(esbExecuteRequestMessage); var executionDto = new ExecutionDto { DataObject = mockDataObject.Object, DataListFormat = DataListFormat.CreateFormat("XML", EmitionTypes.XML, "application/xml"), ErrorResultTO = new ErrorResultTO(), Request = new EsbExecuteRequest { WasInternalService = true, ExecuteResult = new StringBuilder(serExecuteMessage) }, Serializer = jsonSerializer, }; var executionDtoExtensions = new ExecutionDtoExtensions(executionDto); //-------------------------------Act-------------------------------------- executionDtoExtensions.CreateResponseWriter(new StringResponseWriterFactory()); //-------------------------------Assert----------------------------------- Assert.AreEqual(expected: "\"<xml>test message</xml>\"", actual: executionDto.PayLoad); }
public void ExecutionDtoExtensions_CreateResponseWriter_NotWasInternalService_And_EmitionTypesXML_Success() { //-------------------------------Arrange---------------------------------- var mockDataObject = new Mock <IDSFDataObject>(); var mockResource = new Mock <IWarewolfResource>(); mockResource.Setup(o => o.DataList).Returns(new StringBuilder("<DataList>the test string to be built</DataList>")); mockDataObject.Setup(o => o.Environment.HasErrors()).Returns(false); mockDataObject.Setup(o => o.ReturnType).Returns(EmitionTypes.XML); var dataListDataFormat = DataListFormat.CreateFormat("XML", EmitionTypes.XML, "application/xml"); var executionDto = new ExecutionDto { Resource = mockResource.Object, DataObject = mockDataObject.Object, ErrorResultTO = new ErrorResultTO(), DataListFormat = dataListDataFormat, }; var executionDtoExtensions = new ExecutionDtoExtensions(executionDto); //-------------------------------Act-------------------------------------- executionDtoExtensions.CreateResponseWriter(new StringResponseWriterFactory()); //-------------------------------Assert----------------------------------- Assert.AreEqual(expected: "<DataList />", actual: executionDto.PayLoad); }
string GetExecutePayload(IDSFDataObject dataObject, IWarewolfResource resource, WebRequestTO webRequest, ref DataListFormat formatter) { var notDebug = !dataObject.IsDebug || dataObject.RemoteInvoke || dataObject.RemoteNonDebugInvoke; if (notDebug && resource?.DataList != null) { switch (dataObject.ReturnType) { case EmitionTypes.XML: { return(ExecutionEnvironmentUtils.GetXmlOutputFromEnvironment(dataObject, resource.DataList.ToString(), 0)); } case EmitionTypes.SWAGGER: { formatter = DataListFormat.CreateFormat("SWAGGER", EmitionTypes.SWAGGER, "application/json"); return(ExecutionEnvironmentUtils.GetSwaggerOutputForService(resource, resource.DataList.ToString(), webRequest.WebServerUrl)); } default: case EmitionTypes.JSON: { formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); return(ExecutionEnvironmentUtils.GetJsonOutputFromEnvironment(dataObject, resource.DataList.ToString(), 0)); } } } return(string.Empty); }
public void ExecutionDtoExtensions_CreateResponseWriter_NotWasInternalService_And_IsDebug_Success() { //-------------------------------Arrange---------------------------------- var mockDataObject = new Mock <IDSFDataObject>(); mockDataObject.Setup(o => o.Environment.HasErrors()).Returns(false); mockDataObject.Setup(o => o.IsDebug).Returns(true); var dataListDataFormat = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); var executionDto = new ExecutionDto { Resource = null, DataObject = mockDataObject.Object, ErrorResultTO = new ErrorResultTO(), DataListFormat = dataListDataFormat, }; var executionDtoExtensions = new ExecutionDtoExtensions(executionDto); //-------------------------------Act-------------------------------------- executionDtoExtensions.CreateResponseWriter(new StringResponseWriterFactory()); //-------------------------------Assert----------------------------------- Assert.AreEqual(expected: string.Empty, actual: executionDto.PayLoad); }
static WebServiceContainer CreateWebServiceContainer(XElement serviceXml, XElement sourceXml, string response, bool isFaulty = false) { ErrorResultTO errors; var compiler = DataListFactory.CreateDataListCompiler(); var dataListId = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), "".ToStringBuilder(), "<DataList></DataList>".ToStringBuilder(), out errors); var dataObj = new Mock <IDSFDataObject>(); dataObj.Setup(d => d.DataListID).Returns(dataListId); var workspace = new Mock <IWorkspace>(); var esbChannel = new Mock <IEsbChannel>(); var sa = CreateServiceAction(serviceXml, sourceXml); WebServiceContainer container; if (!isFaulty) { container = new WebServiceContainerMock(sa, dataObj.Object, workspace.Object, esbChannel.Object) { WebRequestRespsonse = response }; } else { container = new FaultyWebServiceContainerMock(sa, dataObj.Object, workspace.Object, esbChannel.Object) { WebRequestRespsonse = string.Empty }; } return(container); }
public void WebServiceContainerExecuteWithValidServiceHavingInputsExpectedExecutesService() { var container = CreateWebServiceContainer(WebServiceWithInputsXml, WebSourceWithInputsXml, WebServiceWithInputsResponseXml.ToString()); ErrorResultTO errors; var dataListID = container.Execute(out errors); var compiler = DataListFactory.CreateDataListCompiler(); var result = compiler.ConvertFrom(dataListID, DataListFormat.CreateFormat(GlobalConstants._XML), enTranslationDepth.Data, out errors); Assert.IsNotNull(result); var resultXml = XElement.Parse(result.ToString()); var expectedRoot = (XElement)WebServiceWithInputsResponseXml.FirstNode; foreach (var actualNode in resultXml.Elements()) { var actualName = actualNode.Name.LocalName; if (!actualName.StartsWith("Dev2System")) { var expectedNode = expectedRoot.Element(actualName); if (expectedNode != null) { Assert.AreEqual(expectedNode.Value, actualNode.Value); } } } }
public void ExecutionDtoExtensions_CreateResponseWriter_NotWasInternalService_And_EmitionTypesSWAGGER_Success() { //-------------------------------Arrange---------------------------------- var mockDataObject = new Mock <IDSFDataObject>(); var mockResource = new Mock <IWarewolfResource>(); mockResource.Setup(o => o.DataList).Returns(new StringBuilder("<DataList>the test string to be built</DataList>")); mockDataObject.Setup(o => o.Environment.HasErrors()).Returns(false); mockDataObject.Setup(o => o.ReturnType).Returns(EmitionTypes.SWAGGER); var dataListDataFormat = DataListFormat.CreateFormat("SWAGGER", EmitionTypes.SWAGGER, "application/json"); var webRequestTO = new WebRequestTO { WebServerUrl = "http://serverName:3142/public/resourceName.api" }; var executionDto = new ExecutionDto { Resource = mockResource.Object, DataObject = mockDataObject.Object, ErrorResultTO = new ErrorResultTO(), DataListFormat = dataListDataFormat, WebRequestTO = webRequestTO, }; var executionDtoExtensions = new ExecutionDtoExtensions(executionDto); //-------------------------------Act-------------------------------------- executionDtoExtensions.CreateResponseWriter(new StringResponseWriterFactory()); //-------------------------------Assert----------------------------------- Assert.AreEqual(expected: "{\r\n \"swagger\": 2,\r\n \"info\": {\r\n \"title\": null,\r\n \"description\": \"\",\r\n \"version\": \"1.0.0\"\r\n },\r\n \"host\": \":0/\",\r\n \"basePath\": \"/\",\r\n \"schemes\": [\r\n \"http\"\r\n ],\r\n \"produces\": [\r\n \"application/json\",\r\n \"application/xml\"\r\n ],\r\n \"paths\": {\r\n \"serviceName\": \"/public/resourceName.api\",\r\n \"get\": {\r\n \"summary\": \"\",\r\n \"description\": \"\",\r\n \"parameters\": []\r\n }\r\n },\r\n \"responses\": {\r\n \"200\": {\r\n \"schema\": {\r\n \"$ref\": \"#/definition/Output\"\r\n }\r\n }\r\n },\r\n \"definitions\": {\r\n \"Output\": {\r\n \"type\": \"object\",\r\n \"properties\": {}\r\n }\r\n }\r\n}", actual: executionDto.PayLoad); }
private static IResponseWriter DebugFromWebExecutionResponse(IDSFDataObject dataObject, Dev2JsonSerializer serializer) { var formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); var serialize = SetupForWebExecution(dataObject, serializer); return(new StringResponseWriter(serialize, formatter.ContentType)); }
WebServiceContainer CreateWebServiceContainerThrowingException(string response) { ErrorResultTO errors; var compiler = DataListFactory.CreateDataListCompiler(); var dataListId = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), "", "<DataList></DataList>".ToStringBuilder(), out errors); var dataObj = new Mock <IDSFDataObject>(); dataObj.Setup(d => d.DataListID).Returns(dataListId); var serviceExecution = new WebserviceExecution(dataObj.Object, true); var webService = new WebService { Method = new ServiceMethod() }; var outputDescription = new OutputDescription { Format = OutputFormats.ShapedXML }; webService.OutputDescription = outputDescription; serviceExecution.Service = webService; var container = new WebServiceContainerMockWithError(serviceExecution) { WebRequestRespsonse = response, }; return(container); }
public static DataListFormat RunCoverageAndReturnHTML(this ICoverageDataObject coverageData, ITestCoverageCatalog testCoverageCatalog, ITestCatalog testCatalog, IResourceCatalog catalog, Guid workspaceGuid, out string executePayload) { var warewolfWorkflowReports = RunListOfCoverage(coverageData, testCoverageCatalog, testCatalog, workspaceGuid, catalog); var allTestResults = warewolfWorkflowReports.AllTestResults; var allCoverageReports = warewolfWorkflowReports.AllCoverageReports; var formatter = DataListFormat.CreateFormat("HTML", EmitionTypes.Cover, "text/html; charset=utf-8"); var stringWriter = new StringWriter(); using (var writer = new HtmlTextWriter(stringWriter)) { var testResults = warewolfWorkflowReports.AllTestResults; writer.SetupNavBarHtml(warewolfWorkflowReports.TotalWorkflowNodesCoveredPercentage); writer.SetupCountSummaryHtml(testResults, coverageData); writer.SetupLinesCountSummaryHtml(warewolfWorkflowReports); allCoverageReports .ToList() .ForEach(oo => { var resourcePath = string.Empty; if (oo.Resource is IFilePathResource filePath) { resourcePath = filePath.Path; } writer.SetupWorkflowRowHtml(resourcePath, coverageData, oo); }); } executePayload = stringWriter.ToString(); return(formatter); }
public override IBinaryDataList GetOutputs() { IBinaryDataList result; ErrorResultTO errors; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); var outputDlString = compiler.GenerateWizardDataListFromDefs(OutputMapping, enDev2ArgumentType.Output, false, out errors, true); var outputDlShape = compiler.GenerateWizardDataListFromDefs(OutputMapping, enDev2ArgumentType.Output, false, out errors); if (!errors.HasErrors()) { Guid dlId = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), outputDlString, outputDlShape, out errors); if (!errors.HasErrors()) { result = compiler.FetchBinaryDataList(dlId, out errors); } else { string errorString = string.Join(",", errors.FetchErrors()); throw new Exception(errorString); } } else { string errorString = string.Join(",", errors.FetchErrors()); throw new Exception(errorString); } return(result); }
public static DataListFormat RunSingleTestBatchAndReturnTRX(this IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, DataListFormat formatter, string serviceName, ITestCatalog testCatalog, ref string executePayload) { var testResults = RunAllTestsForWorkflow(dataObject, serviceName, userPrinciple, workspaceGuid, serializer, testCatalog); formatter = DataListFormat.CreateFormat("XML", EmitionTypes.XML, "text/xml"); executePayload = ServiceTestModelTRXResultBuilder.BuildTestResultTRX(serviceName, testResults); return(formatter); }
static string ExtractKeyValuePairs(NameValueCollection pairs) { IBinaryDataList bdl = Dev2BinaryDataListFactory.CreateDataList(); // Extract request keys ;) foreach (var key in pairs.AllKeys) { if (key == "wid") //Don't add the Workspace ID to DataList { continue; } if (key.IsXml()) { return(key); //We have a workspace id and XML DataList } string error; bdl.TryCreateScalarTemplate(string.Empty, key, string.Empty, true, out error); if (!string.IsNullOrEmpty(error)) { Dev2Logger.Log.Error(error); } IBinaryDataListEntry entry; if (bdl.TryGetEntry(key, out entry, out error)) { var item = Dev2BinaryDataListFactory.CreateBinaryItem(pairs[key], key); entry.TryPutScalar(item, out error); if (!string.IsNullOrEmpty(error)) { Dev2Logger.Log.Error(error); } } else { Dev2Logger.Log.Error(error); } } IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; Guid pushedId = compiler.PushBinaryDataList(bdl.UID, bdl, out errors); if (pushedId != Guid.Empty) { var result = compiler.ConvertFrom(pushedId, DataListFormat.CreateFormat(GlobalConstants._XML), enTranslationDepth.Data, out errors); if (errors.HasErrors()) { Dev2Logger.Log.Error(errors.MakeDisplayReady()); } return(result.ToString()); } Dev2Logger.Log.Error(errors.MakeDisplayReady()); return(string.Empty); }
public string GetXMLForInputs(IBinaryDataList binaryDataList) { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; return (compiler.ConvertFrom(binaryDataList.UID, DataListFormat.CreateFormat(GlobalConstants._XML_Inputs_Only), enTranslationDepth.Data, out errors).ToString()); }
/// <summary> /// Shapes for sub request. Returns a key valid pair with remaining output mappings to be processed later! /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="inputDefs">The input defs.</param> /// <param name="outputDefs">The output defs.</param> /// <param name="errors">The errors.</param> public IList <KeyValuePair <enDev2ArgumentType, IList <IDev2Definition> > > ShapeForSubRequest(IDSFDataObject dataObject, string inputDefs, string outputDefs, out ErrorResultTO errors) { // We need to make it based upon the request ;) var oldID = dataObject.DataListID; var compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO invokeErrors; errors = new ErrorResultTO(); StringBuilder theShape; if (IsServiceWorkflow(dataObject.WorkspaceID, dataObject.ResourceID)) { theShape = FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID); } else { var isDbService = dataObject.RemoteServiceType == "DbService" || dataObject.RemoteServiceType == "InvokeStoredProc"; theShape = ShapeMappingsToTargetDataList(inputDefs, outputDefs, out invokeErrors, isDbService); errors.MergeErrors(invokeErrors); } var shapeID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), new StringBuilder(), theShape, out invokeErrors); errors.MergeErrors(invokeErrors); dataObject.RawPayload = new StringBuilder(); IList <KeyValuePair <enDev2ArgumentType, IList <IDev2Definition> > > remainingMappings = null; if (!dataObject.IsDataListScoped) { // Now ID flow through mappings ;) remainingMappings = compiler.ShapeForSubExecution(oldID, shapeID, inputDefs, outputDefs, out invokeErrors); errors.MergeErrors(invokeErrors); } else { // we have a scoped datalist ;) compiler.SetParentID(shapeID, oldID); var inputID = compiler.Shape(oldID, enDev2ArgumentType.Input, inputDefs, out invokeErrors, oldID); errors.MergeErrors(invokeErrors); var outputID = compiler.Merge(oldID, shapeID, enDataListMergeTypes.Union, enTranslationDepth.Shape, false, out invokeErrors); errors.MergeErrors(invokeErrors); shapeID = compiler.Merge(outputID, inputID, enDataListMergeTypes.Union, enTranslationDepth.Shape, false, out invokeErrors); errors.MergeErrors(invokeErrors); } // set execution ID ;) dataObject.DataListID = shapeID; return(remainingMappings); }
/// <summary> /// Creates the XML data from binary data list. /// </summary> /// <param name="binaryDataList">The binary data list.</param> /// <param name="errors">The errors.</param> /// <returns></returns> private string CreateXmlDataFromBinaryDataList(IBinaryDataList binaryDataList, out ErrorResultTO errors) { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid dlGuid = compiler.PushBinaryDataList(binaryDataList.UID, binaryDataList, out errors); string result = compiler.ConvertFrom(dlGuid, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors).ToString(); return(result); }
public override Guid Execute(out ErrorResultTO errors) { Dev2Logger.Log.Info(String.Format("Started Remote Execution. Service Name:{0} Resource Id:{1} Mode:{2}", DataObject.ServiceName, DataObject.ResourceID, DataObject.IsDebug ? "Debug" : "Execute")); var dataListCompiler = DataListFactory.CreateDataListCompiler(); var serviceName = DataObject.ServiceName; errors = new ErrorResultTO(); ErrorResultTO invokeErrors; // get data in a format we can send ;) var dataListFragment = dataListCompiler.ConvertFrom(DataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), enTranslationDepth.Data, out invokeErrors); errors.MergeErrors(invokeErrors); string result = string.Empty; var connection = GetConnection(DataObject.EnvironmentID); if (connection == null) { errors.AddError("Server source not found."); return(DataObject.DataListID); } try { // Invoke Remote WF Here ;) result = ExecuteGetRequest(connection, serviceName, dataListFragment.ToString()); IList <IDebugState> msg = FetchRemoteDebugItems(connection); DataObject.RemoteDebugItems = msg; // set them so they can be acted upon } catch (Exception e) { errors.AddError(e.Message.Contains("Forbidden") ? "Executing a service requires Execute permissions" : e.Message); Dev2Logger.Log.Error(e); } // Create tmpDL var tmpId = dataListCompiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), result.ToStringBuilder(), DataObject.RemoteInvokeResultShape, out invokeErrors); errors.MergeErrors(invokeErrors); // Merge Result into Local DL ;) Guid mergeOp = dataListCompiler.Merge(DataObject.DataListID, tmpId, enDataListMergeTypes.Union, enTranslationDepth.Data, false, out invokeErrors); errors.MergeErrors(invokeErrors); if (mergeOp == DataObject.DataListID) { return(mergeOp); } Dev2Logger.Log.Info(String.Format("Completed Remote Execution. Service Name:{0} Resource Id:{1} Mode:{2}", DataObject.ServiceName, DataObject.ResourceID, DataObject.IsDebug ? "Debug" : "Execute")); return(Guid.Empty); }
public static void MyClassInitialize(TestContext testContext) { // boot strap the server DataListTranslatorFactory dltf = new DataListTranslatorFactory(); Dls.AddTranslator(dltf.FetchTranslator(DataListFormat.CreateFormat(GlobalConstants._BINARY))); Dls.AddTranslator(dltf.FetchTranslator(DataListFormat.CreateFormat(GlobalConstants._XML))); Dls.AddTranslator(dltf.FetchTranslator(DataListFormat.CreateFormat(GlobalConstants._JSON))); Dls.AddTranslator(dltf.FetchTranslator(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags))); Dls.AddTranslator(dltf.FetchTranslator(DataListFormat.CreateFormat(GlobalConstants._XML_Inputs_Only))); }
/// <summary> /// Creates the XML data from binary data list. /// </summary> /// <param name="binaryDataList">The binary data list.</param> /// <param name="errors">The errors.</param> /// <returns></returns> private string CreateXmlDataFromBinaryDataList(IBinaryDataList binaryDataList, out ErrorResultTO errors) { string result = string.Empty; ErrorResultTO allErrors = new ErrorResultTO(); errors = new ErrorResultTO(); Guid dlGuid = _compiler.PushBinaryDataList(binaryDataList.UID, binaryDataList, out errors); result = _compiler.ConvertFrom(dlGuid, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors); return(result); }
public static DataListFormat RunMultipleTestBatchesAndReturnTRX(this IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, IResourceCatalog catalog, ITestCatalog testCatalog, out string executePayload, ITestCoverageCatalog testCoverageCatalog) { var testResults = RunListOfTests(dataObject, userPrinciple, workspaceGuid, serializer, catalog, testCatalog, testCoverageCatalog); var formatter = DataListFormat.CreateFormat("XML", EmitionTypes.XML, "text/xml"); executePayload = ServiceTestModelTRXResultBuilder.BuildTestResultTRX(dataObject.ServiceName, testResults.Results.SelectMany(o => o.Results).ToList()); return(formatter); }
public void CanConvertFromWithSingleScalarDataListXMLTranslatorWithOutSystemTags() { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; Guid dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), new StringBuilder("<root><scalar>s1</scalar></root>"), new StringBuilder("<root><scalar/></root>"), out errors); var data = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), enTranslationDepth.Data, out errors); const string Expected = "<DataList><scalar>s1</scalar></DataList>"; Assert.AreEqual(Expected, data.ToString(), "Expected [ " + Expected + " ] but got [ " + data + " ]"); }
public void CanConvertFromDataListToJsonMultipleScalarsMultipleRecordsets() { var compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; var dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), new StringBuilder("<root><scalar>s1</scalar><otherScalar>s2</otherScalar><rs><val>1</val><otherVal>ABC</otherVal></rs><rs><val>2</val><otherVal>ZZZ</otherVal></rs><otherRS><val>1</val><myVal>ABC</myVal></otherRS><otherRS><val>90</val><myVal>123</myVal></otherRS></root>"), new StringBuilder("<root><scalar/><otherScalar/><rs><val/><otherVal/></rs><otherRS><val/><myVal/></otherRS></root>"), out errors); var data = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._JSON), enTranslationDepth.Data, out errors); const string expected = "{\"scalar\":\"s1\",\"otherScalar\":\"s2\",\"rs\" : [{\"val\":\"1\",\"otherVal\":\"ABC\"}, {\"val\":\"2\",\"otherVal\":\"ZZZ\"}],\"otherRS\" : [{\"val\":\"1\",\"myVal\":\"ABC\"}, {\"val\":\"90\",\"myVal\":\"123\"}]}"; Assert.AreEqual(expected, data.ToString(), "Expected [ " + expected + " ] but got [ " + data + " ]"); }
public static DataListFormat RunSingleTestBatchAndReturnJSON(this IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, DataListFormat formatter, string serviceName, ITestCatalog testCatalog, ref string executePayload) { var testResults = RunAllTestsForWorkflow(dataObject, serviceName, userPrinciple, workspaceGuid, serializer, testCatalog); formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); var objArray = (from testRunResult in testResults where testRunResult != null select testRunResult.BuildTestResultJSONForWebRequest() ).ToList(); executePayload = serializer.Serialize(objArray); return(formatter); }
private IResponseWriter ServiceTestExecutionResponse(out string executePayload, IDSFDataObject dataObject, Dev2JsonSerializer serializer, bool canExecute) { var formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); if (!canExecute) { executePayload = string.Empty; return(new StringResponseWriter(dataObject.Environment.FetchErrors(), formatter.ContentType)); } executePayload = ServiceTestExecutor.SetupForTestExecution(serializer, _esbExecuteRequest, dataObject); return(new StringResponseWriter(executePayload, formatter.ContentType)); }
public void Can_Create_XML_With_ColumnIODirection_Both() { Guid tmp = CreateDataList(enDev2ColumnArgumentDirection.Both); ErrorResultTO errors; var result = _compiler.ConvertFrom(tmp, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors); const string expected = @"<DataList><recset Description="""" IsEditable=""True"" ColumnIODirection=""Both"" ><f1 Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /><f2 Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /><f3 Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /><f4 Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /><f5 Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /></recset><myScalar Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /></DataList>"; _compiler.ForceDeleteDataListByID(tmp); Assert.AreEqual(expected, result.ToString()); }
static void TryGetFormatter(string executePayload, ref DataListFormat formatter) { if (executePayload.IsJSON()) { formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); } else { if (executePayload.IsXml()) { formatter = DataListFormat.CreateFormat("XML", EmitionTypes.XML, "text/xml"); } } }
public T FetchServerModel <T>(IDSFDataObject dataObject, Guid workspaceId, out ErrorResultTO errors) { var serviceID = dataObject.ResourceID; var theWorkspace = WorkspaceRepository.Instance.Get(workspaceId); var invoker = new EsbServiceInvoker(this, this, theWorkspace); var generateInvokeContainer = invoker.GenerateInvokeContainer(dataObject, serviceID, true); var curDlid = generateInvokeContainer.Execute(out errors); var compiler = DataListFactory.CreateDataListCompiler(); var convertFrom = compiler.ConvertFrom(curDlid, DataListFormat.CreateFormat(GlobalConstants._XML), enTranslationDepth.Data, out errors); var jsonSerializerSettings = new JsonSerializerSettings(); var deserializeObject = JsonConvert.DeserializeObject <T>(convertFrom.ToString(), jsonSerializerSettings); return(deserializeObject); }
void TryGetFormatter(ref DataListFormat formatter) { if (_executionDto.PayLoad.IsJSON()) { formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); } else { if (_executionDto.PayLoad.IsXml()) { formatter = DataListFormat.CreateFormat("XML", EmitionTypes.XML, "text/xml"); } } }
public void CanConvertFromDataListToJsonSingleScalarSingleRecordsetColumn() { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; Guid dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), new StringBuilder("<root><scalar>s1</scalar><rs><val>1</val></rs><rs><val>2</val></rs></root>"), new StringBuilder("<root><scalar/><rs><val/></rs></root>"), out errors); var data = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._JSON), enTranslationDepth.Data, out errors); var result = JsonConvert.DeserializeObject <TestClassRsWithScalar>(data.ToString()); Assert.AreEqual("s1", result.scalar); Assert.AreEqual("1", result.rs[0].val); Assert.AreEqual("2", result.rs[1].val); }
public void DataListXMLTranslatorWithOutSystemTags_ConvertAndOnlyMapInputs_WhenMappingRecordsetsAndScalarsMarkedAsBoth_ExpectInputsMapped() { //------------Setup for test-------------------------- var compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; var dataList = new StringBuilder(@"<DataList> <result Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /> <rs Description="""" IsEditable=""True"" ColumnIODirection=""Both"" > <val1 Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /> <val2 Description="""" IsEditable=""True"" ColumnIODirection=""Both"" /> </rs> </DataList>"); var payload = new StringBuilder("<DataList><rs><val1>1</val1><val2>2</val2></rs><rs><val1>3</val1><val2>4</val2></rs><result>99</result></DataList>"); //------------Execute Test--------------------------- var result = compiler.ConvertAndOnlyMapInputs(DataListFormat.CreateFormat(GlobalConstants._XML), payload, dataList, out errors); var dl = compiler.FetchBinaryDataList(result, out errors); var rsEntries = dl.FetchRecordsetEntries(); // Examine for correct data ;) string error; var rsEntry = rsEntries[0].FetchRecordAt(1, out error); // row 1 validation Assert.AreEqual(2, rsEntry.Count); Assert.AreEqual("val1", rsEntry[0].FieldName); Assert.AreEqual("1", rsEntry[0].TheValue); Assert.AreEqual("val2", rsEntry[1].FieldName); Assert.AreEqual("2", rsEntry[1].TheValue); // row 2 validation rsEntry = rsEntries[0].FetchRecordAt(2, out error); Assert.AreEqual(2, rsEntry.Count); Assert.AreEqual("val1", rsEntry[0].FieldName); Assert.AreEqual("3", rsEntry[0].TheValue); Assert.AreEqual("val2", rsEntry[1].FieldName); Assert.AreEqual("4", rsEntry[1].TheValue); // check scalar value var scalarEntries = dl.FetchScalarEntries(); var scalar = scalarEntries[0].FetchScalar(); Assert.AreEqual("99", scalar.TheValue); Assert.AreEqual("result", scalar.FieldName); }