Skip to content

Commit 5de1e80

Browse files
committed
Initial commit
1 parent f44148d commit 5de1e80

17 files changed

Lines changed: 499 additions & 27 deletions

AddToPath/Program.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

PathEd.Tests/PathEd.Tests.csproj

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
4+
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
5+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
6+
<PropertyGroup>
7+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9+
<ProjectGuid>{E06D651C-A778-4451-8534-0F1019F5294D}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>PathEd.Tests</RootNamespace>
13+
<AssemblyName>PathEd.Tests</AssemblyName>
14+
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
17+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
18+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
19+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
20+
<IsCodedUITest>False</IsCodedUITest>
21+
<TestProjectType>UnitTest</TestProjectType>
22+
<NuGetPackageImportStamp>
23+
</NuGetPackageImportStamp>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
26+
<DebugSymbols>true</DebugSymbols>
27+
<DebugType>full</DebugType>
28+
<Optimize>false</Optimize>
29+
<OutputPath>bin\Debug\</OutputPath>
30+
<DefineConstants>DEBUG;TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
35+
<DebugType>pdbonly</DebugType>
36+
<Optimize>true</Optimize>
37+
<OutputPath>bin\Release\</OutputPath>
38+
<DefineConstants>TRACE</DefineConstants>
39+
<ErrorReport>prompt</ErrorReport>
40+
<WarningLevel>4</WarningLevel>
41+
</PropertyGroup>
42+
<ItemGroup>
43+
<Reference Include="FluentAssertions, Version=5.4.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
44+
<HintPath>..\packages\FluentAssertions.5.4.2\lib\net47\FluentAssertions.dll</HintPath>
45+
</Reference>
46+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
47+
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
48+
</Reference>
49+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
50+
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
51+
</Reference>
52+
<Reference Include="nunit.framework, Version=3.11.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
53+
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
54+
</Reference>
55+
<Reference Include="System" />
56+
<Reference Include="System.Core" />
57+
<Reference Include="System.Xml" />
58+
<Reference Include="System.Xml.Linq" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<Compile Include="TestPath.cs" />
62+
<Compile Include="PathUpdaterTests.cs" />
63+
<Compile Include="Properties\AssemblyInfo.cs" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<None Include="packages.config" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<ProjectReference Include="..\PathEd\PathEd.csproj">
70+
<Project>{7faa6495-170f-46e5-9b28-28d39ba7f7e3}</Project>
71+
<Name>PathEd</Name>
72+
</ProjectReference>
73+
</ItemGroup>
74+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
75+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
77+
<PropertyGroup>
78+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
79+
</PropertyGroup>
80+
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
81+
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
82+
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
83+
</Target>
84+
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
85+
</Project>

PathEd.Tests/PathUpdaterTests.cs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
using FluentAssertions;
2+
using NUnit.Framework;
3+
using System;
4+
5+
namespace PathEd.Tests
6+
{
7+
public class PathUpdaterTests
8+
{
9+
protected TestPath _path;
10+
protected PathUpdater _updater;
11+
12+
[SetUp]
13+
public void Setup()
14+
{
15+
_path = new TestPath();
16+
_updater = new PathUpdater(_path);
17+
}
18+
19+
public class AddMethod : PathUpdaterTests
20+
{
21+
22+
[Test]
23+
public void Throws_If_Null_Is_Passed()
24+
{
25+
Action a = () => _updater.Add(null);
26+
a.Should().Throw<ArgumentNullException>();
27+
}
28+
29+
[Test]
30+
public void Returns_Value_If_Path_Is_Null()
31+
{
32+
_path.Set(null);
33+
_updater.Add("xyz");
34+
_path.Get().Should().Be("xyz");
35+
}
36+
37+
[Test]
38+
public void Returns_Value_If_Path_Is_Empty()
39+
{
40+
_path.Set("");
41+
_updater.Add("xyz");
42+
_path.Get().Should().Be("xyz");
43+
}
44+
45+
[Test]
46+
public void Preserves_Prior_Values()
47+
{
48+
_path.Set("abc;def;ghi");
49+
_updater.Add("xyz");
50+
_path.Get().Should().Be("abc;def;ghi;xyz");
51+
}
52+
53+
[Test]
54+
public void Does_Not_Add_Duplicates()
55+
{
56+
_path.Set("abc;xyz;ghi");
57+
_updater.Add("xyz");
58+
_path.Get().Should().Be("abc;xyz;ghi");
59+
}
60+
61+
[Test]
62+
public void Does_Not_Add_Duplicates_Ignore_Case()
63+
{
64+
_path.Set("abc;XYz;ghi");
65+
_updater.Add("xYZ");
66+
_path.Get().Should().Be("abc;XYz;ghi");
67+
}
68+
}
69+
70+
public class RemoveMethod : PathUpdaterTests
71+
{
72+
[Test]
73+
public void Throws_If_Null_Is_Passed()
74+
{
75+
Action a = () => _updater.Remove(null);
76+
a.Should().Throw<ArgumentNullException>();
77+
}
78+
79+
[Test]
80+
public void Does_Nothing_If_Path_Is_Null()
81+
{
82+
_path.Set(null);
83+
_updater.Remove("xyz");
84+
_path.Get().Should().Be(null);
85+
}
86+
87+
[Test]
88+
public void Does_Nothing_If_Path_Is_Empty()
89+
{
90+
_path.Set("");
91+
_updater.Remove("xyz");
92+
_path.Get().Should().Be("");
93+
}
94+
95+
[Test]
96+
public void Removes_Value_From_The_End_With_Semicolon()
97+
{
98+
_path.Set("abc;def;ghi;xyz;");
99+
_updater.Remove("xyz");
100+
_path.Get().Should().Be("abc;def;ghi");
101+
}
102+
103+
[Test]
104+
public void Removes_Value_From_The_End_Without_Semicolon()
105+
{
106+
_path.Set("abc;def;ghi;xyz");
107+
_updater.Remove("xyz");
108+
_path.Get().Should().Be("abc;def;ghi");
109+
}
110+
111+
[Test]
112+
public void Removes_Value_From_The_Middle_With_One_Semicolon()
113+
{
114+
_path.Set("abc;xyz;ghi");
115+
_updater.Remove("xyz");
116+
_path.Get().Should().Be("abc;ghi");
117+
}
118+
119+
[Test]
120+
public void Removes_Value_From_The_Middle_With_One_Semicolon_Ignore_Case()
121+
{
122+
_path.Set("abc;XYz;ghi");
123+
_updater.Remove("xYZ");
124+
_path.Get().Should().Be("abc;ghi");
125+
}
126+
127+
[Test]
128+
public void Removes_Value_From_The_Beginning_With_One_Semicolon()
129+
{
130+
_path.Set("xyz;abc;ghi");
131+
_updater.Remove("xyz");
132+
_path.Get().Should().Be("abc;ghi");
133+
}
134+
135+
/// <summary>
136+
/// This is especially important to remove directories with spaces in them
137+
/// like "C:\Program Files\RepoZ" which are often defined with quotes
138+
/// </summary>
139+
[Test]
140+
public void Removes_Value_With_Quotes_As_Well()
141+
{
142+
_path.Set("abc;def;\"x y z\";ghi");
143+
_updater.Remove("x y z");
144+
_path.Get().Should().Be("abc;def;ghi");
145+
}
146+
}
147+
}
148+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
[assembly: AssemblyTitle("PathEd.Tests")]
6+
[assembly: AssemblyDescription("")]
7+
[assembly: AssemblyConfiguration("")]
8+
[assembly: AssemblyCompany("")]
9+
[assembly: AssemblyProduct("PathEd.Tests")]
10+
[assembly: AssemblyCopyright("Copyright © 2018")]
11+
[assembly: AssemblyTrademark("")]
12+
[assembly: AssemblyCulture("")]
13+
14+
[assembly: ComVisible(false)]
15+
16+
[assembly: Guid("e06d651c-a778-4451-8534-0f1019f5294d")]
17+
18+
// [assembly: AssemblyVersion("3.3.0.0")]
19+
[assembly: AssemblyVersion("3.3.0.0")]
20+
[assembly: AssemblyFileVersion("3.3.0.0")]

PathEd.Tests/TestPath.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace PathEd.Tests
2+
{
3+
public class TestPath : IPath
4+
{
5+
private string _path = "";
6+
7+
public string Get() => _path;
8+
9+
public void Set(string value) => _path = value;
10+
}
11+
}

PathEd.Tests/packages.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="FluentAssertions" version="5.4.2" targetFramework="net47" />
4+
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net47" />
5+
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net47" />
6+
<package id="NUnit" version="3.11.0" targetFramework="net47" />
7+
</packages>

AddToPath.sln renamed to PathEd.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.28010.2019
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddToPath", "AddToPath\AddToPath.csproj", "{7FAA6495-170F-46E5-9B28-28D39BA7F7E3}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PathEd", "PathEd\PathEd.csproj", "{7FAA6495-170F-46E5-9B28-28D39BA7F7E3}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PathEd.Tests", "PathEd.Tests\PathEd.Tests.csproj", "{E06D651C-A778-4451-8534-0F1019F5294D}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
1517
{7FAA6495-170F-46E5-9B28-28D39BA7F7E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{7FAA6495-170F-46E5-9B28-28D39BA7F7E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{7FAA6495-170F-46E5-9B28-28D39BA7F7E3}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{E06D651C-A778-4451-8534-0F1019F5294D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{E06D651C-A778-4451-8534-0F1019F5294D}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{E06D651C-A778-4451-8534-0F1019F5294D}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{E06D651C-A778-4451-8534-0F1019F5294D}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

PathEd.v3.ncrunchsolution

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<SolutionConfiguration>
2+
<Settings>
3+
<AllowParallelTestExecution>True</AllowParallelTestExecution>
4+
<SolutionConfigured>True</SolutionConfigured>
5+
</Settings>
6+
</SolutionConfiguration>

PathEd/IPath.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace PathEd
2+
{
3+
public interface IPath
4+
{
5+
string Get();
6+
7+
void Set(string value);
8+
}
9+
}

PathEd/MachinePath.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace PathEd
4+
{
5+
public class MachinePath : IPath
6+
{
7+
public string Get()
8+
{
9+
return Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
10+
}
11+
12+
public void Set(string value)
13+
{
14+
Environment.SetEnvironmentVariable("PATH", value, EnvironmentVariableTarget.Machine);
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)