Improved SinglePage algorithm. Bumped package version to 1.6.6
This commit is contained in:
@ -18,6 +18,8 @@ namespace Rest.Net.Tests
|
||||
|
||||
public string TestFile = null;
|
||||
|
||||
public string IndexFile = null;
|
||||
|
||||
public ServeFileTests()
|
||||
{
|
||||
this.BaseDirectory = Path.Combine(Environment.CurrentDirectory, "test");
|
||||
@ -34,12 +36,17 @@ namespace Rest.Net.Tests
|
||||
|
||||
if (!File.Exists(this.TestFile))
|
||||
File.WriteAllText(this.TestFile, "hello world");
|
||||
|
||||
this.IndexFile = Path.Combine(this.BaseDirectory, "index.html");
|
||||
|
||||
if (!File.Exists(this.IndexFile))
|
||||
File.WriteAllText(this.IndexFile, "hello world");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeMultiple_File_ShouldWork()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "/test.html", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "/test.html", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
@ -49,7 +56,7 @@ namespace Rest.Net.Tests
|
||||
[Fact]
|
||||
public void ServeMultiple_File_WithParentDirectory_ShouldWork()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "test/test.html", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "test/test.html", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
@ -59,7 +66,7 @@ namespace Rest.Net.Tests
|
||||
[Fact]
|
||||
public void ServeMultiple_Directory_ShouldWork()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "/test2", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "/test2", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeTrue();
|
||||
|
||||
@ -69,13 +76,13 @@ namespace Rest.Net.Tests
|
||||
[Fact]
|
||||
public void ServeMultiple_NavigatingUp_Should_NotWork()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "../test.html", null, out string resolvedPath, out bool isDirectory).Should().BeFalse();
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "../test.html", "index.html", out string resolvedPath, out bool isDirectory).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeMultiple_Correct_NavigatingUp_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "a/b/../../test.html", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "a/b/../../test.html", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
@ -85,13 +92,23 @@ namespace Rest.Net.Tests
|
||||
[Fact]
|
||||
public void ServeMultiple_NavigatingUp_Multiple_Should_NotWork()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "test/../../test.html", null, out string resolvedPath, out bool isDirectory).Should().BeFalse();
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "test/../../test.html", "index.html", out string resolvedPath, out bool isDirectory).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_File_ShouldWork()
|
||||
public void ServeSingle_Empty_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/test.html", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
resolvedPath.Should().BeEquivalentTo(this.IndexFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_File_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/test.html", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
@ -99,19 +116,9 @@ namespace Rest.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_File_WithParentDirectory_ShouldWork()
|
||||
public void ServeSingle_Directory_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "test/test.html", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
resolvedPath.Should().BeEquivalentTo(this.TestFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_Directory_ShouldWork()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/test2", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/test2", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeTrue();
|
||||
|
||||
@ -119,9 +126,49 @@ namespace Rest.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_File_Route_ShouldWork()
|
||||
public void ServeSingle_File_Route_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/a/b/test.html", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/a/b/test.html", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
resolvedPath.Should().BeEquivalentTo(this.TestFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_Directory_Route_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/a/b/test2", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeTrue();
|
||||
|
||||
resolvedPath.Should().BeEquivalentTo(this.TestDirectory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_File_Route_Invalid_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/a/b/c", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
resolvedPath.Should().BeEquivalentTo(this.IndexFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_File_WithoutExtension_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/test", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
resolvedPath.Should().BeEquivalentTo(this.TestFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_File_Route_WithoutExtension_Should_Work()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "/a/b/c/test", "index.html", out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
|
Reference in New Issue
Block a user