public void TestProjectSelectionScope()
        {
            // Arrange

            // Import database
            var database = SqlServerDatabaseFactory
                           .Import(SqlServerDatabaseFactory.GetLogger(), "server=(local);database=OnLineStore;integrated security=yes;", "dbo.sysdiagrams");

            // Create instance of Entity Framework Core project
            var project = new DapperProject
            {
                Name            = "OnLineStore",
                Database        = database,
                OutputDirectory = "C:\\Temp\\CatFactory.Dapper\\OnLineStore.Core"
            };

            // Act

            // Apply settings for Entity Framework Core project
            project.GlobalSelection(settings =>
            {
                settings.ForceOverwrite = true;
            });

            project.Selection("Sales.OrderHeader", settings => settings.UseStringBuilderForQueries = false);

            var orderHeader = database.FindTable("Sales.OrderHeader");

            var selectionForOrder = project.GetSelection(orderHeader);

            // Assert
            Assert.True(project.Selections.Count == 2);
            Assert.True(project.GlobalSelection().Settings.UseStringBuilderForQueries == true);
            Assert.True(selectionForOrder.Settings.UseStringBuilderForQueries == false);
        }
Пример #2
0
        public void TestDapperProject()
        {
            // Arrange
            var project = new DapperProject
            {
                Name            = "Store",
                Database        = StoreDatabase.Mock,
                OutputDirectory = "C:\\Temp\\CatFactory\\Dapper"
            };

            project.ScaffoldingDefinition += (source, args) =>
            {
            };

            project.ScaffoldedDefinition += (source, args) =>
            {
            };

            project.GlobalSelection(settings =>
            {
                settings.UseStringBuilderForQueries = false;
            });

            project.Select("Sales.Order", settings => settings.UseQueryBuilder = true);

            // Act
            foreach (var table in project.Database.Tables)
            {
                var selection = project.Selections.FirstOrDefault(item => item.Pattern == table.FullName);

                if (selection == null)
                {
                    selection = project.GlobalSelection();
                }

                var codeBuilder = new CSharpClassCodeBuilder
                {
                    ObjectDefinition = project.GetEntityClassDefinition(table, selection),
                    OutputDirectory  = project.OutputDirectory,
                    ForceOverwrite   = true
                };

                project.Scaffolding(codeBuilder);

                codeBuilder.CreateFile();

                project.Scaffolded(codeBuilder);
            }

            // Assert
            Assert.True(project.Selections.Count == 2);
        }
Пример #3
0
        public void ProjectScaffoldingFromNorthwindDatabaseTest()
        {
            // Import database
            var database = SqlServerDatabaseFactory
                           .Import(LoggerMocker.GetLogger <SqlServerDatabaseFactory>(), "server=(local);database=Northwind;integrated security=yes;", "dbo.sysdiagrams");

            // Create instance of Dapper Project
            var project = new DapperProject
            {
                Name            = "Northwind",
                Database        = database,
                OutputDirectory = @"C:\Temp\CatFactory.Dapper\Northwind.Dapper.API\src\Northwind.Dapper.API"
            };

            // Apply settings for project
            project.GlobalSelection(settings => settings.ForceOverwrite = true);

            // Build features for project, group all entities by schema into a feature
            project.BuildFeatures();

            // Scaffolding =^^=
            project
            .ScaffoldEntityLayer()
            .ScaffoldDataLayer();
        }
Пример #4
0
        public void TestDapperProject()
        {
            // Arrange
            var project = new DapperProject
            {
                Name            = "Store",
                Database        = Databases.OnLineStore,
                OutputDirectory = "C:\\Temp\\CatFactory\\Dapper",
                AuthorInfo      = new AuthorInfo
                {
                    Name  = "Hans H.",
                    Email = "*****@*****.**"
                }
            };

            project.ScaffoldingDefinition += (source, args) =>
            {
            };

            project.ScaffoldedDefinition += (source, args) =>
            {
            };

            project.GlobalSelection(settings => settings.UseStringBuilderForQueries = false);

            project.Selection("Sales.Order", settings => settings.UseQueryBuilder = true);

            // Act
            foreach (var table in project.Database.Tables)
            {
                var selection = project.Selections.FirstOrDefault(item => item.Pattern == table.FullName) ?? project.GlobalSelection();

                var codeBuilder = new CSharpClassCodeBuilder
                {
                    ObjectDefinition = project.GetEntityClassDefinition(table, selection),
                    OutputDirectory  = project.OutputDirectory,
                    ForceOverwrite   = true
                };

                codeBuilder.TranslatedDefinition += (source, args) =>
                {
                    if (project.AuthorInfo != null)
                    {
                        codeBuilder.Lines.Insert(0, new CommentLine("// Author name: {0}", project.AuthorInfo.Name));
                        codeBuilder.Lines.Insert(1, new CommentLine("// Email: {0}", project.AuthorInfo.Email));
                        codeBuilder.Lines.Insert(2, new CodeLine());
                    }
                };

                project.Scaffolding(codeBuilder);

                codeBuilder.CreateFile();

                project.Scaffolded(codeBuilder);
            }

            // Assert
            Assert.True(project.Selections.Count == 2);
        }
Пример #5
0
        public void ProjectScaffoldingFromExistingDatabaseTest()
        {
            // Import database
            var database = SqlServerDatabaseFactory
                           .Import(LoggerMocker.GetLogger <SqlServerDatabaseFactory>(), "server=(local);database=Store;integrated security=yes;", "dbo.sysdiagrams");

            // Create instance of Dapper Project
            var project = new DapperProject
            {
                Name            = "Store",
                Database        = database,
                OutputDirectory = @"C:\Temp\CatFactory.Dapper\Store.Dapper.API\src\Store.Dapper.API"
            };

            // Apply settings for project
            project.GlobalSelection(settings =>
            {
                settings.ForceOverwrite = true;
                settings.UpdateExclusions.AddRange(new string[] { "CreationUser", "CreationDateTime", "Timestamp" });
                settings.InsertExclusions.AddRange(new string[] { "LastUpdateUser", "LastUpdateDateTime", "Timestamp" });
            });

            project.Select("Production.*", settings =>
            {
                settings.UseStringBuilderForQueries   = false;
                settings.AddPagingForGetAllOperations = true;
            });

            project.Select("Sales.Order", settings => settings.AddPagingForGetAllOperations = true);

            // Build features for project, group all entities by schema into a feature
            project.BuildFeatures();

            // Add event handlers to before and after of scaffold

            project.ScaffoldingDefinition += (source, args) =>
            {
                // Add code to perform operations with code builder instance before to create code file
            };

            project.ScaffoldedDefinition += (source, args) =>
            {
                // Add code to perform operations after of create code file
            };

            // Scaffolding =^^=
            project
            .ScaffoldEntityLayer()
            .ScaffoldDataLayer();
        }
        public void ProjectScaffoldingFromNorthwindDatabaseTest()
        {
            // Import database
            var databaseFactory = new SqlServerDatabaseFactory(SqlServerDatabaseFactory.GetLogger())
            {
                DatabaseImportSettings = new DatabaseImportSettings
                {
                    ConnectionString       = "server=(local);database=Northwind;integrated security=yes;",
                    ImportScalarFunctions  = true,
                    ImportTableFunctions   = true,
                    ImportStoredProcedures = true,
                    Exclusions             =
                    {
                        "dbo.sp_alterdiagram",
                        "dbo.sp_creatediagram",
                        "dbo.sp_dropdiagram",
                        "dbo.sp_helpdiagramdefinition",
                        "dbo.sp_helpdiagrams",
                        "dbo.sp_renamediagram",
                        "dbo.sp_upgraddiagrams",
                        "dbo.sysdiagrams",
                        "dbo.fn_diagramobjects"
                    }
                }
            };

            var database = databaseFactory.Import();

            // Create instance of Dapper Project
            var project = new DapperProject
            {
                Name            = "Northwind.Core",
                Database        = database,
                OutputDirectory = @"C:\Temp\CatFactory.Dapper\Northwind.Core"
            };

            // Apply settings for project
            project.GlobalSelection(settings => settings.ForceOverwrite = true);

            project.Selection("dbo.Ten Most Expensive Products", settings => settings.UseStringBuilderForQueries = false);

            // Build features for project, group all entities by schema into a feature
            project.BuildFeatures();

            // Scaffolding =^^=
            project
            .ScaffoldEntityLayer()
            .ScaffoldDataLayer();
        }
        public void ProjectScaffoldingFromAdventureWorksDatabaseTest()
        {
            // Import database
            var databaseFactory = new SqlServerDatabaseFactory(SqlServerDatabaseFactory.GetLogger())
            {
                DatabaseImportSettings = new DatabaseImportSettings
                {
                    ConnectionString      = "server=(local);database=AdventureWorks2017;integrated security=yes;",
                    ImportTableFunctions  = true,
                    ImportScalarFunctions = true,
                    Exclusions            =
                    {
                        "dbo.sysdiagrams"
                    },
                    ExclusionTypes =
                    {
                        "geography"
                    }
                }
            };

            var database = databaseFactory.Import();

            // Create instance of Dapper Project
            var project = new DapperProject
            {
                Name            = "AdventureWorks.Core",
                Database        = database,
                OutputDirectory = @"C:\Temp\CatFactory.Dapper\AdventureWorks.Core"
            };

            // Apply settings for project
            project.GlobalSelection(settings => settings.ForceOverwrite = true);

            project.Selection("Sales.SalesOrderHeader", settings => settings.AddPagingForGetAllOperation = true);

            // Build features for project, group all entities by schema into a feature
            project.BuildFeatures();

            // Scaffolding =^^=
            project
            .ScaffoldEntityLayer()
            .ScaffoldDataLayer();
        }
Пример #8
0
        public void ProjectScaffoldingFromAdventureWorksDatabaseTest()
        {
            // Import database

            var factory = new SqlServerDatabaseFactory(LoggerMocker.GetLogger <SqlServerDatabaseFactory>())
            {
                ConnectionString = "server=(local);database=AdventureWorks2012;integrated security=yes;",
                ImportSettings   = new DatabaseImportSettings
                {
                    Exclusions = new List <string> {
                        "dbo.sysdiagrams"
                    },
                    ExclusionTypes = new List <string> {
                        "geography"
                    },
                    ImportTableFunctions = true
                }
            };

            var database = factory.Import();

            // Create instance of Dapper Project
            var project = new DapperProject
            {
                Name            = "AdventureWorks",
                Database        = database,
                OutputDirectory = @"C:\Temp\CatFactory.Dapper\AdventureWorks.Dapper.API\src\AdventureWorks.Dapper.API"
            };

            // Apply settings for project
            project.GlobalSelection(settings =>
            {
                settings.ForceOverwrite = true;
            });

            // Build features for project, group all entities by schema into a feature
            project.BuildFeatures();

            // Scaffolding =^^=
            project
            .ScaffoldEntityLayer()
            .ScaffoldDataLayer();
        }
        public void ProjectScaffoldingFromWideWorldImportersDatabaseTest()
        {
            // Import database
            var databaseFactory = new SqlServerDatabaseFactory(SqlServerDatabaseFactory.GetLogger())
            {
                DatabaseImportSettings = new DatabaseImportSettings
                {
                    ConnectionString = "server=(local);database=WideWorldImporters;integrated security=yes;",
                    Exclusions       =
                    {
                        "dbo.sysdiagrams"
                    }
                }
            };

            var database = databaseFactory.Import();

            // Create instance of Dapper Project
            var project = new DapperProject
            {
                Name            = "WideWorldImporters.Core",
                Database        = database,
                OutputDirectory = @"C:\Temp\CatFactory.Dapper\WideWorldImporters.Core"
            };

            // Apply settings for project
            project.GlobalSelection(settings => settings.ForceOverwrite = true);

            project.Selection("Warehouse.StockItems", settings => settings.AddPagingForGetAllOperation = true);

            // Build features for project, group all entities by schema into a feature
            project.BuildFeatures();

            // Scaffolding =^^=
            project
            .ScaffoldEntityLayer()
            .ScaffoldDataLayer();
        }
        public void ProjectScaffoldingFromOnLineStoreDatabaseTest()
        {
            // Create database factory
            var databaseFactory = new SqlServerDatabaseFactory(SqlServerDatabaseFactory.GetLogger())
            {
                DatabaseImportSettings = new DatabaseImportSettings
                {
                    ConnectionString     = "server=(local);database=OnlineStore;integrated security=yes;",
                    ImportTableFunctions = true,
                    Exclusions           =
                    {
                        "dbo.sysdiagrams",
                        "dbo.fn_diagramobjects"
                    }
                }
            };

            // Import database
            var database = databaseFactory.Import();

            // Create instance of Dapper Project
            var project = new DapperProject
            {
                Name            = "OnlineStore.Core",
                Database        = database,
                OutputDirectory = @"C:\Temp\CatFactory.Dapper\OnlineStore.Core"
            };

            // Apply settings for project
            project.GlobalSelection(settings =>
            {
                settings.ForceOverwrite   = true;
                settings.UpdateExclusions = new List <string> {
                    "CreationUser", "CreationDateTime", "Timestamp"
                };
                settings.InsertExclusions = new List <string> {
                    "LastUpdateUser", "LastUpdateDateTime", "Timestamp"
                };
            });

            project.Selection("Sales.*", settings =>
            {
                //settings.UseStringBuilderForQueries = false;
                settings.AddPagingForGetAllOperation = true;
            });

            //project.Selection("Sales.OrderHeader", settings => settings.AddPagingForGetAllOperation = true);

            // Build features for project, group all entities by schema into a feature
            project.BuildFeatures();

            // Add event handlers to before and after of scaffold

            project.ScaffoldingDefinition += (source, args) =>
            {
                // Add code to perform operations with code builder instance before to create code file
            };

            project.ScaffoldedDefinition += (source, args) =>
            {
                // Add code to perform operations after of create code file
            };

            // Scaffolding =^^=
            project
            .ScaffoldEntityLayer()
            .ScaffoldDataLayer();
        }