Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #634 from thecodejunkie/viewlocationconventionsreo…
Browse files Browse the repository at this point in the history
…rder-632

Updated view location convention order
  • Loading branch information
grumpydev committed Jun 21, 2012
2 parents 86f2b5c + d92d03b commit 5bd57a1
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 17 deletions.
Expand Up @@ -122,7 +122,7 @@ public void Should_define_convention_that_returns_viewname()
{ {
// Given // Given
this.viewLocationConventions.Initialise(this.conventions); this.viewLocationConventions.Initialise(this.conventions);
var convention = this.conventions.ViewLocationConventions[0]; var convention = this.conventions.ViewLocationConventions[5];


// When // When
var result = convention.Invoke( var result = convention.Invoke(
Expand All @@ -139,7 +139,7 @@ public void Should_define_convention_that_returns_viewname_in_views_folder()
{ {
// Given // Given
this.viewLocationConventions.Initialise(this.conventions); this.viewLocationConventions.Initialise(this.conventions);
var convention = this.conventions.ViewLocationConventions[1]; var convention = this.conventions.ViewLocationConventions[4];


// When // When
var result = convention.Invoke( var result = convention.Invoke(
Expand All @@ -156,7 +156,7 @@ public void Should_define_convention_that_returns_viewname_in_modulepath_subfold
{ {
// Given // Given
this.viewLocationConventions.Initialise(this.conventions); this.viewLocationConventions.Initialise(this.conventions);
var convention = this.conventions.ViewLocationConventions[2]; var convention = this.conventions.ViewLocationConventions[0];


// When // When
var result = convention.Invoke( var result = convention.Invoke(
Expand All @@ -173,7 +173,7 @@ public void Should_define_convention_that_returns_viewname_in_modulepath_subfold
{ {
// Given // Given
this.viewLocationConventions.Initialise(this.conventions); this.viewLocationConventions.Initialise(this.conventions);
var convention = this.conventions.ViewLocationConventions[2]; var convention = this.conventions.ViewLocationConventions[0];


// When // When
var result = convention.Invoke( var result = convention.Invoke(
Expand All @@ -185,12 +185,46 @@ public void Should_define_convention_that_returns_viewname_in_modulepath_subfold
result.ShouldEqual("views/modulepath/viewname"); result.ShouldEqual("views/modulepath/viewname");
} }


[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] [Fact]
public void Should_define_convention_that_returns_viewname_in_modulepath_folder() public void Should_define_convention_that_returns_viewname_in_modulepath_folder()
{ {
// Given // Given
this.viewLocationConventions.Initialise(this.conventions); this.viewLocationConventions.Initialise(this.conventions);
var convention = this.conventions.ViewLocationConventions[3]; var convention = this.conventions.ViewLocationConventions[2];


// When // When
var result = convention.Invoke( var result = convention.Invoke(
Expand All @@ -202,12 +236,46 @@ public void Should_define_convention_that_returns_viewname_in_modulepath_folder(
result.ShouldEqual("modulepath/viewname"); result.ShouldEqual("modulepath/viewname");
} }


[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] [Fact]
public void Should_define_convention_that_returns_viewname_in_modulepath_folder_when_modulepath_contains_leading_slash() public void Should_define_convention_that_returns_viewname_in_modulepath_folder_when_modulepath_contains_leading_slash()
{ {
// Given // Given
this.viewLocationConventions.Initialise(this.conventions); this.viewLocationConventions.Initialise(this.conventions);
var convention = this.conventions.ViewLocationConventions[3]; var convention = this.conventions.ViewLocationConventions[2];


// When // When
var result = convention.Invoke( var result = convention.Invoke(
Expand All @@ -224,7 +292,7 @@ public void Should_define_convention_that_returns_viewname_in_modulename_subfold
{ {
// Given // Given
this.viewLocationConventions.Initialise(this.conventions); this.viewLocationConventions.Initialise(this.conventions);
var convention = this.conventions.ViewLocationConventions[4]; var convention = this.conventions.ViewLocationConventions[1];


// When // When
var result = convention.Invoke( var result = convention.Invoke(
Expand All @@ -241,7 +309,7 @@ public void Should_define_convention_that_returns_viewname_in_modulename_folder(
{ {
// Given // Given
this.viewLocationConventions.Initialise(this.conventions); this.viewLocationConventions.Initialise(this.conventions);
var convention = this.conventions.ViewLocationConventions[5]; var convention = this.conventions.ViewLocationConventions[3];


// When // When
var result = convention.Invoke( var result = convention.Invoke(
Expand Down
18 changes: 9 additions & 9 deletions src/Nancy/Conventions/DefaultViewLocationConventions.cs
Expand Up @@ -39,29 +39,29 @@ private static void ConfigureViewLocationConventions(NancyConventions convention
{ {
conventions.ViewLocationConventions = new List<Func<string, object, ViewLocationContext, string>> conventions.ViewLocationConventions = new List<Func<string, object, ViewLocationContext, string>>
{ {
(viewName, model, viewLocationContext) => { (viewName, model, viewLocationContext) =>{
return viewName; return string.IsNullOrEmpty(viewLocationContext.ModulePath) ? string.Empty : string.Concat("views/", viewLocationContext.ModulePath.TrimStart(new[] {'/'}), "/", viewName);
}, },


(viewName, model, viewLocationContext) => { (viewName, model, viewLocationContext) => {
return string.Concat("views/", viewName); return string.Concat("views/", viewLocationContext.ModuleName, "/", viewName);
}, },


(viewName, model, viewLocationContext) => { (viewName, model, viewLocationContext) =>{
return string.Concat("views/", viewLocationContext.ModulePath.TrimStart(new[] {'/'}), "/", viewName); return string.IsNullOrEmpty(viewLocationContext.ModulePath) ? string.Empty : string.Concat(viewLocationContext.ModulePath.TrimStart(new[] { '/' }), "/", viewName);
}, },


(viewName, model, viewLocationContext) => { (viewName, model, viewLocationContext) => {
return string.Concat(viewLocationContext.ModulePath.TrimStart(new[] { '/' }), "/", viewName); return string.Concat(viewLocationContext.ModuleName, "/", viewName);
}, },


(viewName, model, viewLocationContext) => { (viewName, model, viewLocationContext) => {
return string.Concat("views/", viewLocationContext.ModuleName, "/", viewName); return string.Concat("views/", viewName);
}, },


(viewName, model, viewLocationContext) => { (viewName, model, viewLocationContext) => {
return string.Concat(viewLocationContext.ModuleName, "/", viewName); return viewName;
} },
}; };
} }
} }
Expand Down

0 comments on commit 5bd57a1

Please sign in to comment.