Browse files

Reworked test to try and fix/track down the phantom CI fail

  • Loading branch information...
1 parent a17097b commit 0e8707d527f26e5f0df1d8116bc2574b2a9de81b @grumpydev grumpydev committed Feb 13, 2013
Showing with 20 additions and 10 deletions.
  1. +20 −10 src/Nancy.Tests/Unit/StaticContentConventionBuilderFixture.cs
View
30 src/Nancy.Tests/Unit/StaticContentConventionBuilderFixture.cs
@@ -12,6 +12,14 @@ public class StaticContentConventionBuilderFixture
private const string StylesheetContents = @"body {
background-color: white;
}";
+
+ private readonly string directory;
+
+ public StaticContentConventionBuilderFixture()
+ {
+ this.directory = Environment.CurrentDirectory;
+ }
+
[Fact]
public void Should_retrieve_static_content_when_file_name_contains_url_encoded_spaces()
{
@@ -97,14 +105,14 @@ public void Should_skip_the_request_if_resource_is_outside_the_content_folder()
var result = GetStaticContent("css", "../../outside/styles.css");
// Then
- result.ShouldBeNull();
+ result.ShouldEqual("Static content returned an invalid response of (null)");
}
[Fact]
public void Should_retrieve_static_content_when_root_is_relative_path()
{
// Given
- var resources = Path.Combine(Environment.CurrentDirectory, "Resources");
+ var resources = Path.Combine(directory, "Resources");
var relativeRootFolder = Path.Combine(resources, @"../");
// When
@@ -126,7 +134,7 @@ public void Should_throw_security_exception_when_content_path_points_to_root()
};
// When
- var exception = Record.Exception(() => convention.Invoke(context, Environment.CurrentDirectory));
+ var exception = Record.Exception(() => convention.Invoke(context, directory));
// Then
exception.ShouldBeOfType<ArgumentException>();
@@ -144,13 +152,13 @@ public void Should_throw_security_exception_when_content_path_is_null_and_reques
};
// When
- var exception = Record.Exception(() => convention.Invoke(context, Environment.CurrentDirectory));
+ var exception = Record.Exception(() => convention.Invoke(context, directory));
// Then
exception.ShouldBeOfType<ArgumentException>();
}
- private static string GetStaticContent(string virtualDirectory, string requestedFilename, string root = null)
+ private string GetStaticContent(string virtualDirectory, string requestedFilename, string root = null)
{
var resource =
string.Format("/{0}/{1}", virtualDirectory, requestedFilename);
@@ -164,23 +172,25 @@ private static string GetStaticContent(string virtualDirectory, string requested
var resolver =
StaticContentConventionBuilder.AddDirectory(virtualDirectory, "Resources/Assets/Styles");
- var rootFolder = root ?? Environment.CurrentDirectory;
+ var rootFolder = root ?? directory;
GenericFileResponse.SafePaths.Add(rootFolder);
var response =
- resolver.Invoke(context, rootFolder) as GenericFileResponse;
+ resolver.Invoke(context, rootFolder);
+
+ var fileResponse = response as GenericFileResponse;
- if (response != null)
+ if (fileResponse != null)
{
using (var stream = new MemoryStream())
{
- response.Contents(stream);
+ fileResponse.Contents(stream);
return Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Length);
}
}
- return null;
+ return string.Format("Static content returned an invalid response of {0}", response == null ? "(null)" : response.GetType().ToString());
}
}
}

0 comments on commit 0e8707d

Please sign in to comment.