public void NewRecordExpectedAddANewRecordToRecordset() { var rs = new Recordset { Name = "MyRec" }; rs.Records.Add(rs.NewRecord()); Assert.AreEqual(1, rs.Records.Count); Assert.AreEqual("MyRec(1)", rs.Records[0].Label); }
public void SetValueWithRecordNotExistiongExpectedAddANewRecordToRecordset() { var rs = new Recordset { Name = "MyRec" }; rs.Fields.Add(new RecordsetField { Name = "MyField", Alias = "MyField" }); rs.SetValue(0, 0, "MyTestData"); Assert.AreEqual("MyTestData", rs.Records[0][0].Value); }
public void ToStringExpectedReturnsJson() { var rs = new Recordset { Name = "MyRec" }; var jsonStr = rs.ToString(); dynamic jsonObj = JsonConvert.DeserializeObject(jsonStr); Assert.AreEqual(rs.Name, jsonObj.Name.Value); }
public DbService(XElement xml) : base(xml) { ResourceType = ResourceType.DbService; var action = xml.Descendants("Action").FirstOrDefault(); if(action == null) { return; } Source = CreateSource<WebSource>(action); Method = CreateInputsMethod(action); var recordSets = CreateOutputsRecordsetList(action); Recordset = recordSets.FirstOrDefault() ?? new Recordset { Name = action.AttributeSafe("Name") }; if(String.IsNullOrEmpty(Recordset.Name)) { Recordset.Name = Method.Name; } }
public void PluginServiceToXmlExpectedSerializesProperties() { var expected = new PluginService { Source = new PluginSource { ResourceID = Guid.NewGuid(), ResourceName = "TestWebSource", }, Namespace = "abc.pqr", }; expected.Method.Parameters.AddRange( new[] { new MethodParameter { Name = "Param1", DefaultValue = "123" }, new MethodParameter { Name = "Param2", DefaultValue = "456" } }); var rs1 = new Recordset { Name = "Recordset1()" }; rs1.Fields.AddRange(new[] { new RecordsetField { Name = "Field1", Alias = "Alias1" }, new RecordsetField { Name = "Field2", Alias = "Alias2", Path = new XmlPath("actual", "display", "outputExpression", "sampleData") }, new RecordsetField { Name = "Field3", Alias = null } }); expected.Recordsets.Add(rs1); var xml = expected.ToXml(); var actual = new PluginService(xml); Assert.AreEqual(expected.Source.ResourceType, actual.Source.ResourceType); Assert.AreEqual(expected.Source.ResourceID, actual.Source.ResourceID); Assert.AreEqual(expected.Source.ResourceName, actual.Source.ResourceName); Assert.AreEqual(expected.ResourceType, actual.ResourceType); Assert.AreEqual(expected.Namespace, actual.Namespace); foreach(var expectedParameter in expected.Method.Parameters) { var actualParameter = actual.Method.Parameters.First(p => p.Name == expectedParameter.Name); Assert.AreEqual(expectedParameter.DefaultValue, actualParameter.DefaultValue); } foreach(var expectedRecordset in expected.Recordsets) { // expect actual to have removed recordset notation ()... var actualRecordset = actual.Recordsets.First(rs => rs.Name == expectedRecordset.Name.Replace("()", "")); foreach(var expectedField in expectedRecordset.Fields) { var actualField = actualRecordset.Fields.FirstOrDefault(f => expectedField.Name == null ? f.Name == "" : f.Name == expectedField.Name); Assert.IsNotNull(actualField); Assert.AreEqual(expectedField.Alias ?? "", actualField.Alias); if(actualField.Path != null) { Assert.AreEqual(expectedField.Path.ActualPath, actualField.Path.ActualPath); Assert.AreEqual(expectedField.Path.DisplayPath, actualField.Path.DisplayPath); Assert.AreEqual(string.Format("[[{0}]]", expectedField.Alias), actualField.Path.OutputExpression); Assert.AreEqual(expectedField.Path.SampleData, actualField.Path.SampleData); } } } }
public void SetValueSecondMethodExpectedAddANewRecordToRecordset() { var rs = new Recordset { Name = "MyRec" }; var rsr = rs.NewRecord(); rs.Records.Add(rsr); rs.Fields.Add(new RecordsetField { Name = "MyField", Alias = "MyField" }); rs.Fields.Add(new RecordsetField { Name = "MyField2", Alias = "MyField2" }); rs.SetValue(ref rsr, 0, "MyTestData"); Assert.AreEqual("MyTestData", rs.Records[0][0].Value); rs.SetValue(ref rsr, 1, "MyTestData1"); rs.SetValue(ref rsr, 0, "MyTestData3"); Assert.AreEqual("MyTestData1", rs.Records[0][1].Value); Assert.AreEqual("MyTestData3", rs.Records[0][0].Value); }
public void ConstructorWithNoParametersExpectedInitializesListProperties() { var rs = new Recordset(); Assert.IsNotNull(rs.Fields); Assert.IsNotNull(rs.Records); }
public DbService() { ResourceType = ResourceType.DbService; Source = new DbSource(); Recordset = new Recordset(); }
public static RecordsetList ToRecordsetList(this IOutputDescription outputDescription, RecordsetList currentList, string defaultFieldName) { if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } var result = currentList ?? new RecordsetList(); var currentFields = new List <RecordsetField>(); #region Create a copy of the current list's fields so that we don't lose the user-defined aliases. foreach (var rs in result) { currentFields.AddRange(rs.Fields); rs.Fields.Clear(); } #endregion var paths = outputDescription.DataSourceShapes[0].Paths; foreach (var path in paths) { var names = SplitRecordsetAndFieldNames(path); var rsName = names.Item1; var rsAlias = rsName; var fieldName = names.Item2; if (string.IsNullOrEmpty(fieldName) && string.IsNullOrEmpty(defaultFieldName)) { continue; } if (string.IsNullOrEmpty(fieldName) && !string.IsNullOrEmpty(defaultFieldName)) { fieldName = defaultFieldName; } if (fieldName != null) { var fieldAlias = fieldName.Replace(":", ""); var pathLoop = path; var rsField = currentFields.FirstOrDefault(f => f.Path == pathLoop) ?? new RecordsetField { Path = path, Alias = fieldAlias, RecordsetAlias = rsAlias }; rsField.Name = fieldName; var rs = result.FirstOrDefault(r => r.Name == rsName); if (rs == null) { rs = new Recordset { Name = rsName }; result.Add(rs); } var fieldIndex = rs.Fields.Count; rs.Fields.Add(rsField); var data = path.SampleData.Split(','); for (var recordIndex = 0; recordIndex < data.Length; recordIndex++) { rs.SetValue(recordIndex, fieldIndex, data[recordIndex]); } } } result.Description = outputDescription; return(result); }
public SqliteDBService() { ResourceType = "DbService"; Source = new SqliteDBSource(); Recordset = new Recordset(); }
public DbService() { ResourceType = "DbService"; Source = new DbSource(); Recordset = new Recordset(); }
// BUG 9626 - 2013.06.11 - TWR : refactored protected RecordsetList CreateOutputsRecordsetList(XElement action) { var result = new RecordsetList(); var outputDescriptionStr = action.ElementSafe("OutputDescription"); var paths = new List <IPath>(); if (!string.IsNullOrEmpty(outputDescriptionStr)) { var outputDescriptionSerializationService = OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService(); var description = outputDescriptionSerializationService.Deserialize(outputDescriptionStr); if (description == null) { // we need to handle old plugins ;) outputDescriptionStr = outputDescriptionStr.Replace("<JSON />", "") .Replace("</Dev2XMLResult>", "") .Replace("</InterrogationResult>", "") .Replace("<InterrogationResult>", "") .Replace("<Dev2XMLResult>", ""); description = outputDescriptionSerializationService.Deserialize(outputDescriptionStr); } // TODO : Get Result Coming Back ;) OutputDescription = description; if (description != null && description.DataSourceShapes.Count > 0) { paths = description.DataSourceShapes[0].Paths; } } var xElement = action.Element("Outputs"); if (xElement != null) { OutputSpecification = xElement.ToString(); } foreach (var output in action.Descendants("Output")) { var rsName = output.AttributeSafe("RecordsetName"); var rsAlias = output.AttributeSafe("Recordset"); // legacy - should be RecordsetAlias var fieldName = output.AttributeSafe("OriginalName"); var fieldAlias = output.AttributeSafe("MapsTo"); var path = paths.FirstOrDefault(p => output.AttributeSafe("Value").Equals(p.OutputExpression, StringComparison.InvariantCultureIgnoreCase)); if (path != null) { var names = RecordsetListHelper.SplitRecordsetAndFieldNames(path); if (string.IsNullOrEmpty(rsName)) { rsName = names.Item1; } if (string.IsNullOrEmpty(fieldName)) { fieldName = names.Item2; } } var recordset = result.FirstOrDefault(r => r.Name == rsName); if (recordset == null) { recordset = new Recordset { Name = rsName }; result.Add(recordset); } recordset.Fields.Add(new RecordsetField { Name = fieldName, Alias = fieldAlias, RecordsetAlias = rsAlias, Path = path }); } return(result); }
public DbService() { ResourceType = Common.Interfaces.Data.ResourceType.DbService; Source = new DbSource(); Recordset = new Recordset(); }
public void WebServiceToXmlExpectedSerializesProperties() { var expected = new WebService { Source = new WebSource { ResourceID = Guid.NewGuid(), ResourceName = "TestWebSource", }, RequestUrl = "pqr", RequestMethod = WebRequestMethod.Get, RequestHeaders = "Content-Type: text/xml", RequestBody = "abc", RequestResponse = "xyz", JsonPath = "$.somepath" }; #region setup method parameters expected.Method.Parameters.AddRange( new[] { new MethodParameter { Name = "Param1", DefaultValue = "123" }, new MethodParameter { Name = "Param2", DefaultValue = "456" } }); #endregion #region setup rs1 var rs1 = new Recordset { Name = "Recordset1()" }; rs1.Fields.AddRange(new[] { new RecordsetField { Name = "Field1", Alias = "Alias1", RecordsetAlias = "RecAlias1()" }, new RecordsetField { Name = "Field2", Alias = "Alias2", RecordsetAlias = "RecAlias1()" } }); expected.Recordsets.Add(rs1); #endregion #region setup rs2 var rs2 = new Recordset { Name = "Recordset2()" }; rs2.Fields.AddRange(new[] { new RecordsetField { Name = "Field3", Alias = "Alias3" }, new RecordsetField { Name = "Field4", Alias = "Alias4" } }); expected.Recordsets.Add(rs2); #endregion var xml = expected.ToXml(); var actual = new WebService(xml); Assert.AreEqual(expected.Source.ResourceType, actual.Source.ResourceType); Assert.AreEqual(expected.Source.ResourceID, actual.Source.ResourceID); Assert.AreEqual(expected.Source.ResourceName, actual.Source.ResourceName); Assert.AreEqual(expected.ResourceType, actual.ResourceType); Assert.AreEqual(expected.RequestUrl, actual.RequestUrl); Assert.AreEqual(expected.RequestMethod, actual.RequestMethod); Assert.AreEqual(expected.RequestHeaders, actual.RequestHeaders); Assert.AreEqual(expected.RequestBody, actual.RequestBody); Assert.AreEqual(expected.JsonPath, actual.JsonPath); Assert.IsNull(actual.RequestResponse); foreach(var expectedParameter in expected.Method.Parameters) { MethodParameter parameter = expectedParameter; var actualParameter = actual.Method.Parameters.First(p => p.Name == parameter.Name); Assert.AreEqual(expectedParameter.DefaultValue, actualParameter.DefaultValue); } foreach(var expectedRecordset in expected.Recordsets) { // expect actual to have removed recordset notation ()... Recordset recordset = expectedRecordset; var actualRecordset = actual.Recordsets.First(rs => rs.Name == recordset.Name.Replace("()", "")); foreach(var expectedField in expectedRecordset.Fields) { RecordsetField field = expectedField; var actualField = actualRecordset.Fields.First(f => f.Name == field.Name); Assert.AreEqual(expectedField.Alias, actualField.Alias); // expect actual to have removed recordset notation ()... var expectedRecordsetAlias = string.IsNullOrEmpty(expectedField.RecordsetAlias) ? string.Empty : expectedField.RecordsetAlias.Replace("()", ""); Assert.AreEqual(expectedRecordsetAlias, actualField.RecordsetAlias); } } }
// ReSharper disable InconsistentNaming public void DbService_ToXml_WhenRecordSetHasBlankFields_ExpectNotPartOfOutputDescription() // ReSharper restore InconsistentNaming { //------------Setup for test-------------------------- var dbService = new DbService(); var dbSource = new DbSource { ResourceName = "Source" }; var resourceId = Guid.NewGuid(); dbSource.ResourceID = resourceId; dbService.Source = dbSource; var serviceMethod = new ServiceMethod { Name = "Method" }; dbService.Method = serviceMethod; var recordset = new Recordset { Name = "SomeRecSet" }; var recordsetField = new RecordsetField { Alias = "SomeAlias", Name = "" }; recordset.Fields.Add(recordsetField); dbService.Recordset = recordset; // ReSharper disable InconsistentNaming const string expected = @"<Service ID=""00000000-0000-0000-0000-000000000000"" Name="""" ResourceType=""DbService"" IsValid=""false""> <Actions> <Action Name=""SomeRecSet"" Type=""InvokeStoredProc"" SourceID=""{0}"" SourceName=""Source"" ExecuteAction="""" SourceMethod=""Method""> <Inputs /> <Outputs /> <OutputDescription><![CDATA[<z:anyType xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:d1p1=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph.Ouput"" i:type=""d1p1:OutputDescription"" xmlns:z=""http://schemas.microsoft.com/2003/10/Serialization/""><d1p1:DataSourceShapes xmlns:d2p1=""http://schemas.microsoft.com/2003/10/Serialization/Arrays""><d2p1:anyType i:type=""d1p1:DataSourceShape""><d1p1:_x003C_Paths_x003E_k__BackingField /></d2p1:anyType></d1p1:DataSourceShapes><d1p1:Format>ShapedXML</d1p1:Format></z:anyType>]]></OutputDescription> </Action> </Actions> <AuthorRoles /> <Comment /> <Tags /> <HelpLink /> <UnitTestTargetWorkflowService /> <BizRule /> <WorkflowActivityDef /> <XamlDefinition /> <DataList /> <TypeOf>InvokeStoredProc</TypeOf> <DisplayName></DisplayName> <Category></Category> <AuthorRoles></AuthorRoles> <ErrorMessages /> </Service>"; // ReSharper restore InconsistentNaming //------------Execute Test--------------------------- var xElement = dbService.ToXml(); //------------Assert Results------------------------- Assert.AreEqual(string.Format(expected, resourceId), xElement.ToString()); }
public static RecordsetList ToRecordsetList(this IOutputDescription outputDescription, RecordsetList currentList = null, string defaultFieldName = "") { if(outputDescription == null || outputDescription.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception("Error retrieving shape from service output."); } var result = currentList ?? new RecordsetList(); var currentFields = new List<RecordsetField>(); #region Create a copy of the current list's fields so that we don't lose the user-defined aliases. foreach(var rs in result) { currentFields.AddRange(rs.Fields); rs.Fields.Clear(); } #endregion var paths = outputDescription.DataSourceShapes[0].Paths; foreach(var path in paths) { var names = SplitRecordsetAndFieldNames(path); var rsName = names.Item1; var rsAlias = rsName; var fieldName = names.Item2; if(string.IsNullOrEmpty(fieldName) && string.IsNullOrEmpty(defaultFieldName)) { continue; } if(string.IsNullOrEmpty(fieldName) && !string.IsNullOrEmpty(defaultFieldName)) { fieldName = defaultFieldName; } // Bug 10532 - Amend to remove : from the alias ;) var fieldAlias = fieldName.Replace(":", ""); var pathLoop = path; var rsField = currentFields.FirstOrDefault(f => f.Path == pathLoop) ?? new RecordsetField { Path = path, Alias = fieldAlias, RecordsetAlias = rsAlias }; rsField.Name = fieldName; var rs = result.FirstOrDefault(r => r.Name == rsName); if(rs == null) { rs = new Recordset { Name = rsName }; result.Add(rs); } var fieldIndex = rs.Fields.Count; rs.Fields.Add(rsField); var data = path.SampleData.Split(','); for(var recordIndex = 0; recordIndex < data.Length; recordIndex++) { rs.SetValue(recordIndex, fieldIndex, data[recordIndex]); } } return result; }