And please do so

On Wed, Dec 17, 2008 at 5:37 PM, David Tchepak <tche...@gmail.com> wrote:

> Hi Alex,
> The Rhino Mocks website is a wiki, so you can pretty much add anything you
> like to it :-)
> http://ayende.com/wiki/Rhino+Mocks+Documentation.ashx
>
> Regards,
> David
>
>
>
> On Wed, Dec 17, 2008 at 9:34 PM, Alex Scordellis <
> alex.scordel...@gmail.com> wrote:
>
>>
>> I think David is technically right, in that Find<Team> and
>> Find<TeamOrClub> are different methods in the CLR, so when I stub one,
>> the other returns null. So there is not a bug in the RM
>> implementation.
>>
>> However there is a problem for the users of Rhino Mocks. The behaviour
>> is not intuitive.
>>
>> Ayende, if I write a paragraph explaining the problem and the
>> solution, will you add it to the docs on the Rhino.Mocks website? If
>> not, I can blog it, but I think it will be easier for others to find
>> if it's on the main RM site.
>>
>> David's solution works, but can't be applied to my real code. In my
>> real code, the call to findManager.For(findTeam.For(player)) is in the
>> code I'm testing, not in my unit test, and at that point I don't know
>> whether I have a Team or a Club, so I can't make his suggested change
>> findManager.For((Team)findTeam.For(player)).
>>
>> A better fix is:
>>    findManager.Stub(t => t.For<TeamOrClub>(team)).Return(manager);
>>
>> Now this test fails:
>>
>>    Assert.That(findManager.For(team), Is.SameAs(manager));
>>
>> because it calls ManagerFinder.For<Team>(Team t), but these pass:
>>
>>    Assert.That(findManager.For(findTeam.For(player)), Is.SameAs(manager));
>>     Assert.That(findManager.For((TeamOrClub)team), Is.SameAs(manager));
>>
>> because they call ManagerFinder.For<TeamOrClub>(TeamOrClub t).
>>
>>
>> Alex
>>
>>
>> 2008/12/17 Ayende Rahien <aye...@ayende.com>:
>> > So, is there a problem?
>> >
>> > On Tue, Dec 16, 2008 at 8:20 PM, David Tchepak <tche...@gmail.com>
>> wrote:
>> >>
>> >> Oh ok. I think it is a co/contravariance (I always get them mixed up
>> :$)
>> >> problem with the generic method.
>> >>
>> >> It works if you change the last assert to this:
>> >>
>> >>             Assert.That(findManager.For((Team) findTeam.For(player)),
>> >> Is.SameAs(manager));
>> >>
>> >> Although I did need to explicitly add the repeats:
>> >>
>> >>             findTeam.Stub(t =>
>> t.For(player)).Return(team).Repeat.Any();
>> >>             findManager.Stub(t =>
>> >> t.For(team)).Return(manager).Repeat.Any();
>> >>
>> >> I think the problem is that the last assert ends up calling
>> >> ManagerFinder.For<TeamOrClub>(...), which is a different method that
>> >> ManagerFinder.For<Team>(...), so you don't get the stubbed value. It
>> also
>> >> works if you change the ManagerFinder.For to be non-generic and take a
>> >> TeamOrClub parameter.
>> >>
>> >> Hope this helps.
>> >> Regards,
>> >> David
>> >>
>> >>
>> >> On Wed, Dec 17, 2008 at 1:24 AM, Alex Scordellis
>> >> <alex.scordel...@gmail.com> wrote:
>> >>>
>> >>> I have experienced this problems with the following versions
>> >>>
>> >>> * Official release v3.5 for net-3.5 (no castle assemblies)
>> >>> * Home build (using script below) of revision 1686 (castle revision
>> 5380)
>> >>> * Home build (using script below) of revision 1770 (castle revision
>> 5443)
>> >>>
>> >>> cd CastleProject
>> >>> svn up
>> >>> nant quick release rebuild
>> >>> cd ..\RhinoTools
>> >>> svn up
>> >>> copy ..\CastleProject\build\net-3.5\release\*.*
>> .\SharedLibs\Castle\*.*
>> >>> /y
>> >>> nant -D:project.config=release -D:common.testrunner.enabled=false
>> >>> cd ..
>> >>>
>> >>> 2008/12/16 Alex Scordellis <alex.scordel...@gmail.com>:
>> >>> > I don't think that's the problem. If I understand correctly, a
>> stubbed
>> >>> > method will return the value any number of times. Indeed I can add
>> as
>> >>> > many duplicates as I want of the asserts which pass:
>> >>> >
>> >>> >            // These all pass
>> >>> >            Assert.That(findTeam.For(player), Is.SameAs(team));
>> >>> >            Assert.That(findTeam.For(player), Is.SameAs(team));
>> >>> >            Assert.That(findTeam.For(player), Is.SameAs(team));
>> >>> >            Assert.That(findTeam.For(player), Is.SameAs(team));
>> >>> >            Assert.That(findManager.For(team), Is.SameAs(manager));
>> >>> >            Assert.That(findManager.For(team), Is.SameAs(manager));
>> >>> >            Assert.That(findManager.For(team), Is.SameAs(manager));
>> >>> >            Assert.That(findManager.For(team), Is.SameAs(manager));
>> >>> >            Assert.That(findManager.For(team), Is.SameAs(manager));
>> >>> >
>> >>> > Also that would not explain why the issue only occurs when I use
>> >>> > generics.
>> >>> >
>> >>> > Alex
>> >>> >
>> >>> >
>> >>> > 2008/12/16 David Tchepak <tche...@gmail.com>:
>> >>> >> Try:
>> >>> >>
>> >>> >>        findTeam.Stub(t => t.For(player)).Return(team).Repeat.Any();
>> >>> >>
>> >>> >> Otherwise your first assert will use up the single, stubbed return
>> >>> >> value,
>> >>> >> and the final assert will revert to returning null (for reference
>> >>> >> return
>> >>> >> types).
>> >>> >>
>> >>> >> Regards,
>> >>> >> David
>> >>> >>
>> >>> >> On Mon, Dec 15, 2008 at 11:40 PM, Alex Scordellis
>> >>> >> <alex.scordel...@gmail.com> wrote:
>> >>> >>>
>> >>> >>> The test in the code sample below fails when I don't expect it to.
>> A
>> >>> >>> mock is returning null when it looks like it really should be
>> >>> >>> returning the stubbed value.
>> >>> >>>
>> >>> >>>
>> >>> >>>
>> >>> >>> If I change the definition of ManagerFinder to
>> >>> >>>
>> >>> >>>    public interface ManagerFinder
>> >>> >>>    {
>> >>> >>>        Manager For(TeamOrClub grouping);
>> >>> >>>    }
>> >>> >>>
>> >>> >>> then it passes, so it seems to be a problem matching the call to
>> the
>> >>> >>> generic method.
>> >>> >>>
>> >>> >>> Have I missed something?
>> >>> >>>
>> >>> >>> Alex
>> >>> >>>
>> >>> >>>
>> >>> >>>
>> >>> >>>
>> >>> >>> using NUnit.Framework;
>> >>> >>> using NUnit.Framework.SyntaxHelpers;
>> >>> >>> using Rhino.Mocks;
>> >>> >>>
>> >>> >>> namespace RhinoMocksIssue
>> >>> >>> {
>> >>> >>>    [TestFixture]
>> >>> >>>    public class GenericMethodTest
>> >>> >>>    {
>> >>> >>>        [Test]
>> >>> >>>        public void
>> should_return_stubbed_value_from_generic_method()
>> >>> >>>        {
>> >>> >>>            var player = new Player();
>> >>> >>>            var team = new Team();
>> >>> >>>            var manager = new Manager();
>> >>> >>>
>> >>> >>>            var findTeam =
>> MockRepository.GenerateMock<TeamFinder>();
>> >>> >>>            var findManager =
>> >>> >>> MockRepository.GenerateMock<ManagerFinder>();
>> >>> >>>
>> >>> >>>            findTeam.Stub(t => t.For(player)).Return(team);
>> >>> >>>            findManager.Stub(t => t.For(team)).Return(manager);
>> >>> >>>
>> >>> >>>            // These both pass
>> >>> >>>            Assert.That(findTeam.For(player), Is.SameAs(team));
>> >>> >>>            Assert.That(findManager.For(team), Is.SameAs(manager));
>> >>> >>>
>> >>> >>>            // This fails. The LHS is null.
>> >>> >>>            Assert.That(findManager.For(findTeam.For(player)),
>> >>> >>> Is.SameAs(manager));
>> >>> >>>        }
>> >>> >>>    }
>> >>> >>>
>> >>> >>>    public interface TeamFinder
>> >>> >>>    {
>> >>> >>>        TeamOrClub For(Player player);
>> >>> >>>    }
>> >>> >>>
>> >>> >>>    public interface ManagerFinder
>> >>> >>>    {
>> >>> >>>        Manager For<ENTITY>(ENTITY entity) where ENTITY :
>> TeamOrClub;
>> >>> >>>    }
>> >>> >>>
>> >>> >>>    public interface TeamOrClub
>> >>> >>>    {
>> >>> >>>    }
>> >>> >>>
>> >>> >>>    public class Player
>> >>> >>>    {
>> >>> >>>    }
>> >>> >>>
>> >>> >>>    public class Team : TeamOrClub
>> >>> >>>    {
>> >>> >>>    }
>> >>> >>>
>> >>> >>>    public class Club : TeamOrClub
>> >>> >>>    {
>> >>> >>>    }
>> >>> >>>
>> >>> >>>    public class Manager
>> >>> >>>    {
>> >>> >>>    }
>> >>> >>> }
>> >>> >>>
>> >>> >>>
>> >>> >>
>> >>> >>
>> >>> >> >>
>> >>> >>
>> >>> >
>> >>>
>> >>>
>> >>
>> >>
>> >>
>> >
>> >
>> > >
>> >
>>
>>
>>
>
> >
>

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

Reply via email to