Adding a _ViewStart page to define the Layoutpage
Removing the Layout page reference from individual cshtml files. Added some tests to verify layout getting rendered in every view. Added a couple of verifications to verify that title of the page is set appropriately.
This commit is contained in:
parent
75d9ef5e0d
commit
644c45ae5c
|
|
@ -61,6 +61,7 @@
|
|||
<Content Include="Views\Home\Index.cshtml" />
|
||||
<Content Include="Views\Shared\Components\CartSummary\Default.cshtml" />
|
||||
<Content Include="Views\Shared\Components\GenreMenu\Default.cshtml" />
|
||||
<Content Include="Views\Shared\Components\_ViewStart.cshtml" />
|
||||
<Content Include="Views\Shared\Error.cshtml" />
|
||||
<Content Include="Views\Shared\_Layout.cshtml" />
|
||||
<Content Include="Views\Shared\_LoginPartial.cshtml" />
|
||||
|
|
@ -73,6 +74,7 @@
|
|||
<Content Include="Views\Store\Browse.cshtml" />
|
||||
<Content Include="Views\Store\Details.cshtml" />
|
||||
<Content Include="Views\Store\Index.cshtml" />
|
||||
<Content Include="Views\_ViewStart.cshtml" />
|
||||
<Content Include="web.config" />
|
||||
<Content Include="web.Debug.config" />
|
||||
<Content Include="web.Release.config" />
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
@model MusicStore.Models.LoginViewModel
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Log in";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Manage Account";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
@model MusicStore.Models.RegisterViewModel
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Register";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
@model MusicStore.Models.Order
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Address And Payment";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
@model int
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Checkout Complete";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Home Page";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
@{
|
||||
//_ViewStart is applicable to ViewComponents as well. Since the layout page renders the ViewComponents in this case adding an override to Layout page to prevent StackOverFlowException.
|
||||
Layout = null;
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Error";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
@model MusicStore.ViewModels.ShoppingCartViewModel
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Shopping Cart";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
@model MusicStore.Models.Genre
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Browse Albums";
|
||||
}
|
||||
<div class="genre">
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
@model MusicStore.Models.Album
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Album - " + Model.Title;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
@model IEnumerable<MusicStore.Models.Genre>
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Store";
|
||||
}
|
||||
<h3>Browse Genres</h3>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
@model MusicStore.Models.Album
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Create";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
@model MusicStore.Models.Album
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Details";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
@model MusicStore.Models.Album
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Edit";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
}
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Index";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
@model MusicStore.Models.Album
|
||||
|
||||
@{
|
||||
//TODO: Until we have a way to specify the layout page at application level.
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Delete";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
@{
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
|
@ -178,12 +178,9 @@ namespace E2ETests
|
|||
{
|
||||
Console.WriteLine("Home page content : {0}", responseContent);
|
||||
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<li><a href=\"/\">Home</a></li>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<a href=\"/Store\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">Store <b class=\"caret\"></b></a>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<ul class=\"dropdown-menu\">", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<li class=\"divider\"></li>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
ValidateLayoutPage(responseContent);
|
||||
Assert.Contains("<a href=\"/Store/Details/", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<title>Home Page – MVC Music Store</title>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Register", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Login", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("mvcmusicstore.codeplex.com", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
|
|
@ -191,12 +188,23 @@ namespace E2ETests
|
|||
Console.WriteLine("Application initialization successful.");
|
||||
}
|
||||
|
||||
private void ValidateLayoutPage(string responseContent)
|
||||
{
|
||||
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<li><a href=\"/\">Home</a></li>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<a href=\"/Store\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">Store <b class=\"caret\"></b></a>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<ul class=\"dropdown-menu\">", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<li class=\"divider\"></li>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private void AccessStoreWithoutPermissions(string userName = null)
|
||||
{
|
||||
Console.WriteLine("Trying to access StoreManager that needs ManageStore claim with the current user : {0}", userName ?? "Anonymous");
|
||||
var response = httpClient.GetAsync("/StoreManager/").Result;
|
||||
ThrowIfResponseStatusNotOk(response);
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
ValidateLayoutPage(responseContent);
|
||||
Assert.Contains("<title>Log in – MVC Music Store</title>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("<h4>Use a local account to log in.</h4>", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Equal<string>(ApplicationBaseUrl + "Account/Login?ReturnUrl=%2FStoreManager%2F", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Console.WriteLine("Redirected to login page as expected.");
|
||||
|
|
@ -218,6 +226,7 @@ namespace E2ETests
|
|||
var response = httpClient.GetAsync("/Account/Register").Result;
|
||||
ThrowIfResponseStatusNotOk(response);
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
ValidateLayoutPage(responseContent);
|
||||
|
||||
var generatedUserName = Guid.NewGuid().ToString().Replace("-", string.Empty);
|
||||
Console.WriteLine("Creating a new user with name '{0}'", generatedUserName);
|
||||
|
|
@ -242,6 +251,7 @@ namespace E2ETests
|
|||
var response = httpClient.GetAsync("/Account/Register").Result;
|
||||
ThrowIfResponseStatusNotOk(response);
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
ValidateLayoutPage(responseContent);
|
||||
|
||||
var generatedUserName = Guid.NewGuid().ToString().Replace("-", string.Empty);
|
||||
Console.WriteLine("Creating a new user with name '{0}'", generatedUserName);
|
||||
|
|
@ -292,6 +302,7 @@ namespace E2ETests
|
|||
var response = httpClient.GetAsync(string.Empty).Result;
|
||||
ThrowIfResponseStatusNotOk(response);
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
ValidateLayoutPage(responseContent);
|
||||
var formParameters = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("__RequestVerificationToken", HtmlDOMHelper.RetrieveAntiForgeryToken(responseContent, "/Account/LogOff")),
|
||||
|
|
|
|||
Loading…
Reference in New Issue