Example #1
0
        private static void RunTemplateBuilders(string solutionDirectory, ApiTemplate template, IFileSystem fileSystem)
        {
            // dbcontext
            DbContextBuilder.CreateDbContext(solutionDirectory, template.Entities, template.DbContext.ContextName, template.DbContext.Provider, template.DbContext.DatabaseName);

            //entities
            foreach (var entity in template.Entities)
            {
                EntityBuilder.CreateEntity(solutionDirectory, entity, fileSystem);
                DtoBuilder.CreateDtos(solutionDirectory, entity);

                RepositoryBuilder.AddRepository(solutionDirectory, entity, template.DbContext);
                ValidatorBuilder.CreateValidators(solutionDirectory, entity);
                ProfileBuilder.CreateProfile(solutionDirectory, entity);

                ControllerBuilder.CreateController(solutionDirectory, entity, template.SwaggerConfig.AddSwaggerComments, template.AuthorizationSettings.Policies);

                FakesBuilder.CreateFakes(solutionDirectory, template.SolutionName, entity);
                ReadTestBuilder.CreateEntityReadTests(solutionDirectory, template.SolutionName, entity, template.DbContext.ContextName);
                GetTestBuilder.CreateEntityGetTests(solutionDirectory, template.SolutionName, entity, template.DbContext.ContextName, template.AuthorizationSettings.Policies);
                PostTestBuilder.CreateEntityWriteTests(solutionDirectory, entity, template.SolutionName, template.AuthorizationSettings.Policies);
                UpdateTestBuilder.CreateEntityUpdateTests(solutionDirectory, entity, template.SolutionName, template.DbContext.ContextName, template.AuthorizationSettings.Policies);
                DeleteIntegrationTestBuilder.CreateEntityDeleteTests(solutionDirectory, entity, template.SolutionName, template.DbContext.ContextName, template.AuthorizationSettings.Policies);
                DeleteTestBuilder.DeleteEntityWriteTests(solutionDirectory, entity, template.SolutionName, template.DbContext.ContextName);
                WebAppFactoryBuilder.CreateWebAppFactory(solutionDirectory, template.SolutionName, template.DbContext.ContextName, template.AddJwtAuthentication);
            }

            // environments
            Utilities.AddStartupEnvironmentsWithServices(
                solutionDirectory,
                template.SolutionName,
                template.DbContext.DatabaseName,
                template.Environments,
                template.SwaggerConfig,
                template.Port,
                template.AddJwtAuthentication
                );

            //seeders
            SeederBuilder.AddSeeders(solutionDirectory, template.Entities, template.DbContext.ContextName);

            //services
            SwaggerBuilder.AddSwagger(solutionDirectory, template.SwaggerConfig, template.SolutionName, template.AddJwtAuthentication, template.AuthorizationSettings.Policies);

            if (template.AddJwtAuthentication)
            {
                InfrastructureIdentityServiceRegistrationBuilder.CreateInfrastructureIdentityServiceExtension(solutionDirectory, template.AuthorizationSettings.Policies, fileSystem);
            }

            //final
            ReadmeBuilder.CreateReadme(solutionDirectory, template.SolutionName, fileSystem);

            if (template.AddGit)
            {
                GitSetup(solutionDirectory);
            }
        }
Example #2
0
        private static void RunTemplateBuilders(string solutionDirectory, ApiTemplate template, IFileSystem fileSystem)
        {
            // dbcontext
            DbContextBuilder.CreateDbContext(solutionDirectory, template);

            //entities
            foreach (var entity in template.Entities)
            {
                EntityBuilder.CreateEntity(solutionDirectory, entity, fileSystem);
                DtoBuilder.CreateDtos(solutionDirectory, entity);

                RepositoryBuilder.AddRepository(solutionDirectory, entity, template.DbContext);
                ValidatorBuilder.CreateValidators(solutionDirectory, entity);
                ProfileBuilder.CreateProfile(solutionDirectory, entity);

                ControllerBuilder.CreateController(solutionDirectory, entity);

                FakesBuilder.CreateFakes(solutionDirectory, template, entity);
                ReadTestBuilder.CreateEntityReadTests(solutionDirectory, template, entity);
                GetTestBuilder.CreateEntityGetTests(solutionDirectory, template, entity);
                PostTestBuilder.CreateEntityWriteTests(solutionDirectory, template, entity);
                UpdateTestBuilder.CreateEntityUpdateTests(solutionDirectory, template, entity);
                DeleteTestBuilder.DeleteEntityWriteTests(solutionDirectory, template, entity);
                WebAppFactoryBuilder.CreateWebAppFactory(solutionDirectory, template, entity);
            }

            // environments
            AddStartupEnvironmentsWithServices(solutionDirectory, template);

            //seeders
            SeederBuilder.AddSeeders(solutionDirectory, template);

            //services
            SwaggerBuilder.AddSwagger(solutionDirectory, template);

            if (template.AuthSetup.AuthMethod == "JWT")
            {
                IdentityServicesModifier.SetIdentityOptions(solutionDirectory, template.AuthSetup);
                IdentitySeederBuilder.AddSeeders(solutionDirectory, template);
                IdentityRoleBuilder.CreateRoles(solutionDirectory, template.AuthSetup.Roles);
                RoleSeedBuilder.SeedRoles(solutionDirectory, template);
            }

            //final
            ReadmeBuilder.CreateReadme(solutionDirectory, template, fileSystem);

            if (template.AddGit)
            {
                GitSetup(solutionDirectory);
            }
        }
Example #3
0
        private static void RunTemplateBuilders(string rootDirectory, string srcDirectory, string testDirectory, ApiTemplate template, IFileSystem fileSystem, Verbosity verbosity)
        {
            // dbcontext
            DbContextBuilder.CreateDbContext(srcDirectory, template.Entities, template.DbContext.ContextName, template.DbContext.Provider, template.DbContext.DatabaseName, template.SolutionName);
            if (verbosity == Verbosity.More)
            {
                WriteHelpText($"{template.SolutionName} db context was scaffolded successfully.");
            }

            //entities
            EntityScaffolding.ScaffoldEntities(srcDirectory,
                                               testDirectory,
                                               template.SolutionName,
                                               template.Entities,
                                               template.DbContext.ContextName,
                                               template.SwaggerConfig.AddSwaggerComments,
                                               template.AuthorizationSettings.Policies,
                                               fileSystem,
                                               verbosity);

            // environments
            Utilities.AddStartupEnvironmentsWithServices(
                srcDirectory,
                template.SolutionName,
                template.DbContext.DatabaseName,
                template.Environments,
                template.SwaggerConfig,
                template.Port,
                template.AddJwtAuthentication,
                template.SolutionName
                );
            if (verbosity == Verbosity.More)
            {
                WriteHelpText($"{template.SolutionName} startup environments were scaffolded successfully.");
            }

            // unit tests, test utils, and one offs
            PagedListTestBuilder.CreateTests(testDirectory, template.SolutionName);
            IntegrationTestFixtureBuilder.CreateFixture(testDirectory, template.SolutionName, template.DbContext.ContextName, template.DbContext.DatabaseName, template.DbContext.Provider, fileSystem);
            IntegrationTestBaseBuilder.CreateBase(testDirectory, template.SolutionName, template.DbContext.Provider, fileSystem);
            DockerDatabaseUtilitiesBuilder.CreateClass(testDirectory, template.SolutionName, template.DbContext.Provider, fileSystem);
            ApiRoutesBuilder.CreateClass(testDirectory, template.SolutionName, template.Entities, fileSystem);
            WebAppFactoryBuilder.CreateWebAppFactory(testDirectory, template.SolutionName, template.DbContext.ContextName, template.AddJwtAuthentication);
            FunctionalTestBaseBuilder.CreateBase(testDirectory, template.SolutionName, template.DbContext.ContextName, fileSystem);
            HealthTestBuilder.CreateTests(testDirectory, template.SolutionName);
            HttpClientExtensionsBuilder.Create(testDirectory, template.SolutionName);

            if (verbosity == Verbosity.More)
            {
                WriteHelpText($"{template.SolutionName} unit tests and testing utilities were scaffolded successfully.");
            }

            //seeders
            SeederBuilder.AddSeeders(srcDirectory, template.Entities, template.DbContext.ContextName, template.SolutionName);
            if (verbosity == Verbosity.More)
            {
                WriteHelpText($"{template.SolutionName} seeders were scaffolded successfully.");
            }

            //services
            // TODO move the auth stuff to a modifier to make it SOLID so i can add it to an add auth command
            SwaggerBuilder.AddSwagger(srcDirectory, template.SwaggerConfig, template.SolutionName, template.AddJwtAuthentication, template.AuthorizationSettings.Policies, template.SolutionName);

            if (verbosity == Verbosity.More)
            {
                WriteHelpText($"{template.SolutionName} swagger setup was scaffolded successfully.");
            }

            if (template.AddJwtAuthentication)
            {
                InfrastructureServiceRegistrationModifier.InitializeAuthServices(srcDirectory, template.SolutionName, template.AuthorizationSettings.Policies);
                if (verbosity == Verbosity.More)
                {
                    WriteHelpText($"{template.SolutionName} auth helpers were scaffolded successfully.");
                }
            }

            ReadmeBuilder.CreateBoundedContextReadme(rootDirectory, template.SolutionName, srcDirectory, fileSystem);
            if (verbosity == Verbosity.More)
            {
                WriteHelpText($"{template.SolutionName} readme was scaffolded successfully.");
            }
        }
Example #4
0
        private static void RunTemplateBuilders(string boundedContextDirectory, string srcDirectory, string testDirectory, ApiTemplate template, IFileSystem fileSystem)
        {
            var projectBaseName = template.ProjectName;

            // get solution dir from bcDir
            var solutionDirectory = Directory.GetParent(boundedContextDirectory)?.FullName;

            Utilities.IsSolutionDirectoryGuard(solutionDirectory);

            // base files needed before below is ran
            DbContextBuilder.CreateDbContext(srcDirectory,
                                             template.Entities,
                                             template.DbContext.ContextName,
                                             template.DbContext.Provider,
                                             template.DbContext.DatabaseName,
                                             template.DbContext.NamingConventionEnum,
                                             template.UseSoftDelete,
                                             projectBaseName,
                                             fileSystem
                                             );
            ApiRoutesBuilder.CreateClass(testDirectory, projectBaseName, fileSystem);

            if (template.AddJwtAuthentication)
            {
                PermissionsBuilder.GetPermissions(srcDirectory, projectBaseName, fileSystem); // <-- needs to run before entity features
                RolesBuilder.GetRoles(solutionDirectory, fileSystem);
                UserPolicyHandlerBuilder.CreatePolicyBuilder(solutionDirectory, srcDirectory, projectBaseName, fileSystem);
                InfrastructureServiceRegistrationModifier.InitializeAuthServices(srcDirectory, projectBaseName);
                EntityScaffolding.ScaffoldRolePermissions(solutionDirectory,
                                                          srcDirectory,
                                                          testDirectory,
                                                          projectBaseName,
                                                          template.DbContext.ContextName,
                                                          template.SwaggerConfig.AddSwaggerComments,
                                                          template.UseSoftDelete,
                                                          fileSystem);
            }

            //entities
            EntityScaffolding.ScaffoldEntities(solutionDirectory,
                                               srcDirectory,
                                               testDirectory,
                                               projectBaseName,
                                               template.Entities,
                                               template.DbContext.ContextName,
                                               template.SwaggerConfig.AddSwaggerComments,
                                               template.UseSoftDelete,
                                               fileSystem);

            // environments
            Utilities.AddStartupEnvironmentsWithServices(
                srcDirectory,
                projectBaseName,
                template.DbContext.DatabaseName,
                template.Environments,
                template.SwaggerConfig,
                template.Port,
                template.AddJwtAuthentication,
                projectBaseName,
                fileSystem
                );

            // unit tests, test utils, and one offs∂
            PagedListTestBuilder.CreateTests(srcDirectory, testDirectory, projectBaseName);
            IntegrationTestFixtureBuilder.CreateFixture(testDirectory, projectBaseName, template.DbContext.ContextName, template.DbContext.DatabaseName, template.DbContext.Provider, fileSystem);
            IntegrationTestBaseBuilder.CreateBase(testDirectory, projectBaseName, template.DbContext.Provider, fileSystem);
            DockerUtilitiesBuilder.CreateGeneralUtilityClass(testDirectory, projectBaseName, template.DbContext.Provider, fileSystem);
            DockerUtilitiesBuilder.CreateDockerDatabaseUtilityClass(testDirectory, projectBaseName, template.DbContext.Provider, fileSystem);
            WebAppFactoryBuilder.CreateWebAppFactory(testDirectory, projectBaseName, template.DbContext.ContextName, template.AddJwtAuthentication);
            FunctionalTestBaseBuilder.CreateBase(testDirectory, projectBaseName, template.DbContext.ContextName, fileSystem);
            HealthTestBuilder.CreateTests(testDirectory, projectBaseName, fileSystem);
            HttpClientExtensionsBuilder.Create(testDirectory, projectBaseName);
            EntityBuilder.CreateBaseEntity(srcDirectory, projectBaseName, template.UseSoftDelete, fileSystem);
            CurrentUserServiceTestBuilder.CreateTests(testDirectory, projectBaseName, fileSystem);

            //seeders
            SeederBuilder.AddSeeders(srcDirectory, template.Entities, template.DbContext.ContextName, projectBaseName);

            //services
            CurrentUserServiceBuilder.GetCurrentUserService(srcDirectory, projectBaseName, fileSystem);
            SwaggerBuilder.AddSwagger(srcDirectory, template.SwaggerConfig, template.ProjectName, template.AddJwtAuthentication, template.PolicyName, projectBaseName, fileSystem);

            DockerBuilders.CreateDockerfile(srcDirectory, projectBaseName, fileSystem);
            DockerBuilders.CreateDockerIgnore(srcDirectory, projectBaseName, fileSystem);

            if (template.Bus.AddBus)
            {
                AddBusCommand.AddBus(template.Bus, srcDirectory, testDirectory, projectBaseName, solutionDirectory, fileSystem);
            }

            if (template.Consumers.Count > 0)
            {
                AddConsumerCommand.AddConsumers(template.Consumers, projectBaseName, solutionDirectory, srcDirectory, testDirectory, fileSystem);
            }

            if (template.Producers.Count > 0)
            {
                AddProducerCommand.AddProducers(template.Producers, projectBaseName, solutionDirectory, srcDirectory, testDirectory, fileSystem);
            }

            DockerBuilders.AddBoundaryToDockerCompose(solutionDirectory, template.DockerConfig);
        }
Example #5
0
        private static void RunTemplateBuilders(string boundedContextDirectory, string srcDirectory, string testDirectory, ApiTemplate template, IFileSystem fileSystem)
        {
            var projectBaseName = template.ProjectName;

            // get solution dir from bcDir
            var solutionDirectory = Directory.GetParent(boundedContextDirectory)?.FullName;

            Utilities.IsSolutionDirectoryGuard(solutionDirectory);

            // base files needed before below is ran
            DbContextBuilder.CreateDbContext(srcDirectory,
                                             template.Entities,
                                             template.DbContext.ContextName,
                                             template.DbContext.Provider,
                                             template.DbContext.DatabaseName,
                                             template.DbContext.NamingConventionEnum,
                                             projectBaseName,
                                             fileSystem
                                             );
            ApiRoutesBuilder.CreateClass(testDirectory, projectBaseName, fileSystem);

            //entities
            EntityScaffolding.ScaffoldEntities(srcDirectory,
                                               testDirectory,
                                               projectBaseName,
                                               template.Entities,
                                               template.DbContext.ContextName,
                                               template.SwaggerConfig.AddSwaggerComments,
                                               fileSystem);

            // environments
            Utilities.AddStartupEnvironmentsWithServices(
                srcDirectory,
                projectBaseName,
                template.DbContext.DatabaseName,
                template.Environments,
                template.SwaggerConfig,
                template.Port,
                template.AddJwtAuthentication,
                projectBaseName,
                fileSystem
                );

            // unit tests, test utils, and one offs
            PagedListTestBuilder.CreateTests(testDirectory, projectBaseName);
            IntegrationTestFixtureBuilder.CreateFixture(testDirectory, projectBaseName, template.DbContext.ContextName, template.DbContext.DatabaseName, template.DbContext.Provider, fileSystem);
            IntegrationTestBaseBuilder.CreateBase(testDirectory, projectBaseName, template.DbContext.Provider, fileSystem);
            DockerUtilitiesBuilder.CreateGeneralUtilityClass(testDirectory, projectBaseName, template.DbContext.Provider, fileSystem);
            DockerUtilitiesBuilder.CreateDockerDatabaseUtilityClass(testDirectory, projectBaseName, template.DbContext.Provider, fileSystem);
            WebAppFactoryBuilder.CreateWebAppFactory(testDirectory, projectBaseName, template.DbContext.ContextName, template.AddJwtAuthentication);
            FunctionalTestBaseBuilder.CreateBase(testDirectory, projectBaseName, template.DbContext.ContextName, fileSystem);
            HealthTestBuilder.CreateTests(testDirectory, projectBaseName, fileSystem);
            HttpClientExtensionsBuilder.Create(testDirectory, projectBaseName);
            EntityBuilder.CreateBaseEntity(srcDirectory, projectBaseName, fileSystem);
            CurrentUserServiceTestBuilder.CreateTests(testDirectory, projectBaseName, fileSystem);

            //seeders
            SeederBuilder.AddSeeders(srcDirectory, template.Entities, template.DbContext.ContextName, projectBaseName);

            //services
            CurrentUserServiceBuilder.GetCurrentUserService(srcDirectory, projectBaseName, fileSystem);

            // TODO move the auth stuff to a modifier to make it SOLID so i can add it to an add auth command
            var policies = template.Entities
                           .SelectMany(entity => entity.Features)
                           .SelectMany(feature => feature.Policies)
                           .ToList();

            SwaggerBuilder.AddSwagger(srcDirectory, template.SwaggerConfig, projectBaseName, template.AddJwtAuthentication, policies, projectBaseName, fileSystem);
            if (template.AddJwtAuthentication)
            {
                InfrastructureServiceRegistrationModifier.InitializeAuthServices(srcDirectory, projectBaseName, policies);
                foreach (var feature in template.Entities.SelectMany(entity => entity.Features))
                {
                    InfrastructureServiceRegistrationModifier.AddPolicies(srcDirectory, feature.Policies, projectBaseName);
                }
            }

            if (template.Bus.AddBus)
            {
                AddBusCommand.AddBus(template.Bus, srcDirectory, testDirectory, projectBaseName, solutionDirectory, fileSystem);
            }

            if (template.Consumers.Count > 0)
            {
                AddConsumerCommand.AddConsumers(template.Consumers, projectBaseName, srcDirectory, testDirectory, fileSystem);
            }

            if (template.Producers.Count > 0)
            {
                AddProducerCommand.AddProducers(template.Producers, projectBaseName, srcDirectory);
            }
        }
Example #6
0
        private static void RunMicroTemplateBuilders(string solutionDirectory, List <Microservice> microservices, List <Gateway> gateways, IFileSystem fileSystem)
        {
            // services path
            var servicesPath = Path.Combine(solutionDirectory, "services");

            fileSystem.Directory.CreateDirectory(servicesPath);

            foreach (var micro in microservices)
            {
                // set micro path
                var microPath = Path.Combine(servicesPath, micro.ProjectFolderName);

                // add projects
                SolutionBuilder.AddMicroServicesProjects(solutionDirectory, microPath, micro.DbContext.Provider, micro.ProjectFolderName, micro.AddJwtAuthentication, fileSystem);

                // dbcontext
                DbContextBuilder.CreateDbContext(microPath, micro.Entities, micro.DbContext.ContextName, micro.DbContext.Provider, micro.DbContext.DatabaseName);

                //entities
                foreach (var entity in micro.Entities)
                {
                    EntityBuilder.CreateEntity(microPath, entity, fileSystem);
                    DtoBuilder.CreateDtos(microPath, entity);

                    RepositoryBuilder.AddRepository(microPath, entity, micro.DbContext);
                    ValidatorBuilder.CreateValidators(microPath, entity);
                    ProfileBuilder.CreateProfile(microPath, entity);

                    ControllerBuilder.CreateController(microPath, entity, micro.SwaggerConfig.AddSwaggerComments, micro.AuthorizationSettings.Policies);

                    FakesBuilder.CreateFakes(microPath, micro.ProjectFolderName, entity);
                    ReadTestBuilder.CreateEntityReadTests(microPath, micro.ProjectFolderName, entity, micro.DbContext.ContextName);
                    GetTestBuilder.CreateEntityGetTests(microPath, micro.ProjectFolderName, entity, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    PostTestBuilder.CreateEntityWriteTests(microPath, entity, micro.ProjectFolderName, micro.AuthorizationSettings.Policies);
                    UpdateTestBuilder.CreateEntityUpdateTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    DeleteIntegrationTestBuilder.CreateEntityDeleteTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    DeleteTestBuilder.DeleteEntityWriteTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName);
                    WebAppFactoryBuilder.CreateWebAppFactory(microPath, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AddJwtAuthentication);
                }


                // environments
                Utilities.AddStartupEnvironmentsWithServices(
                    microPath,
                    micro.ProjectFolderName,
                    micro.DbContext.DatabaseName,
                    micro.Environments,
                    micro.SwaggerConfig,
                    micro.Port,
                    micro.AddJwtAuthentication
                    );

                //seeders
                SeederBuilder.AddSeeders(microPath, micro.Entities, micro.DbContext.ContextName);

                //services
                SwaggerBuilder.AddSwagger(microPath, micro.SwaggerConfig, micro.ProjectFolderName, micro.AddJwtAuthentication, micro.AuthorizationSettings.Policies);

                if (micro.AddJwtAuthentication)
                {
                    InfrastructureIdentityServiceRegistrationBuilder.CreateInfrastructureIdentityServiceExtension(microPath, micro.AuthorizationSettings.Policies, fileSystem);
                }
            }

            // gateway path
            var gatewayPath = Path.Combine(solutionDirectory, "gateways");

            fileSystem.Directory.CreateDirectory(gatewayPath);

            foreach (var gateway in gateways)
            {
                SolutionBuilder.AddGatewayProject(solutionDirectory, gatewayPath, gateway.GatewayProjectName, fileSystem);

                foreach (var env in gateway.EnvironmentGateways)
                {
                    //TODO: run quality checks that profile name exists, gateway url is a valid path and https, Env Name

                    if (env.EnvironmentName != "Startup")
                    {
                        StartupBuilder.CreateGatewayStartup(gatewayPath, env.EnvironmentName, gateway.GatewayProjectName);
                    }

                    GatewayAppSettingsBuilder.CreateAppSettings(gatewayPath, env, gateway.GatewayProjectName, microservices);
                    GatewayLaunchSettingsModifier.AddProfile(gatewayPath, env, gateway.GatewayProjectName);
                }
            }
        }