I'm diving into ASP.NET MVC 2 and I'm walking through a tutorial and I'm getting an error related to a template method in my unit tests. The erroneous code is...
var displayedProducts = (IList<Product>)result.ViewData.Model;
displayedProducts.Count.ShouldEqual(2);
and the method definition for ShouldEqual
is...
public static void ShouldEqual<T>(this T actualValue, T expectedValue)
{
Assert.AreEqual(expectedValue, actualValue);
}
and the error is...
'int' does not contain a definition for 'ShouldEqual' and no extension method 'ShouldEqual' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)开发者_如何学C
but because I'm so new to all this, I don't see what I missing.
- Does anyone see the problem?
- Can someone explain to me how
ShouldEqual
is a member function ofCount
Thanks so much for your help! If more code is needed, please let me know.
I recognize this... this is from the Steve Sanderson book?
I can reproduce this error if I comment out the using
statement for the namespace where ShouldEqual
is declared.
In the file where you have
var displayedProducts = (IList<Product>)result.ViewData.Model;
displayedProducts.Count.ShouldEqual(2);
can you check and make sure you have a using
statement for the namespace that ShouldEqual
is in?
ShouldEqual is compiler trick only. It's a stand alone function (static class (CLASSNAME) and method). The compiler replaces the call with...
CLASSNAME.ShouldEqual<int>(displayedProducts.Count, 2);
See here for more information : http://msdn.microsoft.com/en-us/library/bb383977.aspx
精彩评论