Support primitive return types in setup

New method which allows specifying the return type to support the above

Updated Moq version to 4.2
That's a good idea. It did occur to me. Would constraining TReturn to
struct work?


On Mon, Jun 23, 2014 at 4:49 PM, Tim Kellogg <notifications@github.com>
wrote:

> In Moq.AutoMock/AutoMocker.cs:
>
> > @@ -171,6 +171,21 @@ public ISetup<TService> Setup<TService>(Expression<Action<TService>> setup)
> >              return Setup<ISetup<TService>, TService>(m => m.Setup(setup));
> >          }
> >
> > +        /// <summary>
> > +        /// Shortcut for mock.Setup(...), creating the mock when necessary.
> > +        /// For specific return types. E.g. primitive, structs
> > +        /// that cannot be infered
> > +        /// </summary>
> > +        /// <typeparam name="TService"></typeparam>
> > +        /// <typeparam name="TReturn"></typeparam>
> > +        /// <param name="setup"></param>
> > +        /// <returns></returns>
> > +        public ISetup<TService, TReturn> Setup<TService, TReturn>(Expression<Func<TService, TReturn>> setup)
> > +            where TService : class
> > +        {
> > +            return Setup<ISetup<TService, TReturn>, TService>(m => m.Setup(setup));
>
> Ian, if you're feeling ambitious - on line 162 walk the AST and if there's
> a cast to Object like you got, throw an exception that points them toward
> this overload. Maybe a NotSupportedException or whatever - something to
> point them in the right direction.
>
> --
> Reply to this email directly or view it on GitHub
> <https://github.com/tkellogg/Moq.AutoMocker/pull/9/files#r14082195>.
>



-- 

Ian Cox
C.T.O.

Release  Mobile

m:            Matrix Studios, 91 Peterborough Road, London, SW6 3BU
w:            http://www.releasemobile.com

Registered in England.  Number 06323661