Skip to content

Commit a8d52f3

Browse files
committed
Refactoring Tuple to ProjectItem class
1 parent 2a3a701 commit a8d52f3

9 files changed

Lines changed: 42 additions & 35 deletions

File tree

src/ScriptCs.Contracts/ScriptCs.Contracts.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<Compile Include="LogLevel.cs" />
106106
<Compile Include="LogProviderExtensions.cs" />
107107
<Compile Include="ModuleAttribute.cs" />
108+
<Compile Include="ProjectItem.cs" />
108109
<Compile Include="Properties\AssemblyInfo.cs" />
109110
<Compile Include="ScriptPack.cs" />
110111
<Compile Include="ScriptPackSession.cs" />

src/ScriptCs.Hosting/DirectoryInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public class DirectoryInfo
1010
{
1111
public DirectoryInfo()
1212
{
13-
Guid = System.Guid.NewGuid().ToString().ToUpper();
13+
Guid = Guid.NewGuid();
1414
Files = new List<string>();
1515
Directories = new Dictionary<string, DirectoryInfo>();
1616
}
1717

18-
public string Guid { get; private set; }
18+
public Guid Guid { get; private set; }
1919
public string Name { get; set; }
2020
public string Path { get; set; }
2121
public string FullPath { get; set; }

src/ScriptCs.Hosting/IVisualStudioSolution.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace ScriptCs.Contracts
66
public interface IVisualStudioSolution
77
{
88
void AddHeader();
9-
void AddScriptcsProject(string scriptcsPath, string workingPath, string args, bool attach, string projectGuid);
10-
void AddProject(string path, string name, string guid, string[] files);
11-
void AddGlobalHeader(string projectGuid);
12-
void AddGlobalNestedProjects(IList<Tuple<string, string>> nestedItems);
13-
void AddGlobal(string projectGuid, IList<Tuple<string, string>> nestedItems);
9+
void AddScriptcsProject(string scriptcsPath, string workingPath, string args, bool attach, Guid projectGuid);
10+
void AddProject(string path, string name, Guid guid, string[] files);
11+
void AddGlobalHeader(Guid projectGuid);
12+
void AddGlobalNestedProjects(IList<ProjectItem> nestedItems);
13+
void AddGlobal(Guid projectGuid, IList<ProjectItem> nestedItems);
1414
}
1515
}

src/ScriptCs.Hosting/IVisualStudioSolutionWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace ScriptCs.Contracts
66
{
77
public interface IVisualStudioSolutionWriter
88
{
9-
string WriteSolution(IFileSystem fs, string script, IVisualStudioSolution solution, IList<Tuple<string, string>> nestedItems = null);
9+
string WriteSolution(IFileSystem fs, string script, IVisualStudioSolution solution, IList<ProjectItem> nestedItems = null);
1010
}
1111
}

src/ScriptCs.Hosting/VisualStudioSolution.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void AddHeader()
2929
_header.AppendLine("MinimumVisualStudioVersion = 10.0.40219.1");
3030
}
3131

32-
public void AddScriptcsProject(string scriptcsPath, string workingPath, string args, bool attach, string projectGuid)
32+
public void AddScriptcsProject(string scriptcsPath, string workingPath, string args, bool attach, Guid projectGuid)
3333
{
3434
_projects.AppendFormat(@"Project(""{{911E67C6-3D85-4FCE-B560-20A9C3E3FF48}}"") = ""scriptcs"", ""{0}"", ""{{{1}}}""{2}", scriptcsPath, projectGuid, Environment.NewLine);
3535
_projects.AppendLine("\tProjectSection(DebuggerProjectSystem) = preProject");
@@ -47,7 +47,7 @@ public void AddScriptcsProject(string scriptcsPath, string workingPath, string a
4747
_projects.AppendLine("EndProject");
4848
}
4949

50-
public void AddProject(string path, string name, string guid, string[] files)
50+
public void AddProject(string path, string name, Guid guid, string[] files)
5151
{
5252
_projects.AppendFormat(@"Project(""{{2150E333-8FDC-42A3-9474-1A3956D46DE8}}"") = ""{0}"", ""{0}"", ""{{{1}}}""{2}", name, guid, Environment.NewLine);
5353
_projects.AppendLine("\tProjectSection(SolutionItems) = preProject");
@@ -66,7 +66,7 @@ public void AddProject(string path, string name, string guid, string[] files)
6666
_projects.AppendLine("EndProject");
6767
}
6868

69-
public void AddGlobalHeader(string projectGuid)
69+
public void AddGlobalHeader(Guid projectGuid)
7070
{
7171
_global.AppendLine ("Global");
7272
_global.AppendLine ("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
@@ -80,20 +80,20 @@ public void AddGlobalHeader(string projectGuid)
8080
_global.AppendLine ("\tEndGlobalSection");
8181
}
8282

83-
public void AddGlobalNestedProjects(IList<Tuple<string, string>> nestedItems)
83+
public void AddGlobalNestedProjects(IList<ProjectItem> nestedItems)
8484
{
8585
if (nestedItems.Any())
8686
{
8787
_global.AppendLine("\tGlobalSection(NestedProjects) = preSolution");
8888
foreach (var item in nestedItems)
8989
{
90-
_global.AppendFormat("\t\t{{{0}}} = {{{1}}}{2}", item.Item1, item.Item2, Environment.NewLine);
90+
_global.AppendFormat("\t\t{{{0}}} = {{{1}}}{2}", item.Project, item.Parent, Environment.NewLine);
9191
}
9292
_global.AppendLine("\tEndGlobalSection");
9393
}
9494
}
9595

96-
public void AddGlobal(string projectGuid, IList<Tuple<string, string>> nestedItems)
96+
public void AddGlobal(Guid projectGuid, IList<ProjectItem> nestedItems)
9797
{
9898
AddGlobalHeader(projectGuid);
9999
AddGlobalNestedProjects(nestedItems);

src/ScriptCs.Hosting/VisualStudioSolutionWriter.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ namespace ScriptCs.Hosting
1111
public class VisualStudioSolutionWriter : IVisualStudioSolutionWriter
1212
{
1313
internal DirectoryInfo _root;
14+
private Guid _nullGuid = new Guid();
1415

15-
public string WriteSolution(IFileSystem fs, string script, IVisualStudioSolution solution, IList<Tuple<string, string>> nestedItems = null)
16+
public string WriteSolution(IFileSystem fs, string script, IVisualStudioSolution solution, IList<ProjectItem> nestedItems = null)
1617
{
1718
if (nestedItems == null)
1819
{
19-
nestedItems = new List<Tuple<string, string>>();
20+
nestedItems = new List<ProjectItem>();
2021
}
2122

2223
var launcher = Path.Combine(fs.TempPath, "launcher-" + Guid.NewGuid().ToString() + ".sln");
@@ -30,26 +31,26 @@ public string WriteSolution(IFileSystem fs, string script, IVisualStudioSolution
3031
var scriptcsPath = Path.Combine(fs.HostBin, "scriptcs.exe");
3132
var scriptcsArgs = string.Format("{0} -debug -loglevel info", script);
3233
_root = new DirectoryInfo { Name = "Solution Items", FullPath = currentDir};
33-
var projectGuid = Guid.NewGuid().ToString().ToUpper();
34+
var projectGuid = Guid.NewGuid();
3435

3536
solution.AddScriptcsProject(scriptcsPath, currentDir, scriptcsArgs, false, projectGuid);
3637
GetDirectoryInfo(fs, currentDir, _root);
37-
AddDirectoryProject(solution, fs, _root, null, nestedItems);
38+
AddDirectoryProject(solution, fs, _root, _nullGuid, nestedItems);
3839
solution.AddGlobal(projectGuid, nestedItems);
3940
fs.WriteToFile(launcher, solution.ToString());
4041
return launcher;
4142
}
4243

43-
private void AddDirectoryProject(IVisualStudioSolution solution, IFileSystem fs, DirectoryInfo currentDirectory, string parent, IList<Tuple<string, string>> nestedItems)
44+
private void AddDirectoryProject(IVisualStudioSolution solution, IFileSystem fs, DirectoryInfo currentDirectory, Guid parent, IList<ProjectItem> nestedItems)
4445
{
4546
solution.AddProject(currentDirectory.FullPath, currentDirectory.Name, currentDirectory.Guid, currentDirectory.Files.ToArray());
4647
foreach (DirectoryInfo dir in currentDirectory.Directories.Values)
4748
{
4849
AddDirectoryProject(solution, fs, dir, currentDirectory.Guid, nestedItems);
4950
}
50-
if (parent != null)
51+
if (parent != _nullGuid)
5152
{
52-
nestedItems.Add(new Tuple<string, string>(currentDirectory.Guid, parent));
53+
nestedItems.Add(new ProjectItem(currentDirectory.Guid, parent));
5354
}
5455
}
5556

test/ScriptCs.Hosting.Tests/ReplCommands/OpenVSCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void CreatesTheSolution()
4949
_mockWriter.Verify(
5050
w =>
5151
w.WriteSolution(It.IsAny<IFileSystem>(), It.IsAny<string>(), It.IsAny<IVisualStudioSolution>(),
52-
It.IsAny<IList<Tuple<string, string>>>()));
52+
It.IsAny<IList<ProjectItem>>()));
5353
}
5454

5555
[Fact]

test/ScriptCs.Hosting.Tests/VisualStudioSolutionTests.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Should;
77
using Xunit;
88
using System.IO;
9+
using ScriptCs.Contracts;
910

1011
namespace ScriptCs.Hosting.Tests
1112
{
@@ -37,7 +38,7 @@ public void ShouldAppendTheHeader()
3738

3839
public class TheAddGlobalHeaderMethod
3940
{
40-
private string _projectGuid = Guid.NewGuid().ToString();
41+
private Guid _projectGuid = Guid.NewGuid();
4142
private VisualStudioSolution _builder = new VisualStudioSolution();
4243

4344
[Fact]
@@ -66,15 +67,19 @@ public void ShouldAppenedGlobalSectionEntriesForEachProject()
6667
{
6768
var builder = new VisualStudioSolution();
6869

69-
var nestedItems = new List<Tuple<string, string>>();
70-
nestedItems.Add(new Tuple<string, string>("A", "B"));
71-
nestedItems.Add(new Tuple<string, string>("B", "C"));
70+
var nestedItems = new List<ProjectItem>();
71+
var a = Guid.NewGuid();
72+
var b = Guid.NewGuid();
73+
var c = Guid.NewGuid();
74+
75+
nestedItems.Add(new ProjectItem(a, b));
76+
nestedItems.Add(new ProjectItem(b, c));
7277
builder.AddGlobalNestedProjects(nestedItems);
7378
var nestedBuilder = new StringBuilder();
7479
nestedBuilder.AppendLine("\tGlobalSection(NestedProjects) = preSolution");
75-
nestedBuilder.AppendFormat("\t\t{{{0}}} = {{{1}}}{2}", nestedItems[0].Item1, nestedItems[0].Item2,
80+
nestedBuilder.AppendFormat("\t\t{{{0}}} = {{{1}}}{2}", nestedItems[0].Project, nestedItems[0].Parent,
7681
Environment.NewLine);
77-
nestedBuilder.AppendFormat("\t\t{{{0}}} = {{{1}}}{2}", nestedItems[1].Item1, nestedItems[1].Item2,
82+
nestedBuilder.AppendFormat("\t\t{{{0}}} = {{{1}}}{2}", nestedItems[1].Project, nestedItems[1].Parent,
7883
Environment.NewLine);
7984
nestedBuilder.AppendLine("\tEndGlobalSection");
8085
builder._global.ToString().Contains(nestedBuilder.ToString());
@@ -88,7 +93,7 @@ public class TheAddScriptcsProjectMethod
8893
private const string _workingPath = "working";
8994
private const string _args = "test.csx";
9095
private const bool _attach = true;
91-
private string _projectGuid = Guid.NewGuid().ToString();
96+
private Guid _projectGuid = Guid.NewGuid();
9297
private string _projects;
9398

9499
public TheAddScriptcsProjectMethod()

test/ScriptCs.Hosting.Tests/VisualStudioSolutionWriterTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class TheWriteSolutionMethod
1919
private Mock<IVisualStudioSolution> _solutionMock;
2020
private Mock<IFileSystem> _fsMock;
2121
private VisualStudioSolutionWriter _writer;
22-
private IList<Tuple<string, string>> _nestedItems;
22+
private IList<ProjectItem> _nestedItems;
2323
private string _launcher;
2424

2525
public TheWriteSolutionMethod()
@@ -33,15 +33,15 @@ public TheWriteSolutionMethod()
3333
_fsMock.Setup(fs=>fs.EnumerateFilesAndDirectories(It.IsAny<string>(), It.IsAny<string>(), SearchOption.AllDirectories)).Returns(new [] {Path.Combine("root","file1.csx"), Path.Combine("root", "child1", "file2.csx"), Path.Combine("root", "child1", "child2", "file3.csx")});
3434
_fsMock.Setup(fs => fs.FileExists(It.IsAny<string>())).Returns(false);
3535
_fsMock.SetupGet(fs => fs.TempPath).Returns("temp");
36-
_nestedItems = new List<Tuple<string, string>>();
36+
_nestedItems = new List<ProjectItem>();
3737
_launcher = _writer.WriteSolution(_fsMock.Object, "test.csx", _solutionMock.Object, _nestedItems);
3838
}
3939

4040
[Fact]
4141
public void ShouldAddTheScriptcsProject()
4242
{
4343
var scriptcsPath = Path.Combine("bin", "scriptcs.exe");
44-
_solutionMock.Verify(fs=>fs.AddScriptcsProject(scriptcsPath, "root", "test.csx -debug -loglevel info", false, It.IsAny<string>()));
44+
_solutionMock.Verify(fs=>fs.AddScriptcsProject(scriptcsPath, "root", "test.csx -debug -loglevel info", false, It.IsAny<Guid>()));
4545
}
4646

4747
[Fact]
@@ -59,14 +59,14 @@ public void ShouldCallAddDirectoryProjectForChild()
5959
{
6060
var child1 = _writer._root.Directories.Values.First();
6161
var child2 = child1.Directories.Values.First();
62-
_nestedItems.Where(i => i.Item1 == child1.Guid).Count().ShouldEqual(1);
63-
_nestedItems.Where(i => i.Item1 == child2.Guid).Count().ShouldEqual(1);
62+
_nestedItems.Where(i => i.Project == child1.Guid).Count().ShouldEqual(1);
63+
_nestedItems.Where(i => i.Project == child2.Guid).Count().ShouldEqual(1);
6464
}
6565

6666
[Fact]
6767
public void ShouldAddGlobal()
6868
{
69-
_solutionMock.Verify(s=>s.AddGlobal(It.IsAny<string>(), _nestedItems));
69+
_solutionMock.Verify(s=>s.AddGlobal(It.IsAny<Guid>(), _nestedItems));
7070
}
7171

7272
[Fact]

0 commit comments

Comments
 (0)