views:

17

answers:

1

Problem: I can't access the count of items in a SelectList

I have an HtmlHelper method that returns a SelectList:

public static SelectList FilterSelectList(this HtmlHelper helper, List<Stuff> eList, string dept)
{
 List<Stuff> returnList = new List<Stuff>();

 //Do Stuff    

 return new SelectList(returnList, "ID", "Name");
}

I then have a test which confirms that the filter was done correctly:

// Arrange
List<Stuff> eList = MVCMocks.GetList();
string dept = "T";
int expectedCount = eList.FindAll(e => e.Dept == dept).Count;

// Act
var actual = HtmlHelpers.FilterSelectList(helper, eList, dept);

// Assert
Assert.AreEqual(expectedCount, actual.Count, "The list was not properly filtered.");

Calling actual.Count results in an error.

I'm hoping this is just a case of me having a stupid oversight, but I've been banging my head on this for a while. Prove me right! :)

EDIT: Stuff I've Tried

actual.Count
actual.Count()
actual.Items.Count()
actual.GetEnumerator().?
+1  A: 

You need actual.Count() (note parens!) not actual.Count.

Craig Stuntz
Newp, tried that. No luck. See my comment above...
morganpdx
Then you don't have a `using System.Linq` in your test class.
Craig Stuntz
Aha! That did it! Thanks Craig :)
morganpdx