Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve count of SelectList items?

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().?
like image 383
morganpdx Avatar asked Oct 21 '10 17:10

morganpdx


1 Answers

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

like image 112
Craig Stuntz Avatar answered Oct 17 '22 15:10

Craig Stuntz