Dictionary <string, IList <IPath> > GroupPaths(IDataSourceShape dataSourceShape) { var groupedPaths = new Dictionary <string, IList <IPath> >(); foreach (IPath path in dataSourceShape.Paths) { if (!string.IsNullOrWhiteSpace(path.OutputExpression)) { var key = GetOutputDescriptionKey(path.OutputExpression); if (groupedPaths.TryGetValue(key, out IList <IPath> dataSourceShapePaths)) { dataSourceShapePaths.Add(path); } else { dataSourceShapePaths = new List <IPath> { path }; groupedPaths.Add(key, dataSourceShapePaths); } } } return(groupedPaths); }
// ReSharper disable InconsistentNaming public void SqlDatabaseBroker_TestService_ValidDbServiceThatReturnsNull_RecordsetWithNullColumn() // ReSharper restore InconsistentNaming { var service = new DbService { ResourceID = Guid.NewGuid(), ResourceName = "NullService", ResourceType = ResourceType.DbService, ResourcePath = "Test", Method = new ServiceMethod { Name = "Pr_GeneralTestColumnData", Parameters = new List <MethodParameter>(), ExecuteAction = "Pr_GeneralTestColumnData" }, Recordset = new Recordset { Name = "Collections", }, Source = SqlServerTests.CreateDev2TestingDbSource() }; var broker = new SqlDatabaseBroker(); IOutputDescription outputDescription = broker.TestService(service); Assert.AreEqual(1, outputDescription.DataSourceShapes.Count); IDataSourceShape dataSourceShape = outputDescription.DataSourceShapes[0]; Assert.IsNotNull(dataSourceShape); Assert.AreEqual(3, dataSourceShape.Paths.Count); StringAssert.Contains(dataSourceShape.Paths[2].DisplayPath, "TestTextNull"); //This is the field that contains a null value. Previously this column would not have been returned. }
public void SerializeOutputDescriptionWithJSONPaths_Expected_DeserializationToWork() { IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new JsonPath("Name", "Name", "[[ScalarName]]")); dataSourceShape.Paths.Add(new JsonPath("Departments().Name", "Departments.Name", "[[Names().DepartmentName]]")); dataSourceShape.Paths.Add(new JsonPath("Departments().Employees().Name", "Departments.Employees.Name", "[[Names().EmployeeName]]")); dataSourceShape.Paths.Add(new JsonPath("PrimitiveRecordset()", "PrimitiveRecordset", "[[OtherNames().Name]]")); IOutputDescription testOutputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); testOutputDescription.DataSourceShapes.Add(dataSourceShape); IOutputDescriptionSerializationService outputDescriptionSerializationService = OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService(); string serializedData = outputDescriptionSerializationService.Serialize(testOutputDescription); IOutputDescription deserializedOutputDescription = outputDescriptionSerializationService.Deserialize(serializedData); string expected = testOutputDescription.Format.ToString() + "^" + string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" + string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" + string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression)); string actual = deserializedOutputDescription.Format.ToString() + "^" + string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" + string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" + string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression)); Assert.AreEqual(expected, actual); }
public void SerializeOutputDescriptionWithXMLPaths_Expected_DeserializationToWork() { IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new XmlPath("Company:Name", "Company:Name", "[[Names().CompanyName]]")); dataSourceShape.Paths.Add(new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name", "[[Names().DepartmentName]]")); dataSourceShape.Paths.Add(new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name", "[[Names().EmployeeName]]")); IOutputDescription testOutputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); testOutputDescription.DataSourceShapes.Add(dataSourceShape); IOutputDescriptionSerializationService outputDescriptionSerializationService = OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService(); string serializedData = outputDescriptionSerializationService.Serialize(testOutputDescription); IOutputDescription deserializedOutputDescription = outputDescriptionSerializationService.Deserialize(serializedData); string expected = testOutputDescription.Format.ToString() + "^" + string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" + string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" + string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression)); string actual = deserializedOutputDescription.Format.ToString() + "^" + string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" + string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" + string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression)); Assert.AreEqual(expected, actual); }
public bool Equals(IDataSourceShape other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } var collectionEquals = CommonEqualityOps.CollectionEquals(Paths, other.Paths, EqualityFactory.GetEqualityComparer <IPath>(EqualsMethod, GetHashCodeMethod)); return(collectionEquals); }
/// <summary> /// Groups paths by their output expressions /// </summary> private Dictionary<string, IList<IPath>> GroupPaths(IDataSourceShape dataSourceShape) { var groupedPaths = new Dictionary<string, IList<IPath>>(); foreach (IPath path in dataSourceShape.Paths) { if (!string.IsNullOrWhiteSpace(path.OutputExpression)) { string key = GetOutputDescriptionKey(path.OutputExpression); IList<IPath> dataSourceShapePaths; if (groupedPaths.TryGetValue(key, out dataSourceShapePaths)) { dataSourceShapePaths.Add(path); } else { dataSourceShapePaths = new List<IPath> {path}; groupedPaths.Add(key, dataSourceShapePaths); } } } return groupedPaths; }