views:

492

answers:

3

The mstest framework has a CollectionAssert that accepts ICollections. My method returns an IList. Apparantly a list is not a collection..

Are there ways to make my IList an ICollection?

+1  A: 

Isn't IList extending ICollection? I thought so at least.

Magnus
I thought so too :5
borisCallens
+1  A: 

You could call the ToArray() extension method on it - Array implements ICollection

Edit: Also, while List<T> implements ICollection, IList<T> only implements ICollection<T> which does not implement ICollection, so if you know the item in the test is a List<T>, you should be able to cast it...

Lee
+1  A: 

You can send in a List

    List<string> menuesSentIn = new List<string>(){
        "AddCaseRelations",
        "AddRecord",
        "AddRecordToCase",
        "AssignCase",
        "ChangeDiaryNumber",
        "CompleteCase",            
        "CreateCaseFromRecord",
        "Decision",
        "DispatchCase",
        "EditCase",
        "OpenCase",
        "ReceiveComplement",
        "RequestComplementCase",
        "SendCaseTo",
        "ShowVersionHistory"};
    List<string> menuesToHide = actual.GetMenuItemTemplatesToHide(menuesSentIn);
    List<string> menuesExpected = new List<string>(){
        "AddCaseRelations",
        "AddRecord",
        "AddRecordToCase",
        "CompleteCase",            
        "CreateCaseFromRecord",
        "Decision",
        "DispatchCase",
        "**EditCaseFalse**",
        "OpenCase",
        "ReceiveComplement",
        "RequestComplementCase"};
    CollectionAssert.AreEqual(menuesToHide,menuesExpected

As number 7 is forced wrong I get back Failed CreateMenuContextWithAssignerAndReaderRoleCheckWhatToHide_Success Mpa.IM.CaseManagement.Tests CollectionAssert.AreEqual failed. (Element at index 7 do not match.)

salgo60
and how exactly is this related to the question?
borisCallens
I send in two list<string> (IList) that are compared in CollectionAssert is that your problem...
salgo60