views:

304

answers:

2

I'm creating an EnityList to do some client side testing with my ViewModel. Something like:

   var people = new EntityList<Person>()
    {
        new Incident() {Age = 55, Name="Joe"},
        new Incident() {Age=42, Name="Sam"}
    };

The problem is that the implicit (and explicit) Adds fail. The entitylist is created as read-only. Any thoughts on how to create a test EntityList?

+2  A: 

I think you also need an EntityContainer to own your EntityList.

Colin Blair
Your blog is most helpful! Unfortunately, even with that help (and reflector), I wasn't able to create the EntityList<>. lol.
Erik Mork
+2  A: 

If you're doing testing then you probably don't want an EntityList. I would expect that a ViewModel shouldn't know about the EntityList, but rather should just get access to an IEnumberable instead. Both EntityList and List expose this, so in your tests you can just create a List.

I realize this doesn't help with the issue of EntityList being read-only. :)

Bryant
I think you're right. I was under the mistaken impression that the type exposed on the ViewModel had to implement INotifyCollectionChanged, but apparently the binding engine will try a cast from IEnumerable<> if that's what you have exposed. Er. I hope anyway.
Erik Mork