p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9 (http://p2p.wrox.com/forumdisplay.php?f=490)
-   -   Chapter 1 - NerdDinner - Errors (http://p2p.wrox.com/showthread.php?t=73701)

Steve S April 1st, 2009 04:53 PM

Chapter 1 - NerdDinner - Errors
 
The pdf version of chapter one is great, thanks. However I did find an error in the code. On pdf page 105 (book 103) the ActionResults Edit shows an attribute of [Authorize]. This should be left out of the code until later (pdf page 126) when authorization is discussed. Including it will produce a challenge response for using the edit page with the newly added country drop down.

Steve S April 3rd, 2009 06:38 PM

on page 105 of the PDF the instructions state:
We’ll then update our view template so that it expects a “DinnerFormViewModel” instead of a “Dinner”
object by changing the “inherits” attribute at the top of the edit.aspx page like so:
Inherits="System.Web.Mvc.ViewPage<NerdDinner.Contr ollers.DinnerFormViewModel>

The inherits statement needs to also be included in the create.aspx. The follwing pages address making the required changes to the ActionResult methods for both the edit and ceate, but the inherit for the create.aspx is not mentioned. This generates an error otherwise.

Steve S April 3rd, 2009 06:48 PM

page 116 of the pdf:

All of the view templates we’ve created for our NerdDinner application (“List”, “Details”, “Edit”,
“Create”, “NotFound”, etc) have been based on this Site.master template. This is indicated via the
“MasterPageFile” attribute that was added by default to the top <% @ Page %> directive when we
created our views using the “Add View” dialog:

Code:

<%@ Page Language="C#"
Inherits="System.Web.Mvc.ViewPage<NerdDinner.Controllers.DinnerViewModel>"
MasterPageFile="~/Views/Shared/Site.Master" %>

There is no "List" View (probably means Index) and only the "Edit" And "Create" use the <NerdDinner.Controllers.DinnerViewModel> the "Details" uses <NerdDinner.Models.Dinner> and the "Not Found" uses 'none of the above'

They do all use the same master page, which is the point being made, but implying that all use the same <% @ page %> is a erroneous.

Steve S April 3rd, 2009 08:00 PM

bottom of page 125:

We can then update the \Views\Dinners\Index.aspx view template to inherit from ViewPage <NerdDinner.Helpers.PaginatedList<Dinner>> instead of ViewPage<IEnumerable<Dinner>>,
and then add the following code to the bottom of our view-template to show or hide next and previous
navigation UI:

This should really be
<NerdDinner.Helpers.PaginatedList<NerdDinner.Models.Dinner>> per the sample code.

Steve S April 9th, 2009 01:14 PM

The first 100 - ~130 pages are pretty good with good accuracy, but after that things start getting dicey.

I've been going back and forth with the AJAX map on pages 146 - 155 following step by step. No errors, but no map either. I've tested the sample code and it works as outlined, but following the first chapter pdf doesn't. So far I can not see what is preventing the code from working and have tried easter egging the download code with the sample code and still have not gotten the map to show up.

Beyond page 144 Scott starts introducing named div tags in the code with no mention of them or the CSS, which is also much different in the download code than comes with a new project creation; which is to be expected, but it would have been nice if it weren't foregotten.

Yes, I could just use the download code, but the knowledge transfer ins't as great as the hands on step-by-step approach that the first chapter is supposed to be.

I would expect Wrox and the Gu are going to field lots of traffic on the last 50 pages of chapter one.

My Bad. On Page 145 is this snippet
<script src="/Scripts/jQuery-1.3.2.js" type="text/javascript"></script>
I grabbed this one from the working download sample
<script src="/Scripts/jquery-1.2.6.js" type="text/javascript"></script>

Little bit of a versioning issue there. Now the maps are showing, but in the wrong size and location

Steve S April 10th, 2009 03:33 PM

I am growing more than a little frustrated in Scott Gu's walk through tutorial. The further into it I get it is obvious that there was little attention to detail towards the end on Scott's part and even less by any technical editor.

On page 181 is:
Code:

[TestMethod]
public void EditAction_Should_Return_View_For_ValidDinner() {
// Arrange
var controller = CreateDinnersController();
// Act
var result = controller.Edit(1) as ViewResult;
// Assert
Assert.IsInstanceOfType(result.ViewData.Model,
typeof(DinnerFormViewModel));
}

As Pointed out this test fails for lack of User Identity, so far so good. To address this the subject of mocking is brought up, along with a URL to download Moq, which I did (version 3.0.802)

At the top of page 183 a new DinnersController is created using the new mocking:
Code:

DinnersController CreateDinnersControllerAs(string userName) {
var mock = new Mock<ControllerContext>();
mock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns(userName);
mock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
var controller = CreateDinnersController();
controller.ControllerContext = mock.Object;
return controller;
}

On Page 183 two more tests are added:
Code:

[TestMethod]
public void EditAction_Should_Return_EditView_When_ValidOwner() {
// Arrange
var controller = CreateControllerAs("SomeUser");
// Act
var result = controller.Edit(1) as ViewResult;
// Assert
Assert.IsInstanceOfType(result.ViewData.Model,
typeof(DinnerFormViewModel));
}
[TestMethod]
public void EditAction_Should_Return_InvalidOwnerView_When_InvalidOwner() {
// Arrange
var controller = CreateControllerAs("NotOwnerUser");
// Act
var result = controller.Edit(1) as ViewResult;
// Assert
Assert.AreEqual(result.ViewName, "InvalidOwner");
}

As shown higlighted in Red the tests call a non existent create routine. Also There seems to be a disconnect between the download code and the PDF chapter. EditAction_Should_Return_EditView_When_ValidOwner( ) is in the book but not in the download code. The download code has EditAction_Should_Return_View_For_ValidDinner(), which is modfied to address the user shown in the first code section above from page 181.

And, to top it off the tests are now not being executed because the downloaded moq.dll is not trusted. Arrrrrgghhh[:(!]

Steve S April 10th, 2009 04:57 PM

On pdf page 83 the AddRuleViolations method is added to the Control Helpers class and is used/mentioned through page 100 several times. By the time the reader is at page 184 this method is no longer mentioned or used and a new method AddModelErrors is introduced in its stead.

I realize that over the course of a tutorial calls and items will be changed and improvements will be made; it would be helpfull to the user following the tutorial if these changes were a bit more explicit than just depracted with no mention. It would allow the student a higher success rate, less frustration and fewer inqueries to the author or publisher about them.

All in all a good tutorial but the last 60 pages could have used more attention to detail and better technical editing.

njappboy May 7th, 2009 07:01 PM

/Dinners/Create POST error
 
has anyone else run into this issue (our did I just not read carefully and miss a code change)

on page 89 (chapter 1) the DinnersController implements a Create (POST) method to create/persist a new Dinner object.

The code shown in the book is as follows:
Code:

//
// POST: /Dinners/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Dinner dinner) {
if (ModelState.IsValid) {
try {
dinner.HostedBy = "SomeUser";
dinnerRepository.Add(dinner);
dinnerRepository.Save();
return RedirectToAction("Details", new {id = dinner.DinnerID });
}
catch {
ModelState.AddRuleViolations(dinner.GetRuleViolations());
}
}
return View(dinner);
}

I don't see how this method is supposed to ever work properly for a few reasons:
  1. HostedBy has a validation rule (pg 39) that says it can't be null or empty. In this case it will always be null when IsValid is called because the property isn't set until the
    Code:

    if (ModelState.IsValid)
    condition is met.
  2. If the model is not valid the view is returned but a call to
    Code:

    ModelState.AddRuleViolations(dinner.GetRuleViolations());
    is never made so the actual rule violations are not added to the ModelState and consequently no error are displayed on the view.
Did I miss a step outlined in the chapter or is this an accurate assessment of this implementation?

sakshamgautam June 13th, 2009 03:25 PM

Small CSS Error
 
Style for hr element in the file: Site.css looks like this:

Code:

hr
{
    padding:0px, 10px, 0px, 10px;
    height:1px;
}

I know that it's really small detail, but the value should be without commas!

S.

AbrarP October 8th, 2009 06:23 AM

Dinner Controller Class
 
There seems to be an error in the errata of this book...

pg 71... They discuss the cleanliness of creating of extending the ModelState Dictionary by adding an AddRuleViolations method... this is all fair except that when you try to compile the code it wont build cos its fraught with errors. So is the errata of this book... it just make no sense.

Anyone experience issues with this?


All times are GMT -4. The time now is 01:01 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.