• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / RepoAutomation / 3895898324

pending completion
3895898324

push

github

GitHub
Merge pull request #212 from samsmithnz/FixToLanguageTest

333 of 474 branches covered (70.25%)

Branch coverage included in aggregate %.

795 of 893 relevant lines covered (89.03%)

6.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.44
/src/RepoAutomation.Core/Helpers/DotNet.cs
1
using System.Text;
2

3
namespace RepoAutomation.Core.Helpers
4
{
5
    public static class DotNet
6
    {
7
        public static string CloneRepo(string repoLocation, string repository,
8
            string workingDirectory)
9
        {
3✔
10
            StringBuilder log = new();
3✔
11
            if (!Directory.Exists(workingDirectory))
3!
12
            {
×
13
                Directory.CreateDirectory(workingDirectory);
×
14
            }
×
15
            //the project folder in the working directory
16
            //string workingDirectoryWithRepo = workingDirectory + "\\" + repository;
17

18
            //Clone the code from the repo
19
            Console.WriteLine("Cloning repo '" + repository + "' to " + workingDirectory);
3✔
20
            log.Append(CommandLine.RunCommand("git",
3✔
21
                "clone " + repoLocation,
3✔
22
                workingDirectory));
3✔
23

24
            return log.ToString();
3✔
25
        }
3✔
26

27
        public static string SetupDotnetProjects(string repository, string workingDirectory,
28
            string projectTypes)
29
        {
1✔
30
            StringBuilder log = new();
1✔
31

32
            //Split out the project types
33
            Dictionary<string, string> projectsToCreate = CreateProjectTypeArray(projectTypes);
1✔
34

35
            //the project folder in the working directory
36
            string workingDirectoryWithRepo = workingDirectory + "\\" + repository;
1✔
37

38
            //Create a src folder
39
            string workingSrcDirectory = workingDirectoryWithRepo + "/src";
1✔
40
            if (!Directory.Exists(workingSrcDirectory))
1✔
41
            {
1✔
42
                Console.WriteLine("Creating directory '" + workingSrcDirectory + "'");
1✔
43
                Directory.CreateDirectory(workingSrcDirectory);
1✔
44
            }
1✔
45

46
            //Create each project
47
            foreach (KeyValuePair<string, string> item in projectsToCreate)
7✔
48
            {
2✔
49
                Console.WriteLine("Creating " + item.Key + " project " + repository + item.Value);
2✔
50
                log.Append(CommandLine.RunCommand("dotnet",
2✔
51
                    "new " + item.Key + " -n " + repository + item.Value, //e.g. new mstest -n MyProject.Tests
2✔
52
                    workingSrcDirectory));
2✔
53
            }
2✔
54

55
            //Create the solution file in the src folder
56
            string solutionName = repository;
1✔
57
            Console.WriteLine("Creating solution");
1✔
58
            log.Append(CommandLine.RunCommand("dotnet",
1✔
59
                "new sln --name " + solutionName,
1✔
60
                workingSrcDirectory));
1✔
61

62
            //Bind the previously created projects to the solution
63
            foreach (KeyValuePair<string, string> item in projectsToCreate)
7✔
64
            {
2✔
65
                log.Append(CommandLine.RunCommand("dotnet",
2✔
66
                    "sln add " + repository + item.Value,
2✔
67
                    workingSrcDirectory));
2✔
68
            }
2✔
69

70
            string solutionText = File.ReadAllText(workingSrcDirectory + "/" + solutionName + ".sln");
1✔
71
            log.Append(solutionText);
1✔
72

73
            return log.ToString();
1✔
74
        }
1✔
75

76
        public static Dictionary<string, string> CreateProjectTypeArray(string projectTypes)
77
        {
5✔
78
            Dictionary<string, string> projectsToCreate = new();
5✔
79
            if (!string.IsNullOrEmpty(projectTypes))
5✔
80
            {
2✔
81
                string[] projectsArray = projectTypes.Replace(" ", "").Split(',');
2✔
82
                foreach (string project in projectsArray)
16✔
83
                {
5✔
84
                    switch (project)
5!
85
                    {
86
                        case "mstest":
87
                        case "nunit":
88
                        case "nunit-test":
89
                        case "xunit":
90
                            projectsToCreate.Add(project, ".Tests");
2✔
91
                            break;
2✔
92

93
                        case "console":
94
                        case "classlib":
95
                            projectsToCreate.Add(project, "");
1✔
96
                            break;
1✔
97

98
                        case "wpf":
99
                            projectsToCreate.Add(project, ".WPF");
×
100
                            break;
×
101

102
                        case "winforms":
103
                            projectsToCreate.Add(project, ".Winforms");
×
104
                            break;
×
105

106
                        case "web":
107
                        case "mvc":
108
                        case "webapp":
109
                        case "razor":
110
                        case "angular":
111
                        case "react":
112
                        case "blazorserver":
113
                            projectsToCreate.Add(project, ".Web");
2✔
114
                            break;
2✔
115

116

117
                        case "webapi":
118
                        case "grpc":
119
                            projectsToCreate.Add(project, ".Service");
×
120
                            break;
×
121

122
                        default:
123
                            throw new Exception(project + " is an unknown or currently unsupported .NET project type;");
×
124
                    }
125
                }
5✔
126
            }
2✔
127
            return projectsToCreate;
5✔
128
        }
5✔
129

130
    }
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc