示例#1
0
        public void ProcedureTest()
        {
            var schema = PrepareModel();

            var procedure = new DatabaseStoredProcedure {
                Name = "SelectCategory"
            };
            var argument = new DatabaseArgument
            {
                Name             = "p1",
                DatabaseDataType = "VARCHAR",
                Length           = 10,
                DataType         = DataTypeConverter.FindDataType("VARCHAR", schema.DataTypes, SqlType.SqlServer, null),
                In = true,
            };

            procedure.Arguments.Add(argument);
            var rs           = new DatabaseResultSet();
            var resultColumn = new DatabaseColumn {
                Name = "Output", DbDataType = "VARCHAR"
            };

            DataTypeConverter.AddDataType(resultColumn);
            rs.Columns.Add(resultColumn);
            procedure.ResultSets.Add(rs);
            schema.StoredProcedures.Add(procedure);

            var          directory  = TestHelper.CreateDirectory("MySprocTest");
            const string @namespace = "MySprocTest";
            var          settings   = new CodeWriterSettings
            {
                Namespace             = @namespace,
                CodeTarget            = CodeTarget.Poco,
                WriteStoredProcedures = true
            };

            var target = new CodeWriter(schema, settings);

            target.Execute(directory);

            var procedures = directory.GetDirectories("Procedures").FirstOrDefault();

            if (procedures == null)
            {
                Assert.Fail("Could not find Procedures subdirectory");
            }
            var files    = procedures.GetFiles("*.cs");
            var products = files.FirstOrDefault(f => f.Name == "SelectCategory.cs");

            Assert.IsNotNull(products, "Should have written SelectCategory class for SelectCategory procedure");

            var category = files.FirstOrDefault(f => f.Name == "SelectCategoryResult.cs");

            Assert.IsNotNull(category, "Should have written SelectCategoryResult class to the result of the sproc");
        }