From 644c45ae5c0282e5215200c33c03ee79365135d4 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 30 Jul 2014 14:56:20 -0700 Subject: [PATCH] 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. --- src/MusicStore/MusicStore.kproj | 2 + src/MusicStore/Views/Account/Login.cshtml | 2 - src/MusicStore/Views/Account/Manage.cshtml | 2 - src/MusicStore/Views/Account/Register.cshtml | 2 - .../Views/Checkout/AddressAndPayment.cshtml | 2 - src/MusicStore/Views/Checkout/Complete.cshtml | 2 - src/MusicStore/Views/Home/Index.cshtml | 2 - .../Views/Shared/Components/_ViewStart.cshtml | 4 + src/MusicStore/Views/Shared/Error.cshtml | 2 - .../Views/ShoppingCart/Index.cshtml | 2 - src/MusicStore/Views/Store/Browse.cshtml | 2 - src/MusicStore/Views/Store/Details.cshtml | 2 - src/MusicStore/Views/Store/Index.cshtml | 28 ++--- .../Views/StoreManager/Create.cshtml | 2 - .../Views/StoreManager/Details.cshtml | 2 - src/MusicStore/Views/StoreManager/Edit.cshtml | 2 - .../Views/StoreManager/Index.cshtml | 116 +++++++++--------- .../Views/StoreManager/RemoveAlbum.cshtml | 2 - src/MusicStore/Views/_ViewStart.cshtml | 3 + test/E2ETests/SmokeTests.cs | 21 +++- 20 files changed, 95 insertions(+), 107 deletions(-) create mode 100644 src/MusicStore/Views/Shared/Components/_ViewStart.cshtml create mode 100644 src/MusicStore/Views/_ViewStart.cshtml diff --git a/src/MusicStore/MusicStore.kproj b/src/MusicStore/MusicStore.kproj index f0e4bc61b2..c3e2a081bb 100644 --- a/src/MusicStore/MusicStore.kproj +++ b/src/MusicStore/MusicStore.kproj @@ -61,6 +61,7 @@ + @@ -73,6 +74,7 @@ + diff --git a/src/MusicStore/Views/Account/Login.cshtml b/src/MusicStore/Views/Account/Login.cshtml index f31debf962..0f5fa2c1ce 100644 --- a/src/MusicStore/Views/Account/Login.cshtml +++ b/src/MusicStore/Views/Account/Login.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/Account/Manage.cshtml b/src/MusicStore/Views/Account/Manage.cshtml index fef49f927d..714decf75b 100644 --- a/src/MusicStore/Views/Account/Manage.cshtml +++ b/src/MusicStore/Views/Account/Manage.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/Account/Register.cshtml b/src/MusicStore/Views/Account/Register.cshtml index b6a0891300..7eb99e5b56 100644 --- a/src/MusicStore/Views/Account/Register.cshtml +++ b/src/MusicStore/Views/Account/Register.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/Checkout/AddressAndPayment.cshtml b/src/MusicStore/Views/Checkout/AddressAndPayment.cshtml index 2fe088a9a9..41f8472a11 100644 --- a/src/MusicStore/Views/Checkout/AddressAndPayment.cshtml +++ b/src/MusicStore/Views/Checkout/AddressAndPayment.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/Checkout/Complete.cshtml b/src/MusicStore/Views/Checkout/Complete.cshtml index a5a5e4c244..9546e23626 100644 --- a/src/MusicStore/Views/Checkout/Complete.cshtml +++ b/src/MusicStore/Views/Checkout/Complete.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/Home/Index.cshtml b/src/MusicStore/Views/Home/Index.cshtml index 2427e67ead..b908309310 100644 --- a/src/MusicStore/Views/Home/Index.cshtml +++ b/src/MusicStore/Views/Home/Index.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/Shared/Components/_ViewStart.cshtml b/src/MusicStore/Views/Shared/Components/_ViewStart.cshtml new file mode 100644 index 0000000000..8570cc72dd --- /dev/null +++ b/src/MusicStore/Views/Shared/Components/_ViewStart.cshtml @@ -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; +} \ No newline at end of file diff --git a/src/MusicStore/Views/Shared/Error.cshtml b/src/MusicStore/Views/Shared/Error.cshtml index 3a7b5effbb..dd26209ba7 100644 --- a/src/MusicStore/Views/Shared/Error.cshtml +++ b/src/MusicStore/Views/Shared/Error.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/ShoppingCart/Index.cshtml b/src/MusicStore/Views/ShoppingCart/Index.cshtml index 28243b0f76..65d422b527 100644 --- a/src/MusicStore/Views/ShoppingCart/Index.cshtml +++ b/src/MusicStore/Views/ShoppingCart/Index.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/Store/Browse.cshtml b/src/MusicStore/Views/Store/Browse.cshtml index 377c8333db..a05188fa9b 100644 --- a/src/MusicStore/Views/Store/Browse.cshtml +++ b/src/MusicStore/Views/Store/Browse.cshtml @@ -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"; }
diff --git a/src/MusicStore/Views/Store/Details.cshtml b/src/MusicStore/Views/Store/Details.cshtml index 97303aa0fb..4b07337acc 100644 --- a/src/MusicStore/Views/Store/Details.cshtml +++ b/src/MusicStore/Views/Store/Details.cshtml @@ -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; } diff --git a/src/MusicStore/Views/Store/Index.cshtml b/src/MusicStore/Views/Store/Index.cshtml index c6d081ee57..06f782f647 100644 --- a/src/MusicStore/Views/Store/Index.cshtml +++ b/src/MusicStore/Views/Store/Index.cshtml @@ -1,17 +1,15 @@ @model IEnumerable - @{ - //TODO: Until we have a way to specify the layout page at application level. - Layout = "/Views/Shared/_Layout.cshtml"; - ViewBag.Title = "Store"; - } -

Browse Genres

+@{ + ViewBag.Title = "Store"; +} +

Browse Genres

-

- Select from @Model.Count() genres: -

-
    - @foreach (var genre in Model) - { -
  • @Html.ActionLink(genre.Name, "Browse", new { genre = genre.Name })
  • - } -
\ No newline at end of file +

+ Select from @Model.Count() genres: +

+
    + @foreach (var genre in Model) + { +
  • @Html.ActionLink(genre.Name, "Browse", new { genre = genre.Name })
  • + } +
\ No newline at end of file diff --git a/src/MusicStore/Views/StoreManager/Create.cshtml b/src/MusicStore/Views/StoreManager/Create.cshtml index d69a2afbde..3a153316af 100644 --- a/src/MusicStore/Views/StoreManager/Create.cshtml +++ b/src/MusicStore/Views/StoreManager/Create.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/StoreManager/Details.cshtml b/src/MusicStore/Views/StoreManager/Details.cshtml index 16b1862920..dd72e8d82f 100644 --- a/src/MusicStore/Views/StoreManager/Details.cshtml +++ b/src/MusicStore/Views/StoreManager/Details.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/StoreManager/Edit.cshtml b/src/MusicStore/Views/StoreManager/Edit.cshtml index e4297853fb..3e9def0bfb 100644 --- a/src/MusicStore/Views/StoreManager/Edit.cshtml +++ b/src/MusicStore/Views/StoreManager/Edit.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/StoreManager/Index.cshtml b/src/MusicStore/Views/StoreManager/Index.cshtml index 9215cb846c..74f258fa3d 100644 --- a/src/MusicStore/Views/StoreManager/Index.cshtml +++ b/src/MusicStore/Views/StoreManager/Index.cshtml @@ -1,66 +1,64 @@ @model IEnumerable - @helper Truncate(string input, int length) +@helper Truncate(string input, int length) { - if (input.Length <= length) - { - @input - } - else - { - @input.Substring(0, length)... - } + if (input.Length <= length) + { + @input + } + else + { + @input.Substring(0, length)... + } } - @{ - //TODO: Until we have a way to specify the layout page at application level. - Layout = "/Views/Shared/_Layout.cshtml"; - ViewBag.Title = "Index"; +@{ + ViewBag.Title = "Index"; +} + +

Index

+ +

+ @Html.ActionLink("Create New", "Create") +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } -

Index

- -

- @Html.ActionLink("Create New", "Create") -

-
+ @Html.DisplayNameFor(model => model.Genre.Name) + + @Html.DisplayNameFor(model => model.FirstOrDefault().Artist.Name) + + @Html.DisplayNameFor(model => model.FirstOrDefault().Title) + + @Html.DisplayNameFor(model => model.FirstOrDefault().Price) +
+ @Html.ValueFor(modelItem => item.Genre.Name) + + @Truncate(item.Artist.Name, 25) + + @Truncate(item.Title, 25) + + @Html.ValueFor(modelItem => item.Price) + + @Html.ActionLink("Edit", "Edit", new { id = item.AlbumId }) | + @Html.ActionLink("Details", "Details", new { id = item.AlbumId }) | + @Html.ActionLink("Delete", "RemoveAlbum", new { id = item.AlbumId }) +
- - - - - - - - - @foreach (var item in Model) - { - - - - - - - - } - -
- @Html.DisplayNameFor(model => model.Genre.Name) - - @Html.DisplayNameFor(model => model.FirstOrDefault().Artist.Name) - - @Html.DisplayNameFor(model => model.FirstOrDefault().Title) - - @Html.DisplayNameFor(model => model.FirstOrDefault().Price) -
- @Html.ValueFor(modelItem => item.Genre.Name) - - @Truncate(item.Artist.Name, 25) - - @Truncate(item.Title, 25) - - @Html.ValueFor(modelItem => item.Price) - - @Html.ActionLink("Edit", "Edit", new { id = item.AlbumId }) | - @Html.ActionLink("Details", "Details", new { id = item.AlbumId }) | - @Html.ActionLink("Delete", "RemoveAlbum", new { id = item.AlbumId }) -
\ No newline at end of file + \ No newline at end of file diff --git a/src/MusicStore/Views/StoreManager/RemoveAlbum.cshtml b/src/MusicStore/Views/StoreManager/RemoveAlbum.cshtml index 0546b401b5..0e0b4bcccf 100644 --- a/src/MusicStore/Views/StoreManager/RemoveAlbum.cshtml +++ b/src/MusicStore/Views/StoreManager/RemoveAlbum.cshtml @@ -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"; } diff --git a/src/MusicStore/Views/_ViewStart.cshtml b/src/MusicStore/Views/_ViewStart.cshtml new file mode 100644 index 0000000000..ab23e9a239 --- /dev/null +++ b/src/MusicStore/Views/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "/Views/Shared/_Layout.cshtml"; +} \ No newline at end of file diff --git a/test/E2ETests/SmokeTests.cs b/test/E2ETests/SmokeTests.cs index 9d7c236aac..759e84aeca 100644 --- a/test/E2ETests/SmokeTests.cs +++ b/test/E2ETests/SmokeTests.cs @@ -178,12 +178,9 @@ namespace E2ETests { Console.WriteLine("Home page content : {0}", responseContent); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase); - Assert.Contains("
  • Home
  • ", responseContent, StringComparison.OrdinalIgnoreCase); - Assert.Contains("Store ", responseContent, StringComparison.OrdinalIgnoreCase); - Assert.Contains("