Why create a StrictMock of List<T>?  For one thing, the Contains
method isn't virtual so you can't set expectations on it (nor stub
it's behavior).  Second, I tend to avoid StrictMock's.  They introduce
too much of the implementations details in your tests and less of the
behavior.  The same can be said for ordered tests too, but they do
have their use in some cases.

What's the goal of what you're trying to test?  What class is being
tested in this scenario?

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



On Wed, May 4, 2011 at 7:53 AM, Giulio Petrucci
<[email protected]> wrote:
> Hi Patrick,
>
> On Thu, Apr 28, 2011 at 8:20 PM, Patrick Steele
> <[email protected]> wrote:
>> What is MyMock1?  What's the signature of MyMethod<T>?
>
> In the meantime I did some other tests and a lot of things changed.
> :-) Here is my "current" situation.
>
> //wrapper for an EF ObjectContext or an NH ISession
> public interface IDataContext : IDisposable
>    {
>        bool HasPendingChanges { get; }
>
>        void Add(object entity);
>        ITransaction BeginTransaction();
>        ITransaction BeginTransaction(System.Data.IsolationLevel isolation);
>        void Close();
>        bool Contains(object entity);
>        void Delete(object entity);
>        void Evict(object entity);
>        void FlushChanges();
>        T GetByKey<T>(object key);
>        IQueryable<T> Query<T>();
>        void Refresh(object entity);
>        void Update(object entity);
>    }
>
> MockRepository repo = ...;
> Foo foo = ...;
> object id = ...;
> var list = repo.StrictMock<List<Foo>>();
> var dc = repo.StrictMock<IDataContext>();
> //...;
>
> using (repo.Ordered())
> {
>    dc.Expect(item => item.GetByKey<Foo>(id)).Repeat.Once().Return(foo);
>    list.Expect(l => l.Contains(foo)).Repeat.Once().Return(true); //error
> }
>
> The detailed error is:
>
> Type 'System.Boolean' doesn't match the return type 'Foo' for method
> 'IDataContext.GetByKey<Foo>(missing parameter);'
>
> Thanks,
> 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