├── .gitignore
├── README
├── build.proj
├── packages.config
├── src
├── App.config
├── ArgParser.cs
├── Config.cs
├── Package.cs
├── Program.cs
├── commands
│ ├── FetchPackage.cs
│ ├── ICommand.cs
│ ├── MakeBuildFile.cs
│ ├── NewProject.cs
│ └── NewProjectException.cs
├── packages.config
├── templates
│ └── build.proj
└── wrappers
│ ├── DirectoryInfoWrapper.cs
│ ├── FileInfoWrapper.cs
│ └── FileSystem.cs
└── tests
├── integrationtests
└── when_creating_a_new_project.cs
├── mocks
└── MockFileSystem.cs
├── packages.config
└── unittests
├── when_creating_files_using_the_filesystem.cs
├── when_executing_a_command.cs
├── when_executing_the_NewProject_command.cs
├── when_making_a_default_build_file.cs
├── when_parsing_arguments.cs
├── when_there_is_no_config_file_present.cs
└── when_using_a_json_config_file.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | obj
2 | bin
3 | *.csproj.user
4 | *.csproj
5 | *.sln
6 | *.suo
7 | *ReSharper*
8 | *resharper*
9 | *.suo
10 | *.cache
11 | * Thumbs.db
12 | Properties
13 | # Other useful stuff
14 | *.bak
15 | *.cache
16 | *.log
17 | *.swp
18 | *.user
19 | CredDB.DEF
20 | packages
21 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Welcome to the ProjectStarter repository
2 |
3 | ProjectStarter is a simple, opinionated CLi program to help you create an initial directory structure
4 | for your .NET C# projects. It will create a new directory with the name you pass to it containing a src, tests lib, and bin directories.
5 | Initially it will create a build.proj file and README as well.
6 | You can then customize the build.proj file to specify your projects name, the output type, and any references you need.
7 |
8 | Why start with an MSBuild file instead of a Visual Studio solution? You can always create a new VS solution later if you prefer. By creating an MSBuild file first you are instantly set up to use a continuous integration server and can use any IDE you'd like.
9 |
10 |
--------------------------------------------------------------------------------
/build.proj:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | Debug
7 |
8 |
9 |
10 | AnyCPU
11 |
12 |
13 |
14 | false
15 | true
16 | bin\Debug\
17 | bin\Debug\
18 |
19 |
20 |
21 | true
22 | false
23 | bin\Release\
24 | bin\Release
25 | bin\Release\
26 |
27 |
28 |
31 |
32 |
33 |
34 |
35 |
36 | ps
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
70 |
71 |
72 |
73 |
74 |
75 |
80 |
81 |
82 |
83 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/ArgParser.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ProjectStarter {
4 | public class ArgParser {
5 | private const string _defaultConfig = @"{ ""RootDirectory"": ""New Project"", ""SubDirectories"": [""src"", ""lib"",""docs"",""tests"", ""configs"",""packages""] }";
6 |
7 |
8 | public ICommand Command { get; set; }
9 | public IConfig ProjectConfig { get; set; }
10 |
11 | public ArgParser(string[] args, IFileSystem FileSystem) {
12 | if (FileSystem == null) { throw new ArgumentNullException("FileSystem can not be null"); };
13 | string configFileContents = FileSystem.ReadFile("default.json");
14 | if(String.IsNullOrEmpty(configFileContents)) {
15 | FileSystem.CreateFile("default.json",_defaultConfig);
16 | configFileContents = _defaultConfig;
17 | }
18 | ProjectConfig = Config.LoadConfig(configFileContents);
19 | if(args != null && !String.IsNullOrEmpty(args[0])) {
20 | Command = new NewProject(FileSystem) { Config=ProjectConfig, Name=args[0] };
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Config.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Newtonsoft.Json.Serialization;
3 |
4 | namespace ProjectStarter {
5 |
6 | public interface IConfig {
7 | string RawConfig { get; set; }
8 | string RootDirectory { get; set; }
9 | string LibPath { get; }
10 | string[] SubDirectories { get; set; }
11 | Package[] Packages { get; }
12 | }
13 |
14 | public class Config : IConfig{
15 |
16 | public string RawConfig { get; set; }
17 | public string RootDirectory { get; set; }
18 | public string[] SubDirectories { get; set; }
19 |
20 | public static IConfig LoadConfig(string configFileContents) {
21 | if(String.IsNullOrEmpty(configFileContents))
22 | throw new ArgumentException("The file contents must contain valid JSON");
23 | var config = Newtonsoft.Json.JsonConvert.DeserializeObject(configFileContents);
24 | config.RawConfig = configFileContents;
25 | return config;
26 |
27 | }
28 |
29 |
30 | public string LibPath { get; set; }
31 |
32 | public Package[] Packages { get; set; }
33 | }
34 |
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/src/Package.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace ProjectStarter
7 | {
8 | public class Package
9 | {
10 | public string PackageId { get; set; }
11 | public string Version { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 |
4 | namespace ProjectStarter
5 | {
6 | public class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | ICommand command = getCommand(args);
11 | command.Execute();
12 | }
13 | public static ICommand getCommand(string[] args)
14 | {
15 | ArgParser parser = new ArgParser(args, new FileSystem(new DirectoryInfoWrapper(Environment.CurrentDirectory), new FileInfoWrapper()));
16 | return parser.Command;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/commands/FetchPackage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.Composition;
3 |
4 | namespace ProjectStarter
5 | {
6 | [Export(typeof(ICommand))]
7 | public class FetchPackage : ICommand
8 | {
9 |
10 | public void Execute()
11 | {
12 |
13 | }
14 |
15 | public string Name { get; set; }
16 | public IConfig Config { get; set; }
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/commands/ICommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.Composition;
3 |
4 | namespace ProjectStarter
5 | {
6 | public interface ICommand
7 | {
8 | void Execute();
9 | string Name { get; set; }
10 | IConfig Config { get; set; }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/commands/MakeBuildFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.Composition;
3 |
4 | namespace ProjectStarter
5 | {
6 |
7 | [Export(typeof(ICommand))]
8 | public class MakeBuildFile : ICommand
9 | {
10 |
11 | public void Execute()
12 | {
13 | throw new NotImplementedException();
14 | }
15 |
16 | public string Name { get; set; }
17 | public IConfig Config { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/commands/NewProject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.Composition;
3 | using NuGet;
4 |
5 | namespace ProjectStarter
6 | {
7 | [Export(typeof(ICommand))]
8 | public class NewProject : ICommand
9 | {
10 |
11 | private readonly IFileSystem _fileSystem;
12 | public string Name { get; set; }
13 | public IConfig Config { get; set; }
14 |
15 | public NewProject(IFileSystem FileSystem)
16 | {
17 | _fileSystem = FileSystem;
18 | }
19 |
20 | public void Execute()
21 | {
22 | CreateDirectories();
23 | FetchPackages();
24 | }
25 |
26 |
27 | private void CreateDirectories()
28 | {
29 | if (!String.IsNullOrEmpty(Name))
30 | Config.RootDirectory = Name;
31 | _fileSystem.CreateDirectory(Config.RootDirectory);
32 | foreach (var dir in Config.SubDirectories)
33 | {
34 | _fileSystem.CreateDirectoryInWorkingDirectory(dir);
35 | }
36 | }
37 | private void FetchPackages()
38 | {
39 | if (Config.Packages != null)
40 | {
41 | IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
42 | PackageManager packageManager = new PackageManager(repo, Config.LibPath);
43 |
44 | try
45 | {
46 | foreach (var package in Config.Packages)
47 | {
48 | packageManager.InstallPackage(package.PackageId, SemanticVersion.Parse(package.Version));
49 | }
50 | }
51 | catch (Exception ex)
52 | {
53 | throw new NewProjectException("Could not fetch pacakges",ex);
54 | }
55 | }
56 |
57 | }
58 | }
59 | public class NewProjectException : Exception
60 | {
61 | public NewProjectException(string message, Exception ex)
62 | {
63 |
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/src/commands/NewProjectException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace ProjectStarter
7 | {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/templates/build.proj:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | Debug
7 |
8 |
9 |
10 | false
11 | true
12 | bin
13 | bin\
14 | bin\
15 |
16 |
17 |
20 |
21 |
22 |
23 |
24 |
25 | Screwturn.YouTubePlugin
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
53 |
54 |
55 |
56 |
57 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/src/wrappers/DirectoryInfoWrapper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace ProjectStarter
5 | {
6 | public interface IDirectoryInfoWrapper
7 | {
8 | DirectoryInfo CreateSubDirectory(string path);
9 | string WorkingDirectory { get; set; }
10 | string FullPath { get; }
11 | bool Exists(string path);
12 | }
13 |
14 | public class DirectoryInfoWrapper : IDirectoryInfoWrapper
15 | {
16 |
17 | public string WorkingDirectory { get; set; }
18 | public string FullPath
19 | {
20 | get
21 | {
22 | return Path.GetFullPath(WorkingDirectory);
23 |
24 | }
25 | }
26 |
27 | public bool Exists(string path)
28 | {
29 | return Directory.Exists( path);
30 | }
31 |
32 | public DirectoryInfoWrapper(string workingDirectory)
33 | {
34 | WorkingDirectory = workingDirectory;
35 | }
36 |
37 | public DirectoryInfo CreateSubDirectory(string path)
38 | {
39 | return Directory.CreateDirectory(path);
40 | }
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/wrappers/FileInfoWrapper.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | namespace ProjectStarter
3 | {
4 | public interface IFileInfoWrapper
5 | {
6 | void CreateFile(string path, string contents);
7 | }
8 |
9 | public class FileInfoWrapper : IFileInfoWrapper
10 | {
11 | public void CreateFile(string path, string contents)
12 | {
13 | var writer = File.CreateText(path);
14 | writer.Write(contents);
15 | writer.Close();
16 | writer.Dispose();
17 | }
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/wrappers/FileSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace ProjectStarter
5 | {
6 | public interface IFileSystem
7 | {
8 | string WorkingDirectory{get; set;}
9 | void CreateDirectory(string name);
10 | void CreateFile(string name, string contents);
11 | void CreateDirectoryInWorkingDirectory(string name);
12 | string ReadFile(string name);
13 | }
14 |
15 | public class FileSystem : IFileSystem
16 | {
17 | private IDirectoryInfoWrapper _currentDirectory;
18 | private IFileInfoWrapper _fileInfoWrapper;
19 | public FileSystem(IDirectoryInfoWrapper currentDirectory, IFileInfoWrapper fileInfoWrapper)
20 | {
21 | _currentDirectory = currentDirectory;
22 | _fileInfoWrapper = fileInfoWrapper;
23 | WorkingDirectory = _currentDirectory.WorkingDirectory;
24 | }
25 |
26 | public string WorkingDirectory { get; set; }
27 |
28 | public void CreateDirectory(string name)
29 | {
30 | WorkingDirectory = name;
31 | _currentDirectory.CreateSubDirectory(name);
32 | }
33 |
34 | public void CreateDirectoryInWorkingDirectory(string name)
35 | {
36 | _currentDirectory.CreateSubDirectory(String.Format("{0}\\{1}", WorkingDirectory, name));
37 | }
38 |
39 | public void CreateFile(string name, string contents)
40 | {
41 | _fileInfoWrapper.CreateFile(name, contents);
42 | }
43 |
44 | public string ReadFile(string name) {
45 | return string.Empty;
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/tests/integrationtests/when_creating_a_new_project.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using Xunit;
4 | using ProjectStarter;
5 |
6 | namespace ProjectStarter.Tests.IntegrationTests
7 | {
8 | public class when_creating_a_new_project
9 | {
10 |
11 | private ArgParser parser;
12 | private string[] args;
13 | private DirectoryInfoWrapper dirInfoWrapper;
14 | public when_creating_a_new_project() {
15 | dirInfoWrapper = new DirectoryInfoWrapper(Environment.CurrentDirectory);
16 | args = new string[] {"Test"};
17 | parser = new ArgParser(args, new FileSystem( dirInfoWrapper, new FileInfoWrapper()));
18 | }
19 |
20 |
21 | public void it_should_create_the_project_directory()
22 | {
23 | Assert.True(Directory.Exists(dirInfoWrapper.FullPath));
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/mocks/MockFileSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using ProjectStarter;
4 |
5 | namespace ProjectStarter_Tests.Mocks {
6 |
7 | public class MockFileSystem : IFileSystem {
8 | public string WorkingDirectory{get; set;}
9 | public bool CreateDirectoryCalled = false;
10 | public bool CreateFileCalled = false;
11 | public bool CreateDirectoryInWorkingDirectoryCalled = false;
12 |
13 |
14 | public List DirectoriesCreated = new List();
15 | public List FilesRead = new List();
16 | public List FilesCreated = new List();
17 |
18 | public string ReturnFromReadFile = "{test:'test'}";
19 |
20 | public void CreateDirectory(string name) {
21 | CreateDirectoryCalled = true;
22 | DirectoriesCreated.Add(name);
23 | }
24 |
25 | public void CreateFile(string name, string contents) {
26 | CreateFileCalled = true;
27 | FilesCreated.Add(name);
28 | }
29 |
30 | public void CreateDirectoryInWorkingDirectory(string name) {
31 | CreateDirectoryInWorkingDirectoryCalled = true;
32 | DirectoriesCreated.Add(name);
33 | }
34 |
35 | public string ReadFile(string name) {
36 | FilesRead.Add(name);
37 | return ReturnFromReadFile;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/tests/unittests/when_creating_files_using_the_filesystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 | using Moq;
4 | using ProjectStarter;
5 |
6 | namespace ProjectStarter_Tests.UnitTests
7 | {
8 | public class when_creating_files_using_the_filesystem
9 | {
10 | private FileSystem _fileSystem;
11 | private Mock _mockDirectoryWrapper;
12 | private Mock _mockFileInfoWrapper;
13 | public when_creating_files_using_the_filesystem()
14 | {
15 | _mockDirectoryWrapper = new Mock();
16 | _mockFileInfoWrapper = new Mock();
17 | _fileSystem = new FileSystem(_mockDirectoryWrapper.Object, _mockFileInfoWrapper.Object);
18 | }
19 |
20 | [Fact]
21 | public void should_call_the_CreateSubDirectory_method()
22 | {
23 | _fileSystem.CreateDirectory("test");
24 | _mockDirectoryWrapper.Verify(m => m.CreateSubDirectory(It.IsAny()));
25 | }
26 |
27 | [Fact]
28 | public void should_call_the_CreateFile_method()
29 | {
30 | _fileSystem.CreateFile("test.txt", "test");
31 | _mockFileInfoWrapper.Verify(f => f.CreateFile(It.IsAny(), It.IsAny()));
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/unittests/when_executing_a_command.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using ProjectStarter;
5 | using ProjectStarter_Tests.Mocks;
6 | using Xunit;
7 |
8 | namespace ProjectStarter_Tests.UnitTests
9 | {
10 | public class when_executing_a_command
11 | {
12 | public ICommand command;
13 | public MockFileSystem _mockFileSystem;
14 | public const string projectname = "test";
15 |
16 | public when_executing_a_command()
17 | {
18 | _mockFileSystem = new MockFileSystem() { ReturnFromReadFile = null };
19 | var parser = new ArgParser(new string[] { projectname }, _mockFileSystem);
20 | parser.Command.Execute();
21 | }
22 |
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/tests/unittests/when_executing_the_NewProject_command.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 | using ProjectStarter;
4 | using ProjectStarter_Tests.Mocks;
5 |
6 | namespace ProjectStarter_Tests.UnitTests
7 | {
8 |
9 | public class when_executing_the_NewProject_command : when_executing_a_command
10 | {
11 |
12 | [Fact]
13 | public void the_root_directory_should_be_created()
14 | {
15 | Assert.Contains(projectname, _mockFileSystem.DirectoriesCreated);
16 | }
17 |
18 | [Fact]
19 | public void the_src_directory_should_be_created()
20 | {
21 | Assert.Contains("src", _mockFileSystem.DirectoriesCreated);
22 | }
23 |
24 | [Fact]
25 | public void the_tests_directory_should_be_created()
26 | {
27 | Assert.Contains("tests", _mockFileSystem.DirectoriesCreated);
28 | }
29 |
30 | [Fact]
31 | public void the_lib_directory_should_be_created()
32 | {
33 | Assert.Contains("lib", _mockFileSystem.DirectoriesCreated);
34 | }
35 |
36 | [Fact]
37 | public void the_packages_directory_should_be_created()
38 | {
39 | Assert.Contains("packages", _mockFileSystem.DirectoriesCreated);
40 | }
41 |
42 | [Fact]
43 | public void the_configs_directory_should_be_created()
44 | {
45 | Assert.Contains("configs", _mockFileSystem.DirectoriesCreated);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/unittests/when_making_a_default_build_file.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 | using ProjectStarter;
4 | using ProjectStarter_Tests.Mocks;
5 |
6 |
7 | namespace ProjectStarter_Tests.UnitTests
8 | {
9 | public class when_making_a_default_build_file : when_executing_a_command
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/unittests/when_parsing_arguments.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 | using ProjectStarter;
4 | using ProjectStarter_Tests.Mocks;
5 |
6 |
7 | namespace ProjectStarter_Tests.UnitTests
8 | {
9 |
10 | public class when_parsing_arguments
11 | {
12 |
13 | public ArgParser parser;
14 | public when_parsing_arguments()
15 | {
16 | parser = new ArgParser(new string[] { "test" }, new MockFileSystem());
17 | }
18 |
19 | [Fact]
20 | public void the_command_property_should_be_set()
21 | {
22 | Assert.NotNull(parser.Command);
23 | }
24 |
25 | [Fact]
26 | public void the_command_property_should_be_the_correct_concrete_type()
27 | {
28 | Assert.IsType(typeof(NewProject), parser.Command);
29 | }
30 |
31 | [Fact]
32 | public void and_passing_in_null_no_Command_should_be_set()
33 | {
34 | var p = new ArgParser(null, new MockFileSystem());
35 | Assert.Null(p.Command);
36 | }
37 |
38 | [Fact]
39 | public void should_throw_when_passed_a_null_FileSystem()
40 | {
41 | Assert.Throws(delegate { new ArgParser(null, null); });
42 | }
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tests/unittests/when_there_is_no_config_file_present.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 | using ProjectStarter_Tests.Mocks;
4 | using ProjectStarter;
5 |
6 | namespace ProjectStarter_Tests.UnitTests {
7 | public class when_there_is_no_config_file_present {
8 | private readonly MockFileSystem _mockFileSystem;
9 | private readonly ArgParser _parser;
10 |
11 |
12 | public when_there_is_no_config_file_present() {
13 | _mockFileSystem = new MockFileSystem() { ReturnFromReadFile = null };
14 | _parser = new ArgParser(null, _mockFileSystem);
15 | }
16 |
17 |
18 | [Fact]
19 | public void should_look_for_the_default_config_file() {
20 | Assert.Contains("default.json", _mockFileSystem.FilesRead);
21 | }
22 |
23 | [Fact]
24 | public void should_create_the_default_config_file_if_it_does_not_exist() {
25 | Assert.Contains("default.json", _mockFileSystem.FilesCreated);
26 | }
27 |
28 | }
29 | }
--------------------------------------------------------------------------------
/tests/unittests/when_using_a_json_config_file.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ProjectStarter;
3 | using ProjectStarter_Tests.Mocks;
4 | using Xunit;
5 |
6 | namespace ProjectStarter_Tests.UnitTests {
7 |
8 | public class when_using_a_json_config_file {
9 |
10 | protected readonly MockFileSystem _mockFileSystem;
11 | protected readonly ArgParser _parser;
12 |
13 | private const string DefaultConfigFileName = "default.json";
14 | private const string JsonConfig = @"{ ""RootDirectory"": ""Test"", ""SubDirectories"": [""test""] }";
15 |
16 |
17 | public when_using_a_json_config_file() {
18 | _mockFileSystem = new MockFileSystem() { ReturnFromReadFile = JsonConfig };
19 | _parser = new ArgParser(null, _mockFileSystem);
20 | }
21 |
22 | [Fact]
23 | public void should_read_the_default_config() {
24 | Assert.Contains(DefaultConfigFileName ,_mockFileSystem.FilesRead );
25 | }
26 |
27 | [Fact]
28 | public void should_deserialize_the_config_file() {
29 | Assert.NotNull(_parser.ProjectConfig);
30 | }
31 |
32 | [Fact]
33 | public void Config_property_should_contain_the_config_contents() {
34 | Assert.Equal(JsonConfig, _parser.ProjectConfig.RawConfig);
35 | }
36 |
37 | [Fact]
38 | public void config_file_should_be_the_proper_type() {
39 | Assert.IsType(typeof(Config), _parser.ProjectConfig);
40 | }
41 |
42 | [Fact]
43 | public void config_object_should_contain_a_project_root_name() {
44 | Assert.NotNull(_parser.ProjectConfig.RootDirectory);
45 | Assert.IsType(typeof(string), _parser.ProjectConfig.RootDirectory);
46 | }
47 |
48 | [Fact]
49 | public void config_object_should_contain_a_list_of_subdirectories() {
50 | Assert.NotEmpty(_parser.ProjectConfig.SubDirectories);
51 | }
52 |
53 | }
54 | }
--------------------------------------------------------------------------------