This question is locked. New answers and comments are not allowed.
I've just started using the Moq framework to speed up my unit tests and reduce their dependence on the database. For example, I can use a mock IObjectScope to easily verify the a Repository method calls the IObjectScope.Add() method as follows:
But when I mock IObjectScope.Extent<T>(), I want to setup the method to return a collection of objects that I've created, as follows:
I don't know how to create a collection of objects to match the return type of ExtentQuery<T>. The class has no constructor, and I haven't been able to cast an IEnumerable<T> collection to that type.
So any help would be appreciated.
Thanks,
Denis
| // Create mock IObjectScope |
| Mock<IObjectScope> _mockScope = new Mock<IObjectScope>(); |
| // Call the repository method... |
| // Verify that IObjectScope.Add() was called |
| _mockScope.Verify( mS => mS.Add( myObject ) ); |
But when I mock IObjectScope.Extent<T>(), I want to setup the method to return a collection of objects that I've created, as follows:
| _mockScope.Setup( mS => mS.Extent<MyClass>() ).Returns( /* Collection of objects */ ); |
I don't know how to create a collection of objects to match the return type of ExtentQuery<T>. The class has no constructor, and I haven't been able to cast an IEnumerable<T> collection to that type.
So any help would be appreciated.
Thanks,
Denis