예제 #1
0
파일: Utilities.cs 프로젝트: p3s/craftsman
        private static bool RunDbMigration(ApiTemplate template, string srcDirectory)
        {
            var webApiProjectClassPath = ClassPathHelper.WebApiProjectClassPath(srcDirectory, template.ProjectName);

            return(ExecuteProcess(
                       "dotnet",
                       @$ "ef migrations add " "InitialMigration" " --project " "{webApiProjectClassPath.FullClassPath}" "",
                       srcDirectory,
                       new Dictionary <string, string>()
            {
                { "ASPNETCORE_ENVIRONMENT", Guid.NewGuid().ToString() }     // guid to not conflict with any given envs
            },
                       20000,
                       $"{Emoji.Known.Warning} {template.ProjectName} Database Migrations timed out and will need to be run manually"));
        }
예제 #2
0
        private static void RunDbMigration(ApiTemplate template, string srcDirectory)
        {
            var webApiProjectClassPath = ClassPathHelper.WebApiProjectClassPath(srcDirectory, template.SolutionName);
            var infraProjectClassPath  = ClassPathHelper.InfrastructureProjectClassPath(srcDirectory, template.SolutionName);

            Utilities.ExecuteProcess(
                "dotnet",
                @$ "ef migrations add " "InitialMigration" " --project " "{infraProjectClassPath.FullClassPath}" " --startup-project " "{webApiProjectClassPath.FullClassPath}" " --output-dir Migrations",
                srcDirectory,
                new Dictionary <string, string>()
            {
                { "ASPNETCORE_ENVIRONMENT", Guid.NewGuid().ToString() }     // guid to not conflict with any given envs
            },
                20000,
                "Db Migrations timed out and will need to be run manually.");
        }
예제 #3
0
파일: Utilities.cs 프로젝트: p3s/craftsman
        public static string GetDbContext(string srcDirectory, string projectBaseName)
        {
            var classPath        = ClassPathHelper.DbContextClassPath(srcDirectory, $"", projectBaseName);
            var directoryClasses = Directory.GetFiles(classPath.FullClassPath, "*.cs");

            foreach (var directoryClass in directoryClasses)
            {
                using var input = File.OpenText(directoryClass);
                string line;
                while (null != (line = input.ReadLine()))
                {
                    if (line.Contains($": DbContext"))
                    {
                        return(Path.GetFileNameWithoutExtension(directoryClass));
                    }
                }
            }

            return("");
        }
예제 #4
0
        public static void AddFeatureToProject(string srcDirectory, string testDirectory, string projectBaseName,
                                               string dbContextName, bool addSwaggerComments, List <Policy> policies, Feature feature, Entity entity,
                                               IFileSystem fileSystem)
        {
            var controllerClassPath = ClassPathHelper.ControllerClassPath(srcDirectory, $"{Utilities.GetControllerName(entity.Plural)}.cs", projectBaseName);

            if (!File.Exists(controllerClassPath.FullClassPath))
            {
                ControllerBuilder.CreateController(srcDirectory, entity.Name, entity.Plural, projectBaseName);
            }

            if (feature.Type == FeatureType.AddRecord.Name)
            {
                CommandAddRecordBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName);
                AddCommandTestBuilder.CreateTests(testDirectory, entity, projectBaseName);
                CreateEntityTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName, fileSystem);
                ControllerModifier.AddEndpoint(srcDirectory, FeatureType.AddRecord, entity, addSwaggerComments, policies,
                                               feature, projectBaseName);
            }

            if (feature.Type == FeatureType.GetRecord.Name)
            {
                QueryGetRecordBuilder.CreateQuery(srcDirectory, entity, dbContextName, projectBaseName);
                GetRecordQueryTestBuilder.CreateTests(testDirectory, entity, projectBaseName);
                GetEntityRecordTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName, fileSystem);
                ControllerModifier.AddEndpoint(srcDirectory, FeatureType.GetRecord, entity, addSwaggerComments, policies,
                                               feature, projectBaseName);
            }

            if (feature.Type == FeatureType.GetList.Name)
            {
                QueryGetListBuilder.CreateQuery(srcDirectory, entity, dbContextName, projectBaseName);
                GetListQueryTestBuilder.CreateTests(testDirectory, entity, projectBaseName);
                GetEntityListTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName, fileSystem);
                ControllerModifier.AddEndpoint(srcDirectory, FeatureType.GetList, entity, addSwaggerComments, policies,
                                               feature, projectBaseName);
            }

            if (feature.Type == FeatureType.DeleteRecord.Name)
            {
                CommandDeleteRecordBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName);
                DeleteCommandTestBuilder.CreateTests(testDirectory, entity, projectBaseName);
                DeleteEntityTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName, fileSystem);
                ControllerModifier.AddEndpoint(srcDirectory, FeatureType.DeleteRecord, entity, addSwaggerComments, policies,
                                               feature, projectBaseName);
            }

            if (feature.Type == FeatureType.UpdateRecord.Name)
            {
                CommandUpdateRecordBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName);
                PutCommandTestBuilder.CreateTests(testDirectory, entity, projectBaseName);
                PutEntityTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName, fileSystem);
                ControllerModifier.AddEndpoint(srcDirectory, FeatureType.UpdateRecord, entity, addSwaggerComments, policies,
                                               feature, projectBaseName);
            }

            if (feature.Type == FeatureType.PatchRecord.Name)
            {
                CommandPatchRecordBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName);
                PatchCommandTestBuilder.CreateTests(testDirectory, entity, projectBaseName, fileSystem);
                PatchEntityTestBuilder.CreateTests(testDirectory, entity, policies, projectBaseName, fileSystem);
                ControllerModifier.AddEndpoint(srcDirectory, FeatureType.PatchRecord, entity, addSwaggerComments, policies,
                                               feature, projectBaseName);
            }

            if (feature.Type == FeatureType.AddListByFk.Name)
            {
                CommandAddListBuilder.CreateCommand(srcDirectory, entity, dbContextName, projectBaseName, feature, fileSystem);
                AddListCommandTestBuilder.CreateTests(testDirectory, entity, feature, projectBaseName, fileSystem);
                AddListTestBuilder.CreateTests(testDirectory, entity, policies, feature, projectBaseName, fileSystem);
                ControllerModifier.AddEndpoint(srcDirectory, FeatureType.AddListByFk, entity, addSwaggerComments, policies,
                                               feature, projectBaseName);
            }

            if (feature.Type == FeatureType.AdHoc.Name)
            {
                EmptyFeatureBuilder.CreateCommand(srcDirectory, dbContextName, projectBaseName, feature);
                // TODO ad hoc feature endpoint
                // TODO empty failing test to promote test writing?
            }
        }
예제 #5
0
 public static ClassPath GetStartupClassPath(string solutionDirectory, string projectBaseName)
 {
     return(ClassPathHelper.StartupClassPath(solutionDirectory, $"Startup.cs", projectBaseName));
 }