private static void RunEntityBuilders(string solutionDirectory, ApiTemplate template, IFileSystem fileSystem) { //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); 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); } //seeders & dbsets SeederModifier.AddSeeders(solutionDirectory, template); DbContextModifier.AddDbSet(solutionDirectory, template); }
public static void ScaffoldEntities(string srcDirectory, string testDirectory, string projectBaseName, List <Entity> entities, string dbContextName, bool addSwaggerComments, IFileSystem fileSystem) { foreach (var entity in entities) { // not worrying about DTOs, profiles, validators, fakers - they are all added by default EntityBuilder.CreateEntity(srcDirectory, entity, projectBaseName, fileSystem); DtoBuilder.CreateDtos(srcDirectory, entity, projectBaseName); ValidatorBuilder.CreateValidators(srcDirectory, projectBaseName, entity); ProfileBuilder.CreateProfile(srcDirectory, entity, projectBaseName); ApiRouteModifier.AddRoutes(testDirectory, entity, projectBaseName); // api routes always added to testing by default. too much of a pain to scaffold if (entity.Features.Count > 0) { ControllerBuilder.CreateController(srcDirectory, entity.Name, entity.Plural, projectBaseName); } // TODO refactor to factory? foreach (var feature in entity.Features) { AddFeatureToProject(srcDirectory, testDirectory, projectBaseName, dbContextName, addSwaggerComments, feature.Policies, feature, entity, fileSystem); } // Shared Tests FakesBuilder.CreateFakes(testDirectory, projectBaseName, entity); } }
public static void ScaffoldEntities(string solutionDirectory, string srcDirectory, string testDirectory, string projectBaseName, List <Entity> entities, string dbContextName, bool addSwaggerComments, bool useSoftDelete, IFileSystem fileSystem) { foreach (var entity in entities) { // not worrying about DTOs, profiles, validators, fakers - they are all added by default EntityBuilder.CreateEntity(solutionDirectory, srcDirectory, entity, projectBaseName, fileSystem); DtoBuilder.CreateDtos(solutionDirectory, entity, projectBaseName); ValidatorBuilder.CreateValidators(solutionDirectory, srcDirectory, projectBaseName, entity); ProfileBuilder.CreateProfile(srcDirectory, entity, projectBaseName); ApiRouteModifier.AddRoutes(testDirectory, entity, projectBaseName); // api routes always added to testing by default. too much of a pain to scaffold dynamically var isProtected = entity.Features.Any(f => f.IsProtected); // <-- one more example of why it would be nice to have specific endpoints for each feature 😤 if (entity.Features.Count > 0) { ControllerBuilder.CreateController(solutionDirectory, srcDirectory, entity.Name, entity.Plural, projectBaseName, isProtected, fileSystem); } // TODO refactor to factory? foreach (var feature in entity.Features) { AddFeatureToProject(solutionDirectory, srcDirectory, testDirectory, projectBaseName, dbContextName, addSwaggerComments, feature, entity, useSoftDelete, fileSystem); } // Shared Tests FakesBuilder.CreateFakes(solutionDirectory, testDirectory, projectBaseName, entity, fileSystem); } }
private static void RunEntityBuilders(string solutionDirectory, ApiTemplate template, IFileSystem fileSystem) { //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); InfrastructureIdentityServiceRegistrationModifier.AddPolicies(solutionDirectory, 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); } //seeders & dbsets SeederModifier.AddSeeders(solutionDirectory, template.Entities, template.DbContext.ContextName); DbContextModifier.AddDbSet(solutionDirectory, template.Entities, template.DbContext.ContextName); }
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); } }
public static void ScaffoldEntities(string srcDirectory, string testDirectory, string projectBaseName, List <Entity> entities, string dbContextName, bool addSwaggerComments, List <Policy> policies, IFileSystem fileSystem, Verbosity verbosity) { foreach (var entity in entities) { EntityBuilder.CreateEntity(srcDirectory, entity, projectBaseName, fileSystem); DtoBuilder.CreateDtos(srcDirectory, entity, projectBaseName); ValidatorBuilder.CreateValidators(srcDirectory, projectBaseName, entity); ProfileBuilder.CreateProfile(srcDirectory, entity, projectBaseName); QueryGetRecordBuilder.CreateQuery(srcDirectory, entity, dbContextName, projectBaseName); QueryGetListBuilder.CreateQuery(srcDirectory, entity, dbContextName, projectBaseName); CommandAddRecordBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName); CommandDeleteRecordBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName); CommandUpdateRecordBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName); CommandPatchRecordBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName); ControllerBuilder.CreateController(srcDirectory, entity, addSwaggerComments, policies, projectBaseName); // Shared Tests FakesBuilder.CreateFakes(testDirectory, projectBaseName, entity); // Integration Tests AddCommandTestBuilder.CreateTests(testDirectory, entity, projectBaseName); DeleteCommandTestBuilder.CreateTests(testDirectory, entity, projectBaseName); PatchCommandTestBuilder.CreateTests(testDirectory, entity, projectBaseName); GetRecordQueryTestBuilder.CreateTests(testDirectory, entity, projectBaseName); GetListQueryTestBuilder.CreateTests(testDirectory, entity, projectBaseName); PutCommandTestBuilder.CreateTests(testDirectory, entity, projectBaseName); // Functional Tests CreateEntityTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName); DeleteEntityTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName); GetEntityRecordTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName); GetEntityListTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName); PatchEntityTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName); PutEntityTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName); if (verbosity == Verbosity.More) { WriteHelpText($"{projectBaseName} '{entity.Name}' entity was scaffolded successfully."); } } }
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); } }
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); } } }