Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'tracing_error_when_no_accept_header' of github.com:code…

…progression/Nancy into codeprogression-tracing_error_when_no_accept_header
  • Loading branch information...
commit 570c3c25f725b9e2f59f0385b27ef838441a1cb9 2 parents 5883865 + 74d2ba5
@grumpydev grumpydev authored
View
21 src/Nancy.Tests.Functional/Modules/RazorWithTracingTestModule.cs
@@ -0,0 +1,21 @@
+namespace Nancy.Tests.Functional.Modules
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
+ public class RazorWithTracingTestModule : NancyModule
+ {
+ public RazorWithTracingTestModule()
+ {
+ StaticConfiguration.EnableRequestTracing = true;
+ Get["/tracing/razor-viewbag"] = _ =>
+ {
+ this.ViewBag.Name = "Bob";
+
+ return View["RazorPage"];
+ };
+ }
+ }
+}
View
2  src/Nancy.Tests.Functional/Nancy.Tests.Functional.csproj
@@ -84,9 +84,11 @@
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
+ <Compile Include="Modules\RazorWithTracingTestModule.cs" />
<Compile Include="Modules\JsonpTestModule.cs" />
<Compile Include="Modules\RazorTestModule.cs" />
<Compile Include="Tests\ContentNegotiationFixture.cs" />
+ <Compile Include="Tests\TracingSmokeTests.cs" />
<Compile Include="Tests\JsonpTests.cs" />
<Compile Include="Tests\ModelBindingTests.cs" />
<Compile Include="Tests\StaticContentTests.cs" />
View
39 src/Nancy.Tests.Functional/Tests/TracingSmokeTests.cs
@@ -0,0 +1,39 @@
+namespace Nancy.Tests.Functional.Tests
+{
+ using System;
+ using Bootstrapper;
+ using Modules;
+ using Testing;
+ using Xunit;
+
+ public class TracingSmokeTests
+ {
+ private readonly INancyBootstrapper bootstrapper;
+
+ private readonly Browser browser;
+
+ public TracingSmokeTests()
+ {
+ this.bootstrapper = new ConfigurableBootstrapper(
+ configuration => configuration.Modules(new Type[] { typeof(RazorWithTracingTestModule) }));
+
+ this.browser = new Browser(bootstrapper);
+ }
+
+ [Fact]
+ public void Should_render_content_from_viewbag()
+ {
+ // Given
+ // When
+ var response = browser.Get(
+ @"/tracing/razor-viewbag",
+ with =>
+ {
+ with.HttpRequest();
+ });
+
+ // Then
+ Assert.True(response.Body.AsString().Contains(@"Hello Bob"));
+ }
+ }
+}
View
1  src/Nancy.Tests/Nancy.Tests.csproj
@@ -129,6 +129,7 @@
<Compile Include="Fakes\Person.cs" />
<Compile Include="Fakes\ViewModel.cs" />
<Compile Include="Unit\Bootstrapper\PipelinesFixture.cs" />
+ <Compile Include="Unit\Conventions\DefaultAcceptHeaderCoercionConventionsFixture.cs" />
<Compile Include="Unit\Conventions\DefaultCultureConventionsFixture.cs" />
<Compile Include="Unit\Conventions\DefaultStaticContentsConventionsFixture.cs" />
<Compile Include="Unit\Culture\BuiltInCultureConventionFixture.cs" />
View
57 src/Nancy.Tests/Unit/Conventions/DefaultAcceptHeaderCoercionConventionsFixture.cs
@@ -0,0 +1,57 @@
+namespace Nancy.Tests.Unit.Conventions
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using Nancy.Conventions;
+ using Nancy.Testing;
+ using Xunit;
+
+ public class DefaultAcceptHeaderCoercionConventionsFixture
+ {
+
+ private readonly NancyConventions conventions;
+ private readonly DefaultAcceptHeaderCoercionConventions acceptHeaderConventions;
+
+ public DefaultAcceptHeaderCoercionConventionsFixture()
+ {
+ this.conventions = new NancyConventions();
+ this.acceptHeaderConventions = new DefaultAcceptHeaderCoercionConventions();
+ }
+
+ [Fact]
+ public void Should_not_be_valid_when_conventions_is_null()
+ {
+ // Given
+ this.conventions.AcceptHeaderCoercionConventions = null;
+
+ // When
+ var result = this.acceptHeaderConventions.Validate(this.conventions);
+
+ // Then
+ result.Item1.ShouldBeFalse();
+ }
+ [Fact]
+ public void Should_return_correct_error_message_when_not_be_valid_because_conventions_is_null()
+ {
+ // Given
+ this.conventions.AcceptHeaderCoercionConventions = null;
+
+ // When
+ var result = this.acceptHeaderConventions.Validate(this.conventions);
+
+ // Then
+ result.Item2.ShouldEqual("The accept header coercion conventions cannot be null.");
+ }
+
+ [Fact]
+ public void Should_add_conventions_when_initialised()
+ {
+ // Given, When
+ this.acceptHeaderConventions.Initialise(this.conventions);
+
+ // Then
+ this.conventions.CultureConventions.Count.ShouldBeGreaterThan(0);
+ }
+ }
+}
View
10 src/Nancy/Routing/DefaultRouteInvoker.cs
@@ -119,6 +119,9 @@ private Response ProcessAsNegotiator(object routeResult, NancyContext context)
var negotiator =
GetNegotiator(routeResult, context);
+ var compatibleHeaders =
+ this.GetCompatibleHeaders(context, negotiator);
+
context.WriteTraceLog(sb =>
{
var allowableFormats = negotiator.NegotiationContext
@@ -126,16 +129,13 @@ private Response ProcessAsNegotiator(object routeResult, NancyContext context)
.Select(mr => mr.ToString())
.Aggregate((t1, t2) => t1 + ", " + t2);
- var acceptFormants = context.Request.Headers["accept"]
+ var acceptFormats = compatibleHeaders.Select(h=>h.Item1)
.Aggregate((t1, t2) => t1 + ", " + t2);
- sb.AppendFormat("[DefaultRouteInvoker] Accept header: {0}\n", acceptFormants);
+ sb.AppendFormat("[DefaultRouteInvoker] Accept header: {0}\n", acceptFormats);
sb.AppendFormat("[DefaultRouteInvoker] Acceptable media ranges: {0}\n", allowableFormats);
});
- var compatibleHeaders =
- this.GetCompatibleHeaders(context, negotiator);
-
if (!compatibleHeaders.Any())
{
context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Unable to negotiate response - no headers compatible"));
Please sign in to comment.
Something went wrong with that request. Please try again.