Is this a compile-time or run-time error?

Also, try using a stub (via GenerateStub) instead of a StrictMock.
Strict mocks make your unit tests more brittle in the long run.

---
Patrick Steele
http://weblogs.asp.net/psteele



On Wed, Mar 16, 2011 at 1:05 PM, Giulio Petrucci
<[email protected]> wrote:
> Hi there
>
> here is my code:
>
> using NHibernate.Linq;
>
> public class DummyEntity { }
> public interface ISessionProvider
> {
>    NHibernate.ISession GetSession();
> }
> //...
>
> var mockRepo = new MockRepository();
> ISession session = mockRepo.StrictMock<ISession>();
> ISessionProvider sessionProvider = mockRepo.StrictMock<ISessionProvider>();
> //...
> IQueryable<DummyEntity> q = new List<DummyEntity>().AsQueryable();
> sessionProvider.Expect(sp => sp.GetSession()).Repeat.Once().Return(session);
> session.Expect(s => s.Query<DummyEntity>()).Repeat.Once().Return(q);
>
> //code to be tested:
> sessionProvider.GetSession().Query<DummyEntity>()
>
> I got this error:
> ***
> System.InvalidOperationException : Type
> 'System.Linq.EnumerableQuery`1[[DummyEntity, MyTest, Version=1.0.0.0,
> Culture=neutral, PublicKeyToken=null]]' doesn't match the return type
> 'NHibernate.ISession' for method 'ISessionProvider.GetSession();'
> ***
>
> BUT if I change my mocking code in:
> sessionProvider.Expect(sp => sp.GetSession()).Repeat.Once().Return(session);
> session.Expect(s => s.Query<DummyEntity>()).Repeat.Once().Return(null);
>
> everything works fine.
> What am I missing?
> Can anyone help me?
>
> Thanks in advance,
> Giulio
>
> --
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Rhino.Mocks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rhinomocks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to