I'm using rhino mock in my unit tests and I'm trying to create a mock using the following code:
var userDetails = MockRepository.GenerateMock<ReadOnlyCollection<UserDetails>>();
But when I run the unit test I get the following error:
Can not instantiate proxy of class:
System.Collections.ObjectModel.ReadOnlyCollection`
1[[SolutionName.FolderName,]].
Could not find a parameterless constructor.
I have searched on the net and found similar questions and solutions, one for moq using the SetupGet() method but I don't know what the equivalent of this is in rhino mocks. (The UserDetails class does have a parameterless constructor) How do I create a stub/mock for the ReadOnlyCollection?
You can pass any constructor arguments to GenerateMock
:
var inner = new List<UserDetails>();
var userDetails = MockRepository.GenerateMock<ReadOnlyCollection<UserDetails>>(inner);
You may want to consider creating an instance of ReadOnlyCollection
in your test and returning it from some other method call, which will be much simpler than mocking the appropriate methods.