View Single Post
  #6 (permalink)  
Old April 10th, 2009, 03:33 PM
Steve S Steve S is offline
Friend of Wrox
Points: 546, Level: 8
Points: 546, Level: 8 Points: 546, Level: 8 Points: 546, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Location: Portland, OR
Posts: 105
Thanks: 3
Thanked 20 Times in 19 Posts
Default

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

Last edited by Steve S; April 10th, 2009 at 03:35 PM..