Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit 02d6638

Browse files
committed
added relative URI helper and tests. Started implementation of matching
strategy relative to the application root.
1 parent 12aa4de commit 02d6638

5 files changed

Lines changed: 87 additions & 0 deletions

File tree

‎CassetteHelper/CassetteHelper.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="IMatchingStrategy.cs" />
5858
<Compile Include="StreamReplacer.cs" />
5959
<Compile Include="MatchingLineVisitor.cs" />
60+
<Compile Include="StringURIExtensions.cs" />
6061
</ItemGroup>
6162
<ItemGroup>
6263
<COMReference Include="EnvDTE">
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace CassetteHelper
4+
{
5+
public static class StringURIExtensions
6+
{
7+
public static string URIRelativeTo(this string filePath, string baseFile)
8+
{
9+
return new Uri(baseFile).MakeRelativeUri(new Uri(filePath)).ToString();
10+
}
11+
}
12+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.IO;
3+
using MbUnit.Framework;
4+
5+
namespace CassetteHelperTests
6+
{
7+
[TestFixture]
8+
public class ApplicationRelativeMatchingStrategyTests
9+
{
10+
[Test]
11+
[Row(null, ExpectedException = typeof(ArgumentNullException), ExpectedExceptionMessage = "applicationRootDirectory")]
12+
[Row("", ExpectedException = typeof(ArgumentNullException), ExpectedExceptionMessage = "applicationRootDirectory")]
13+
[Row(@"c:\iAmAFile.js", ExpectedException = typeof(ArgumentException), ExpectedExceptionMessage = "applicationRootDirectory")]
14+
[Row(@"c:\doesNotExist", ExpectedException = typeof(ArgumentException), ExpectedExceptionMessage = "applicationRootDirectory")]
15+
public void ApplicationRootMustBeValid(string applicationRootDirectory)
16+
{
17+
new ApplicationRelativeMatchingStrategy(applicationRootDirectory, "original.js", "new.js");
18+
}
19+
20+
[Test, ExpectedArgumentNullException("originalFilePath")]
21+
[Row(null)]
22+
[Row("")]
23+
public void OriginalFilePathMustNotBeNullOrEmpty(string originalFilePath)
24+
{
25+
new ApplicationRelativeMatchingStrategy(@"c:\", originalFilePath, "new.js");
26+
}
27+
28+
[Test, ExpectedArgumentNullException("newFilePath")]
29+
[Row(null)]
30+
[Row("")]
31+
public void NewFilePathMustNotBeNullOrEmpty(string newFilePath)
32+
{
33+
new ApplicationRelativeMatchingStrategy(@"c:\", "original.js", newFilePath);
34+
}
35+
}
36+
37+
public class ApplicationRelativeMatchingStrategy
38+
{
39+
public ApplicationRelativeMatchingStrategy(string applicationRootDirectory, string originalFilePath, string newFilePath)
40+
{
41+
if (String.IsNullOrEmpty(applicationRootDirectory)) throw new ArgumentNullException("applicationRootDirectory");
42+
if (String.IsNullOrEmpty(originalFilePath)) throw new ArgumentNullException("originalFilePath");
43+
if (String.IsNullOrEmpty(newFilePath)) throw new ArgumentNullException("newFilePath");
44+
45+
if (!Directory.Exists(applicationRootDirectory)) throw new ArgumentException("Could not find directory '" + applicationRootDirectory + "'", "applicationRootDirectory");
46+
47+
}
48+
49+
50+
}
51+
}

‎CassetteHelperTests/CassetteHelperTests.csproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@
7474
</Reference>
7575
</ItemGroup>
7676
<ItemGroup>
77+
<Compile Include="ApplicationRelativeMatchingStrategyTests.cs" />
7778
<Compile Include="CreateTemporaryFileFrom.cs" />
7879
<Compile Include="StreamReplacerTests.cs" />
7980
<Compile Include="Properties\AssemblyInfo.cs" />
8081
<Compile Include="MatchingLineVisitorTests.cs" />
82+
<Compile Include="StringURIExtensionsTests.cs" />
8183
</ItemGroup>
8284
<ItemGroup>
8385
<ProjectReference Include="..\CassetteHelper\CassetteHelper.csproj">
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using CassetteHelper;
2+
using MbUnit.Framework;
3+
4+
namespace CassetteHelperTests
5+
{
6+
[TestFixture]
7+
public class StringURIExtensionsTests
8+
{
9+
[Test]
10+
[Row(@"c:\", @"c:\foo.js", "foo.js")]
11+
[Row(@"c:\", @"C:\foo.js", "foo.js")] // case insentitive
12+
[Row(@"c:\", @"c:\test", "test")] // directory
13+
[Row(@"c:\", @"c:\test\foo.js", "test/foo.js")] // subdirectory
14+
[Row(@"c:\test.js", @"c:\foo.js", "foo.js")] // sibling
15+
[Row(@"c:\test\foo.js", @"c:\foo.js", "../foo.js")] // parent
16+
public void URIRelativeTo(string baseFile, string currentFile, string expected)
17+
{
18+
Assert.AreEqual(expected, currentFile.URIRelativeTo(baseFile));
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)