Browse files

Merge pull request #634 from thecodejunkie/viewlocationconventionsreo…

…rder-632

Updated view location convention order
  • Loading branch information...
2 parents 86f2b5c + d92d03b commit 5bd57a15be480b0fe87546892ca1a6c3c312b5e5 @grumpydev grumpydev committed Jun 21, 2012
View
84 src/Nancy.Tests/Unit/Conventions/DefaultViewLocationConventionsFixture.cs
@@ -122,7 +122,7 @@ public void Should_define_convention_that_returns_viewname()
{
// Given
this.viewLocationConventions.Initialise(this.conventions);
- var convention = this.conventions.ViewLocationConventions[0];
+ var convention = this.conventions.ViewLocationConventions[5];
// When
var result = convention.Invoke(
@@ -139,7 +139,7 @@ public void Should_define_convention_that_returns_viewname_in_views_folder()
{
// Given
this.viewLocationConventions.Initialise(this.conventions);
- var convention = this.conventions.ViewLocationConventions[1];
+ var convention = this.conventions.ViewLocationConventions[4];
// When
var result = convention.Invoke(
@@ -156,7 +156,7 @@ public void Should_define_convention_that_returns_viewname_in_modulepath_subfold
{
// Given
this.viewLocationConventions.Initialise(this.conventions);
- var convention = this.conventions.ViewLocationConventions[2];
+ var convention = this.conventions.ViewLocationConventions[0];
// When
var result = convention.Invoke(
@@ -173,7 +173,7 @@ public void Should_define_convention_that_returns_viewname_in_modulepath_subfold
{
// Given
this.viewLocationConventions.Initialise(this.conventions);
- var convention = this.conventions.ViewLocationConventions[2];
+ var convention = this.conventions.ViewLocationConventions[0];
// When
var result = convention.Invoke(
@@ -186,11 +186,45 @@ public void Should_define_convention_that_returns_viewname_in_modulepath_subfold
}
[Fact]
+ public void Should_return_empty_result_convention_that_returns_viewname_in_modulepath_subfolder_of_views_folder_when_modulepath_is_empty()
+ {
+ // Given
+ this.viewLocationConventions.Initialise(this.conventions);
+ var convention = this.conventions.ViewLocationConventions[0];
+
+ // When
+ var result = convention.Invoke(
+ "viewname",
+ null,
+ new ViewLocationContext { ModulePath = string.Empty });
+
+ // Then
+ result.ShouldEqual(string.Empty);
+ }
+
+ [Fact]
+ public void Should_return_empty_result_convention_that_returns_viewname_in_modulepath_subfolder_of_views_folder_when_modulepath_is_null()
+ {
+ // Given
+ this.viewLocationConventions.Initialise(this.conventions);
+ var convention = this.conventions.ViewLocationConventions[0];
+
+ // When
+ var result = convention.Invoke(
+ "viewname",
+ null,
+ new ViewLocationContext { ModulePath = null });
+
+ // Then
+ result.ShouldEqual(string.Empty);
+ }
+
+ [Fact]
public void Should_define_convention_that_returns_viewname_in_modulepath_folder()
{
// Given
this.viewLocationConventions.Initialise(this.conventions);
- var convention = this.conventions.ViewLocationConventions[3];
+ var convention = this.conventions.ViewLocationConventions[2];
// When
var result = convention.Invoke(
@@ -203,11 +237,45 @@ public void Should_define_convention_that_returns_viewname_in_modulepath_folder(
}
[Fact]
+ public void Should_return_empty_result_for_convention_that_returns_viewname_in_modulepath_folder_when_modulepath_is_empty()
+ {
+ // Given
+ this.viewLocationConventions.Initialise(this.conventions);
+ var convention = this.conventions.ViewLocationConventions[2];
+
+ // When
+ var result = convention.Invoke(
+ "viewname",
+ null,
+ new ViewLocationContext { ModulePath = string.Empty });
+
+ // Then
+ result.ShouldEqual(string.Empty);
+ }
+
+ [Fact]
+ public void Should_return_empty_result_for_convention_that_returns_viewname_in_modulepath_folder_when_modulepath_is_null()
+ {
+ // Given
+ this.viewLocationConventions.Initialise(this.conventions);
+ var convention = this.conventions.ViewLocationConventions[2];
+
+ // When
+ var result = convention.Invoke(
+ "viewname",
+ null,
+ new ViewLocationContext { ModulePath = null });
+
+ // Then
+ result.ShouldEqual(string.Empty);
+ }
+
+ [Fact]
public void Should_define_convention_that_returns_viewname_in_modulepath_folder_when_modulepath_contains_leading_slash()
{
// Given
this.viewLocationConventions.Initialise(this.conventions);
- var convention = this.conventions.ViewLocationConventions[3];
+ var convention = this.conventions.ViewLocationConventions[2];
// When
var result = convention.Invoke(
@@ -224,7 +292,7 @@ public void Should_define_convention_that_returns_viewname_in_modulename_subfold
{
// Given
this.viewLocationConventions.Initialise(this.conventions);
- var convention = this.conventions.ViewLocationConventions[4];
+ var convention = this.conventions.ViewLocationConventions[1];
// When
var result = convention.Invoke(
@@ -241,7 +309,7 @@ public void Should_define_convention_that_returns_viewname_in_modulename_folder(
{
// Given
this.viewLocationConventions.Initialise(this.conventions);
- var convention = this.conventions.ViewLocationConventions[5];
+ var convention = this.conventions.ViewLocationConventions[3];
// When
var result = convention.Invoke(
View
18 src/Nancy/Conventions/DefaultViewLocationConventions.cs
@@ -39,29 +39,29 @@ private static void ConfigureViewLocationConventions(NancyConventions convention
{
conventions.ViewLocationConventions = new List<Func<string, object, ViewLocationContext, string>>
{
- (viewName, model, viewLocationContext) => {
- return viewName;
+ (viewName, model, viewLocationContext) =>{
+ return string.IsNullOrEmpty(viewLocationContext.ModulePath) ? string.Empty : string.Concat("views/", viewLocationContext.ModulePath.TrimStart(new[] {'/'}), "/", viewName);
},
(viewName, model, viewLocationContext) => {
- return string.Concat("views/", viewName);
+ return string.Concat("views/", viewLocationContext.ModuleName, "/", viewName);
},
- (viewName, model, viewLocationContext) => {
- return string.Concat("views/", viewLocationContext.ModulePath.TrimStart(new[] {'/'}), "/", viewName);
+ (viewName, model, viewLocationContext) =>{
+ return string.IsNullOrEmpty(viewLocationContext.ModulePath) ? string.Empty : string.Concat(viewLocationContext.ModulePath.TrimStart(new[] { '/' }), "/", viewName);
},
(viewName, model, viewLocationContext) => {
- return string.Concat(viewLocationContext.ModulePath.TrimStart(new[] { '/' }), "/", viewName);
+ return string.Concat(viewLocationContext.ModuleName, "/", viewName);
},
(viewName, model, viewLocationContext) => {
- return string.Concat("views/", viewLocationContext.ModuleName, "/", viewName);
+ return string.Concat("views/", viewName);
},
(viewName, model, viewLocationContext) => {
- return string.Concat(viewLocationContext.ModuleName, "/", viewName);
- }
+ return viewName;
+ },
};
}
}

0 comments on commit 5bd57a1

Please sign in to comment.