Exemplo n.º 1
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);
        }
Exemplo n.º 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);
        }