Beispiel #1
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 TestDapperProject()
        {
            // Arrange
            var project = new DapperProject
            {
                Name            = "Store",
                Database        = StoreDatabase.Mock,
                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.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) ?? 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);
        }
        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);
        }
Beispiel #4
0
        public void ProjectScaffoldingFromAdventureWorksDatabaseTest()
        {
            // Import database
            var factory = new SqlServerDatabaseFactory(LoggerMocker.GetLogger <SqlServerDatabaseFactory>())
            {
                ConnectionString = "server=(local);database=AdventureWorks2017;integrated security=yes;",
                ImportSettings   = new DatabaseImportSettings
                {
                    Exclusions = new List <string> {
                        "dbo.sysdiagrams"
                    },
                    ExclusionTypes = new List <string> {
                        "geography"
                    },
                    ImportTableFunctions  = true,
                    ImportScalarFunctions = 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);

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

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

            // Scaffolding =^^=
            project
            .ScaffoldEntityLayer()
            .ScaffoldDataLayer();
        }
        public void TestProjectSelectionScope()
        {
            // Arrange

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

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

            // Act

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

            project.Select("Sales.Order", settings => settings.UseStringBuilderForQueries = false);

            var order = database.FindTable("Sales.Order");

            var selectionForOrder = project.GetSelection(order);

            // Assert

            Assert.True(project.Selections.Count == 2);

            Assert.True(project.GlobalSelection().Settings.UseStringBuilderForQueries == true);
            Assert.True(selectionForOrder.Settings.UseStringBuilderForQueries == false);
        }