public virtual Recordset FetchRecordset(DbService dbService, bool addFields) { if (dbService == null) { throw new ArgumentNullException("dbService"); } var broker = CreateDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription == null || outputDescription.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception("Error retrieving shape from service output."); } // Clear out the Recordset.Fields list because the sequence and // number of fields may have changed since the last invocation. // // Create a copy of the Recordset.Fields list before clearing it // so that we don't lose the user-defined aliases. // dbService.Recordset.Name = dbService.Recordset.Name.Replace(".", "_"); dbService.Recordset.Fields.Clear(); ServiceMappingHelper smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); }
public void ServiceMappingHelper_MapDbOutputs_WhenNoOutputsWithPaths_ExpectNoOutputMappings() { //------------Setup for test-------------------------- const string outputDefs = @"<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 xmlns:d5p1=""http://schemas.datacontract.org/2004/07/Dev2.Converters.Graph.DataTable"" i:type=""d5p1:DataTablePath""><_x003C_ActualPath_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">Column1</_x003C_ActualPath_x003E_k__BackingField><_x003C_DisplayPath_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph""></_x003C_DisplayPath_x003E_k__BackingField><_x003C_OutputExpression_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph""></_x003C_OutputExpression_x003E_k__BackingField><_x003C_SampleData_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">the result</_x003C_SampleData_x003E_k__BackingField></d2p1:anyType></d1p1:_x003C_Paths_x003E_k__BackingField></d2p1:anyType></d1p1:DataSourceShapes><d1p1:Format>ShapedXML</d1p1:Format></z:anyType>"; var serviceMappingHelper = new ServiceMappingHelper(); IOutputDescription outputs = new OutputDescriptionSerializationService().Deserialize(outputDefs); outputs.DataSourceShapes.Add(new DataSourceShape()); DbService theService = CreateCountriesDbService(); theService.Recordset.Fields.Clear(); //------------Execute Test--------------------------- serviceMappingHelper.MapDbOutputs(outputs, ref theService, true); //------------Assert Results------------------------- Assert.AreEqual(0, theService.Recordset.Fields.Count); }
public void ServiceMappingHelper_MapDbOutputs_WhenOutputsWithPaths_ExpectTwoOutputMappings() { //------------Setup for test-------------------------- const string outputDefs = @"<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 xmlns:d5p1=""http://schemas.datacontract.org/2004/07/Dev2.Converters.Graph.DataTable"" i:type=""d5p1:DataTablePath""><_x003C_ActualPath_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">CountryID</_x003C_ActualPath_x003E_k__BackingField><_x003C_DisplayPath_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">CountryID</_x003C_DisplayPath_x003E_k__BackingField><_x003C_OutputExpression_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">[[dbo_Pr_CitiesGetCountries().CountryID]]</_x003C_OutputExpression_x003E_k__BackingField><_x003C_SampleData_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">1__COMMA__2__COMMA__3__COMMA__4__COMMA__5__COMMA__6__COMMA__7__COMMA__8__COMMA__9__COMMA__10</_x003C_SampleData_x003E_k__BackingField></d2p1:anyType><d2p1:anyType xmlns:d5p1=""http://schemas.datacontract.org/2004/07/Dev2.Converters.Graph.DataTable"" i:type=""d5p1:DataTablePath""><_x003C_ActualPath_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">Description</_x003C_ActualPath_x003E_k__BackingField><_x003C_DisplayPath_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">Description</_x003C_DisplayPath_x003E_k__BackingField><_x003C_OutputExpression_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">[[dbo_Pr_CitiesGetCountries().Description]]</_x003C_OutputExpression_x003E_k__BackingField><_x003C_SampleData_x003E_k__BackingField xmlns=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph"">Afghanistan__COMMA__Albania__COMMA__Algeria__COMMA__Andorra__COMMA__Angola__COMMA__Argentina__COMMA__Armenia__COMMA__Australia__COMMA__Austria__COMMA__Azerbaijan</_x003C_SampleData_x003E_k__BackingField></d2p1:anyType></d1p1:_x003C_Paths_x003E_k__BackingField></d2p1:anyType></d1p1:DataSourceShapes><d1p1:Format>ShapedXML</d1p1:Format></z:anyType>"; var serviceMappingHelper = new ServiceMappingHelper(); IOutputDescription outputs = new OutputDescriptionSerializationService().Deserialize(outputDefs); outputs.DataSourceShapes.Add(new DataSourceShape()); DbService theService = CreateCountriesDbService(); theService.Recordset.Fields.Clear(); //------------Execute Test--------------------------- serviceMappingHelper.MapDbOutputs(outputs, ref theService, true); //------------Assert Results------------------------- Assert.AreEqual(2, theService.Recordset.Fields.Count); }
public void ServiceMappingHelper_MapDbOutputs_WhenSampleDataContainsCommaReplacement_Expect10SampleItems() { // // 2013.12.11 - COMMUNITY BUG - 341463 - Fixed test to include empty cells // //------------Setup for test-------------------------- var expectedData = CreateDbServiceLocationsDataTable(); // OutputDescription MUST contain empty cells!!! var outputDefs = XmlResource.Fetch("DbServiceLocationsOutputDescription"); var serviceMappingHelper = new ServiceMappingHelper(); var outputs = new OutputDescriptionSerializationService().Deserialize(outputDefs.ToString()); outputs.DataSourceShapes.Add(new DataSourceShape()); var theService = CreateCountriesDbService(); theService.Recordset.Fields.Clear(); //------------Execute Test--------------------------- serviceMappingHelper.MapDbOutputs(outputs, ref theService, true); //------------Assert Results------------------------- Assert.AreEqual(expectedData.Columns.Count, theService.Recordset.Fields.Count); for (var i = 0; i < expectedData.Rows.Count; i++) { var record = theService.Recordset.Records[i]; Assert.AreEqual(expectedData.Columns.Count, record.Cells.Length); for (var j = 0; j < expectedData.Columns.Count; j++) { var expected = expectedData.Rows[i][j]; var actual = record.Cells[j].Value; Assert.AreEqual(expected, actual); } } }
private Recordset FetchDbSourceRecordset(ref DbService dbService, bool addFields, DbSource source) { switch (source.ServerType) { case enSourceType.SqlDatabase: { var broker = CreateDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } if (dbService.Recordset != null) { dbService.Recordset.Name = dbService.Method.ExecuteAction; if (dbService.Recordset.Name != null) { dbService.Recordset.Name = dbService.Recordset.Name.Replace(".", "_"); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); } return(dbService.Recordset); } case enSourceType.MySqlDatabase: { var broker = new MySqlDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.SQLiteDatabase: { var broker = new SqliteDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.PostgreSQL: { var broker = new PostgreSqlDataBaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.Oracle: { var broker = new OracleDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.ODBC: { var broker = new ODBCDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); dbService.Recordset.Name = @"Unnamed"; return(dbService.Recordset); } default: return(null); } }
public virtual Recordset FetchRecordset(DbService dbService, bool addFields) { if (dbService == null) { throw new ArgumentNullException(nameof(dbService)); } var source = dbService.Source as DbSource; if (source != null) { switch (source.ServerType) { case enSourceType.SqlDatabase: { var broker = CreateDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } // Clear out the Recordset.Fields list because the sequence and // number of fields may have changed since the last invocation. // // Create a copy of the Recordset.Fields list before clearing it // so that we don't lose the user-defined aliases. // if (dbService.Recordset != null) { dbService.Recordset.Name = dbService.Method.ExecuteAction; if (dbService.Recordset.Name != null) { dbService.Recordset.Name = dbService.Recordset.Name.Replace(".", "_"); } dbService.Recordset.Fields.Clear(); ServiceMappingHelper smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); } return(dbService.Recordset); } case enSourceType.MySqlDatabase: { var broker = new MySqlDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); ServiceMappingHelper smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.PostgreSQL: { var broker = new PostgreSqlDataBaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); ServiceMappingHelper smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.Oracle: { var broker = new OracleDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); ServiceMappingHelper smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.ODBC: { var broker = new ODBCDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); ServiceMappingHelper smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); dbService.Recordset.Name = @"Unnamed"; return(dbService.Recordset); } default: return(null); } } return(null); // Clear out the Recordset.Fields list because the sequence and // number of fields may have changed since the last invocation. // // Create a copy of the Recordset.Fields list before clearing it // so that we don't lose the user-defined aliases. // }