c# - Moq - cannot iterate through a hidden IEnumerable -
we have reasonably complicated interface hierarchy , i'm struggling moq want to.
i have interface ireservation
extends irulesreservation
, , hides enumerator new implementation of type.
public interface ireservation : irulesreservation { new ienumerator<iroutepart> getenumerator(); }
irulesreservation
extends ienumerable
.
public interface irulesreservation : ienumerable<irulesroutepart> { }
the method i'm trying test takes in ireservation
, @ various points needs access ienumerable<irulesroutepart>
. mock setup so:
m_mock = new mock<ireservation>(); m_mock.as<irulesreservation>().setup(r => r.getenumerator()).returns(routeparts.select(rp => (irulesroutepart)rp).getenumerator());
in example, routeparts
list of irouteparts
come mock<irouteparts>
objects setup .as<irulesroutepart>()
.
whenever bit of code in function i'm testing uses enumerator, steps on iteration though collection empty.
am doing wrong in setup? or moq unable handle enumerator hidden in way?
edit: strange behaviour i've noticed when running test code on mock:
assert.that((reservation.object irulesreservation).count() == 8); assert.that((reservation.object ienumerable<irulesroutepart>).count() == 8);
the first line pass, second line fail. tried changing mock setup enumerator ienumerable<irulesroutepart>
, no effect:
m_mock.as<ienumerable<irulesroutepart>>().setup(r => r.getenumerator()).returns(routeparts.select(rp => (irulesroutepart)rp).getenumerator());
does object setup returns have data? that's problem.
Comments
Post a Comment