Skip to content

Commit

Permalink
Merge branch 'interface-advance'
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunle committed Jun 6, 2015
2 parents 4d2d591 + 0ed4be6 commit 6abb9a7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Nancy.AttributeRouting.Tests/RouteAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public class RouteAttributeTests
[InlineData("/before/child/nearest", "Result", "rejected-from-nearest")]
[InlineData("/interface", "Result", "query-from-interface")]
[InlineData("/interface/passed-to-interface", "Result", "passed-to-interface")]
public void Attribute_routing_should_accept_get_request(string path, string expectedKey, string expectedValue)
[InlineData("/interface/child", "Result", "from-child-interface")]
public void Attribute_routing_should_accept_get_request(
string path,
string expectedKey,
string expectedValue)
{
// Act
BrowserResponse response = Browser.Get(path, with => with.Accept("application/json"));
Expand Down
4 changes: 4 additions & 0 deletions Nancy.AttributeRouting.Tests/UrlBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ public static IEnumerable<object[]> TestCases
yield return new TestCase<IInterfaceViewModel>(
m => m.GetWithParamter("value"),
"/interface/value");

yield return new TestCase<IChildViewModel>(
m => m.Get(),
"/interface/child");
}
}

Expand Down
2 changes: 2 additions & 0 deletions Nancy.AttributeRouting.Tests/ViewAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ViewAttributeTests
[InlineData("/html/prefix", "Get view prefix message.")]
[InlineData("/html/prefix/type", "Get type prefix message.")]
[InlineData("/html/prefix/deeper", "Get deeper prefix message.")]
[InlineData("/interface/html", "Get HTML from interface.")]
[InlineData("/interface/html/child", "Get HTML with view prefix from interface.")]
public void View_attribute_should_point_out_file_location(string url, string expectedContent)
{
// Act
Expand Down
51 changes: 48 additions & 3 deletions Nancy.AttributeRouting.Tests/ViewModels/InterfaceViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
namespace Nancy.AttributeRouting.Tests.ViewModels
{
[RoutePrefix("interface")]
public interface IInterfaceViewModel
{
[Get("")]
[Get("interface")]
object Get();

[Get("{value}")]
[Get("interface/{value}")]
object GetWithParamter(string value);
}

[RoutePrefix(typeof(IInterfaceViewModel), "interface")]
public interface IChildViewModel
{
[Get("child")]
object Get();
}

public interface IHtmlViewModel
{
[Get("interface/html")]
[View("view")]
object Get();
}

[ViewPrefix("Prefix")]
public interface IHtmlChildViewModel
{
[Get("interface/html/child")]
[View("view-prefix")]
object Get();
}

public class InterfaceViewModel : IInterfaceViewModel
{
public object Get()
Expand All @@ -21,5 +42,29 @@ public object GetWithParamter(string value)
{
return new { Result = value };
}

public class ChildViewModel : IChildViewModel
{
public object Get()
{
return new { Result = "from-child-interface" };
}
}

public class HtmlViewModel : IHtmlViewModel
{
public object Get()
{
return new { Message = "Get HTML from interface." };
}
}

public class HtmlChildViewModel : IHtmlChildViewModel
{
public object Get()
{
return new { Message = "Get HTML with view prefix from interface." };
}
}
}
}
2 changes: 1 addition & 1 deletion Nancy.AttributeRouting/ViewPrefixAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// The ViewPrefix attribute. It decorates on class, indicates the View attribute works with
/// this prefix to locate paths.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public class ViewPrefixAttribute : Attribute
{
private readonly string prefix;
Expand Down

0 comments on commit 6abb9a7

Please sign in to comment.