The following gist shows some examples of what you get:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a link to SingleActionController | |
@Html.ActionLink("Link text", typeof(Type.Of.The.SingleActionController)) | |
// Create a link to SingleActionController with a request and attributes | |
@Html.ActionLink("Another link text", typeof(Type.Of.The.SingleActionController), | |
routeValues: new ShowListRequest | |
{ | |
Property1 = Model.Property1, | |
AnotherProperty = Model.AnotherProperty | |
}, | |
htmlAttributes: new { id = "thelink", @class = "btn" }) | |
// Generate a URL | |
<form action="@Url.Action(typeof(Type.Of.The.SingleActionController))" | |
// Render an action | |
@Html.Action(typeof(Type.Of.The.SingleActionController)) |
If you like type safety and finding errors at compile time rather than build time, you're going to love this approach, together with enabling view compilation.
On top of that I've also added some methods to help with testing of applications built with this library. This is how you verify that an action returns a View:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Verify that a Single Action Controller returns a View | |
var sut = new Some.Controllers.ShowList(with, its, dependencies); | |
var request = new ShowListRequest(); | |
var result = sut.Execute(request); | |
result.AssertIsView() | |
.WithName("_ListPartial") | |
.WithModel<ListViewModel>(p => | |
{ | |
p.Property1.Should().Be(1); | |
p.SomeList.Should().HaveCount(1); | |
}); |
And this is how you check that an action returns a redirect to another Single Action Controller:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Verify that a controller returns a redirect to a Single Action Controller | |
result.AssertIsRedirectToRoute().WithSingleActionController(typeof(ShowList)); |
No comments:
Post a Comment