You can't act on your SUT before you setup your expectations.
[TestFixture]
public class ATest
{
    private IActor actor;
    private List<int> list1, list2;
    private Manager manager;

    [SetUp]
    public void BeforeEachTest()
    {
        list1 = new List<int>();
        list2 = new List<int>();

        actor = MockRepository.GenerateMock<IActor>();
        manager = new Manager(actor);
    }

    [Test]
    public void should_perform_on_one()
    {
        actor.Expect(a => a.PerformAction(list1));

        manager.DoItOnActor(list1);
        manager.DoItOnActor(list2);

        actor.VerifyAllExpectations();
    }

    [Test]
    public void should_perform_on_two()
    {
        actor.Expect(a => a.PerformAction(list2));

        manager.DoItOnActor(list1);
        manager.DoItOnActor(list2);

        actor.VerifyAllExpectations();
    }
}


On Sun, May 31, 2009 at 11:55 PM, Xerxesb <[email protected]> wrote:

>
> Hi there,
>
> I've tried Googling this but turned up no results - was hoping I could
> get some guidance from the list. Basically i've got a class which has
> an expectation that AssertWasCalled on a method which takes in a List
> as a parameter. If i call it twice with two new'ed up lists, the
> framework fails the assertion citing "Expected #1, Actual #2".
>
> I've devised the following test-case to reproduce the situation:
> /************/
> using System.Collections.Generic;
> using NUnit.Framework;
> using Rhino.Mocks;
>
> namespace Test
> {
>    [TestFixture]
>    public class ATest
>    {
>        private IActor _mockActor;
>        private Manager _manager;
>        private List<int> _list1, _list2;
>
>        [SetUp]
>        public void SetUp()
>        {
>            _list1 = new List<int>();
> //            _list1.Add(0);
>            _list2 = new List<int>();
>
>            _mockActor = MockRepository.GenerateMock<IActor>();
>
>            _manager = new Manager(_mockActor);
>            _manager.DoItOnActor(_list1);
>            _manager.DoItOnActor(_list2);
>        }
>
>        [Test]
>        public void ShouldPerformActionOnList1()
>        {
>            _mockActor.AssertWasCalled(x => x.PerformAction(_list1));
>        }
>
>        [Test]
>        public void ShouldPerformActionOnList2()
>        {
>            _mockActor.AssertWasCalled(x => x.PerformAction(_list2));
>        }
>    }
>
>    public interface IActor
>    {
>        void PerformAction(List<int> list);
>    }
>
>    public class Manager
>    {
>        private readonly IActor _actor;
>
>        public Manager(IActor actor)
>        {
>            _actor = actor;
>        }
>
>        public void DoItOnActor(List<int> dataForActor)
>        {
>            _actor.PerformAction(dataForActor);
>        }
>    }
> }
>
> /***********/
>
> If I uncomment the second line in the set-up, Rhino seems to treat the
> lists differently and the expectations pass. However, because they are
> different lists (they just happen to both be empty in this scenario),
> I believe I should be able to call them like that and the scenario
> should pass. Any hints?
>
> Thanks,
> Xerx
>
> >
>


-- 

Groucho Marx <http://www.brainyquote.com/quotes/authors/g/groucho_marx.html>
- "I was married by a judge. I should have asked for a jury."

--~--~---------~--~----~------------~-------~--~----~
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