public void Method_Scenario_Expected() { // Arrange string databaseConnStr = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|TestDatabase.mdf;Integrated Security=True"; var dataService = new DataServiceV2(databaseConnStr, new SqlQueryBuilderWithObjectHierarchy('.'), new RowsToEdmObjectHierarchyResultTransformer('.')); var edmTreeModelBuilder = new EdmObjectHierarchyModelBuilder(new SchemaViewsReader(databaseConnStr, "dbo")); var edmModel = edmTreeModelBuilder.GetModel(); var edmSchemaType = edmModel.FindType("dbo.Case2Obligation"); var edmCollectionType = edmModel.FindDeclaredEntityContainer("container").FindEntitySet("Case2Obligation"); var oDataQueryContext = new ODataQueryContext(edmModel, edmSchemaType); HttpRequestMessage message = new HttpRequestMessage(); message.RequestUri = new Uri("http://localhost:81/Case2Obligation?$orderby=Obligation/debtorName asc, Obligation/consumerIdentity/Number desc&$top=3&$skip=1"); var oDataQueryOptions = new ODataQueryOptions(oDataQueryContext, message); oDataQueryOptions.Validate(new ODataValidationSettings()); var collectionType = (IEdmCollectionType) new EdmCollectionType((IEdmTypeReference) new EdmEntityTypeReference(edmCollectionType.ElementType, false)); var edmEntityObjectCollection = dataService.Get(collectionType, oDataQueryOptions); // Act // Assert }
public void GetModel_TableInDatabaseSchema_SameTypeIsPlacedInSchemaElements() { // Arrange var mock = new Mock <ISchemaReader>(); var tableName = "x"; var secondColumn = new DatabaseColumn { Name = "SecondName", IsPrimaryKey = false, DataType = "nvarchar", Nullable = false, Table = tableName, Schema = "dbo" }; var firstColumn = new DatabaseColumn { Name = "FirstName", IsPrimaryKey = false, DataType = "nvarchar", Nullable = false, Table = tableName, Schema = "dbo" }; DatabaseTable[] tables = { new DatabaseTable() { Name = tableName, Schema = "dbo", Columns = new[] { firstColumn, secondColumn } } }; mock.Setup(s => s.GetTables(It.IsAny <IEnumerable <TableInfo> >())).Returns(tables); // Act var edmTreeModelBuilder = new EdmObjectHierarchyModelBuilder(mock.Object); var edmModel = edmTreeModelBuilder.GetModel(); // Assert var edmSchemaElement = edmModel.SchemaElements.FirstOrDefault(f => f.Name == tableName); Assert.NotNull(edmSchemaElement); var edmEntityType = edmSchemaElement as EdmEntityType; var firstColumnDesclaredProperty = edmEntityType.DeclaredProperties.FirstOrDefault(f => f.Name == firstColumn.Name); Assert.NotNull(firstColumnDesclaredProperty); var secondColumnDesclaredProperty = edmEntityType.DeclaredProperties.FirstOrDefault(f => f.Name == secondColumn.Name); Assert.NotNull(secondColumnDesclaredProperty); }
public void GetModel_PrimaryKeyColumnInDatabaseTable_IsSetOnEdmType() { // Arrange var mock = new Mock <ISchemaReader>(); var tableName = "x"; var pkColumn = new DatabaseColumn { Name = "Id", IsPrimaryKey = true, DataType = "nvarchar", Nullable = false, Table = tableName, Schema = "dbo" }; var firstColumn = new DatabaseColumn { Name = "FirstName", IsPrimaryKey = false, DataType = "nvarchar", Nullable = false, Table = tableName, Schema = "dbo" }; DatabaseTable[] tables = { new DatabaseTable() { Name = tableName, Schema = "dbo", Columns = new[] { pkColumn, firstColumn } } }; mock.Setup(s => s.GetTables(It.IsAny <IEnumerable <TableInfo> >())).Returns(tables); // Act var edmTreeModelBuilder = new EdmObjectHierarchyModelBuilder(mock.Object); var edmModel = edmTreeModelBuilder.GetModel(); // Assert var edmSchemaElement = edmModel.SchemaElements.FirstOrDefault(f => f.Name == tableName); Assert.NotNull(edmSchemaElement); var edmEntityType = edmSchemaElement as EdmEntityType; var pkProperty = edmEntityType.DeclaredKey.FirstOrDefault(f => f.Name == pkColumn.Name); Assert.NotNull(pkProperty); }
public void GetModel_DottedHierarchyColumns_ShouldBeNotBeMixedWithOtherTableComponents() { // Arrange var mock = new Mock <ISchemaReader>(); var tableName = "x"; var c1Name = "Obligation"; var c2Name = "Subject"; var c3Name = "IdentityNumber"; var c3Property1Name = "Value"; var c3Property2Name = "Type"; var firstColumn = new DatabaseColumn { Name = $"{c1Name}.{c2Name}.{c3Name}.{c3Property1Name}", IsPrimaryKey = false, DataType = "nvarchar", Nullable = false, Table = tableName, Schema = "dbo" }; var secondColumn = new DatabaseColumn { Name = $"{c1Name}.{c2Name}.{c3Name}.{c3Property2Name}", IsPrimaryKey = false, DataType = "nvarchar", Nullable = false, Table = tableName, Schema = "dbo" }; DatabaseTable[] tables = { new DatabaseTable() { Name = tableName, Schema = "dbo", Columns = new[] { firstColumn, secondColumn } } }; mock.Setup(s => s.GetTables(It.IsAny <IEnumerable <TableInfo> >())).Returns(tables); // Act var edmTreeModelBuilder = new EdmObjectHierarchyModelBuilder(mock.Object); var edmModel = edmTreeModelBuilder.GetModel(); // Assert var edmSchemaElement = edmModel.SchemaElements.FirstOrDefault(f => f.Name == tableName); Assert.NotNull(edmSchemaElement); var edmEntityType = edmSchemaElement as EdmEntityType; var component1 = edmEntityType.DeclaredProperties.First(f => f.Name == c1Name) as EdmStructuralProperty; Assert.NotNull(component1); EdmComplexType edmComplexType = ((EdmComplexType)component1.Type.Definition); Assert.IsTrue(edmComplexType.Name.StartsWith(tableName)); var component2 = edmComplexType.DeclaredProperties.First(f => f.Name == c2Name) as EdmStructuralProperty; Assert.NotNull(component2); edmComplexType = ((EdmComplexType)component2.Type.Definition); Assert.IsTrue(edmComplexType.Name.StartsWith(tableName)); var component3 = edmComplexType.DeclaredProperties.First(f => f.Name == c3Name) as EdmStructuralProperty; Assert.NotNull(component3); edmComplexType = ((EdmComplexType)component3.Type.Definition); Assert.IsTrue(edmComplexType.Name.StartsWith(tableName)); }