Пример #1
0
        public void Test()
        {
            var mappingRequest =
                XmlSqlSchemaMappingCompilerInput.FromFile(
                    @"AlenosoftTestDb.schema-mapping-request.xml");

            var mappingResponse = new SqlSchemaMappingCompiler(
                ConnectionStrings.AlenosoftTestDb)
                .CompileAsync(mappingRequest)
                .GetAwaiter()
                .GetResult();

            foreach (var operation in mappingResponse.ExecuteReaderOperations)
            {

            }

            const string spName = "uspParameterlessSimpleSelect";
            const string interfaceName = "IMyResultSet";
            var session = new SqlSession(ConnectionStrings.AlenosoftTestDb);
            var schema =
                session.FillSchema(
                    new SqlCommand($"dbo.{spName}") { CommandType = CommandType.StoredProcedure },
                    new DataSet(),
                    SchemaType.Source).Single();

            var service = new SqlSchemaMappingCompiler(ConnectionStrings.AlenosoftTestDb);
            //var request = new FakeSqlSchemaMappingRequest();
            //var selector = new FakeSqlExecuteReaderStoredProcedureSelector("dbo", spName, "MethodName");

            //var mapping = new FakeResultSetMapping();
            //var resultSetInterface = new FakeResultSetInterface(interfaceName);
            //selector.AddMapping(mapping);

            //foreach (DataColumn column in schema.Columns)
            //{
            //    mapping.AddColumnMapping(
            //        new FakeResultSetColumnMapping
            //            {
            //                InterfaceName = interfaceName,
            //                ColumnName = column.ColumnName,
            //                PropertyName = "My" + column.ColumnName,
            //                PropertyType = column.DataType
            //            });
            //    resultSetInterface.AddProperty("My" + column.ColumnName, column.DataType);
            //}

            //request.StoredProcedureSelectors.Add(selector);
            //request.TableContracts.Add(resultSetInterface);
            //var metadata = service.LoadMetadataAsync(request).GetAwaiter().GetResult();

            //var spInfo = metadata.ExecuteReaderOperations.Single();
            //var resultSetInfo = spInfo.ResultSetInfos.Single();
            //var columnInfos = resultSetInfo.ColumnInfos;
            //Assert.Equal(schema.Columns.Count, columnInfos.Count);
            //var lookup = columnInfos.ToDictionary(ci => ci.ColumnName);
            //foreach (DataColumn column in schema.Columns)
            //{
            //    var info = lookup[column.ColumnName];
            //    Assert.Equal(column.ColumnName, info.ColumnName, StringComparer.OrdinalIgnoreCase);
            //    Assert.Equal(column.Ordinal, info.Ordinal);
            //    Assert.Equal(column.DataType, info.DataType);

            //    var columnMapping = info.RowFieldContracts.Single();
            //    Assert.Equal(column.ColumnName, columnMapping.ColumnName, StringComparer.OrdinalIgnoreCase);
            //    Assert.Equal("My" + column.ColumnName, columnMapping.PropertyName, StringComparer.OrdinalIgnoreCase);
            //    Assert.Equal(column.DataType, columnMapping.PropertyType);
            //    Assert.Equal(interfaceName, columnMapping.InterfaceName);
            //}
        }