By Developers, For Developers

Historical errata for Test-Drive ASP.NET MVC

PDF PgPaper PgTypeDescriptionFixed onComments
69TYPO

Missing closing bracket in
<%= Html.Hidden(“oldTitle”, Model.Title %>

2010-09-13
10TYPO

“… the action Index() looks for the file /View/Home/Index.aspx” should be “…/Views/…”

2010-09-13
46TYPO

“Line 22 of the test asserts that the collection ThingsToDo…” should be “Line 20…”

2010-09-13
57TYPO

missing right parenthesis after Model.Title in code snippet <%= Html.Hidden(“oldTitle”, Model.Title %>

2010-09-13
85TYPO

”…we’re adding a new key called View-Name[“Topics”].” Should be ViewData[“Topics”]

2010-09-13
70TYPO

the book shows Content ID=“Content1” for both the “Head” and “MainContent” sections, but when I generated the view, it generated “Content1” for “MainContent” and “Content2” for “Head”. Should be as generated by Visual Studio (Contents1,Contents2)

2010-09-13
96TYPO

File indicated after line “Now let’s get this test to pass:” should be “helper/TestHelper.cs” not “controllers/TodoControllerTest.cs”

2010-09-13
103TYPO

gray-background file indicator shows “controllers/SessionSummary.cs”, should be “models/SessionSummary.cs” to jibe with text “We’ll create SessionSummary under the Model directory,…”

2010-09-13
103TYPO

“if (other.AddedTodos.Count != other.AddedTodos.Count) return false;” should be “if (AddedTodos.Count != other.AddedTodos.Count) return false;”

2010-09-13
105ERROR

Need to call out that after adding private CreateTodo() it makes other tests fail (specifically Should_Add_ToDo_Item). This is a natural part of TDD, you make one test pass and others will fail. Tutorial should either point out how to fix the Should_Add_ToDo_Item test, or ask the reader to strike out on their own and compare their answers to the downloadable code in GetOrganizedFinal.

2010-09-13
101ERROR

ViewData[“UserName”] = User.Identity.Name;
to Index() in TodoController.cs. This does allow the latest test, Should_Set_Logged_In_User_To_ViewData, to pass, but it causes the older test, Should_Display_A_List_Of_Todo_Items, to fail. FWIW, I noticed that in the final version of the downloaded code, Should_Display_A_List_Of_Todo_Items doesn’t exist as such. Should I delete it?

Need to show how to get this test to pass, or have the reader strike out on their own to get it to pass.

2010-09-13
109ERROR

Missing this test from the downloadable code. Also test appears to be failing, the parameters in the querystring don’t seem to be there.

2010-09-13
126TYPO

Rewrite of ThoughtController.Create shows “ViewData[”RealTopics“]” ; should be “ViewData[”Topics“]” (no outer quotes for either)

2010-09-13
130TYPO

Code listing starts with a superfluous(?) string, 

2010-09-13
132TYPO

Just about every file indicator (black on gray) shows “views/…”, even when the files obviously don’t go in “views”

2010-09-13
133TYPO

Last line in Should_Display_errors_When_Todo_Is_Not_Valid should be “Assert.IsTrue(modelState.ContainsKey(”Title“));”

2010-09-13
142TYPO

colorpicker.css listed twice

2010-09-13
173TYPO

“The test requires a new method, GetAll(), on line 8”: method name should be Get

2010-09-13
75ERROR

“We’re also required to override
GetHashCode( ) to help support collections, such as List.”

This statement isn’t correct.
We have to override GetHashCode() because we overrode
Equals(). Collections will work fine for all user reference types without overriding GetHashCode() providing that Equals() wasn’t overridden in a reference type.
There is discussion about this on stackoverflow.com

2010-09-13
81TYPO

There should be quotation mark after colorpicker.css,
like this
<link href=“<: ResolveUrl(“~/Content/colorpicker.css”)>” rel=“Stylesheet” type=“text/css” />

2010-09-13
37SUGGEST

‘namespace GetOrganized.Models’ should be
‘namespace GetOrganized.Web.Models’ when the default namespace is changed as is instructed on page 33.

2010-09-13
69TYPO

missing ending double quote in function ResolveUrl in :

<link href=“<%= ResolveUrl(”~/Content/colorpicker.css“) %>” rel=“Stylesheet” type=“text/css” />

2010-09-13
78SUGGEST

The TodoController.Convert method should have an HttpPost attribute, because it is taking action and changing data.

2010-09-23
24ERROR

When explaining the new NUnit assertion format, the author makes a subtle, yet important semantic error. The new Assert.That style of assertion places the value under test first. The example should read:

Assert.That(new Welcomer().SayHello(), Is.EqualTo(“Hello World”));

The reason it is important is the error message you get when the assertion fails. The second part is what is expected. The new Assert.That format has more descriptive error messages, so they are preferred.

The change was intentional because it was more natural to understand that the first parameter is what is under test. (Can’t tell you how many people have reversed these in the legacy assertion format over the years). For newcomers to unit testing, the Assert.That format will likely prove easier to learn, and in the end are far more powerful.

8ERROR

It should probably be made more explicit that if using the Express Editions of VS, ReSharper cannot be installed. This is because the Express Editions do not support Add-Ins and Extensions. (per jetbrains.net)

24ERROR

In the Assert.That(…

SayHello() is static in Welcomer, and so doesn’t need a new instance.

64TYPO

We assign a model to a list of Topics…

Should be

We assign a list of Topics to a model

96SUGGEST

On page 96, it says to write a test covering Create() to restrict to logged in users only. However by having Authorise on the class (as we already do) you already have the same effect.

97ERROR

Page 97, Sec 5.3, Have brought in the MVC Contrib dll and tried out the Test, but it fails to assert. Think there is something missing in this section and more needs to be done to setup the test.

113ERROR

It says that changing Mime type from application/octet-stream to image/jpg would render it as an image. In fact it appears to make no difference and it still comes up with a show/save box.

109SUGGEST

I found the test on page 109 worked fine for me.

133ERROR

in Should_Display_Errors_When_Todo_Is_Not_Valid()

Need to create a todoController to access the Create method. so needs to be new todoController().Create(…

136TYPO

To keep functionality same, on delete column need .Attributes(onclick => “return confirm(‘Are you sure you want to delete this?’);”)

151TYPO

The code for CreateElements is the old code copied in, and not the required code for the partial.

167TYPO

Code on page doesn’t match that in solution. e.g class needs to be sealed, the Id maps to Id not title, etc.

173TYPO

..test requires a new method, GetAll()… - should be Get()

172ERROR

Sec 8.5, line 8, parameter should be originalTodo.Id, as that defines the key

179TYPO

… then OpenSession() is called… it should read OpenCurrent() is called.

185TYPO

… every time it is created, whereas … : created should be “called”

97ERROR

The figure on that page suggests that we have to implement the Equals() function for the Topic class. But there’s another implementation of Equals() that we are missing to pass the unit test: the one for the Topic class. I know it’s mentioned in passing on page #95, but it would be nice to emphasis this a little more.
Here’s my suggestion for the Equals() in Topic:

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof(Todo)) return false;
var other = (Todo)obj;
return other.Completed Completed && other.TitleTitle &&
other.OutcomeOutcome && other.TopicTopic
; ;
}

As a general rule, some bits and pieces are missing to complete the application in the book. This is good, because it forces us to think. But it might be good to emphasise these missing bits more, ore to put them as exercises.
For instance, prompt the readers to figure out how to delete a Topic. Or to display clean error message on the Process view when the list of thoughts is empty.

Otherwise, I really enjoyed the book. Thanks.

106TYPO

“5.2 Logging In
We will apply some of this theory back into our code. Every web application
has a login page, unless you have a central authorization service
such as Active Directory handling that for you.”

Should probably read:
“5.2 Logging In
We will apply some of this theory back into our code. Every web application
has a login page, unless you have a central authorization service
such as Active Directory handling TO DO that for you.”

144TYPO

Last paragraph: “On line 22 we select the element…”
Should be line 15.

CUOBnfzBZfERROR

That’s way the bseetst answer so far!

96TYPO

In TodoController:

[HttpPost]
public ActionResult Create(Todo todo)
{
try
{
CreateTodo(newTodo);
return RedirectToAction(“Index” );
}
catch
{
return View();
}
}

there is NO newTodo. Should be todo.

107TYPO

For PDF Version: 2010-06-28

Actual Sentence:
We gave it the type ICustomerAttributeProvider…

Should be:
We gave it the type ICustomAttributeProvider…

175ERROR

instead:
<% Html.RenderPartial(“CreateElements” ); %>

should be:
<% Html.RenderPartial(“CreateElements”, new GetOrganized.Models.Todo()); %>

Categories: