[TestFixture]
        public class
Given_An_Overloaded_Mockable_Operation_That_Accepts_A_Name_Value_Collection_Or_An_IList
{

                [Test]
                public void
When_I_Invoke_With_Name_Value_Collection_And_Assert_It_Was_Called_Using_GetArgumentsForCallsMadeOn_Then_Test_Passes
() {
                        NameValueCollection parameters = new 
NameValueCollection { { "1",
"xxx" } };
                        String expectedFirstItemValue = parameters[0];

                        Printer mockPrinter = 
MockRepository.GenerateMock<Printer>();

                        mockPrinter.Print(parameters);

                        NameValueCollection theSuppliedParams = 
(NameValueCollection)
                                mockPrinter.GetArgumentsForCallsMadeOn(
                                        printer =>
                                        printer.Print(
                                                
Arg<NameValueCollection>.List.ContainsAll(parameters)
                                        )
                                )[0][0];

                        Assert.AreEqual(expectedFirstItemValue, 
theSuppliedParams[0]);
                }

                [Test]
                public void
When_I_Invoke_With_Name_Value_Collection_And_Assert_It_Was_Called_Using_List_Element_Then_Test_Fails
() {
                        NameValueCollection parameters = new 
NameValueCollection { { "1",
"xxx" } };
                        String expectedFirstItemValue = parameters[0];

                        Printer mockPrinter = 
MockRepository.GenerateMock<Printer>();

                        mockPrinter.Print(parameters);

                        mockPrinter.AssertWasCalled(
                                printer =>
                                printer.Print(
                                        
Arg<NameValueCollection>.List.Element(0, Is.Equal
(expectedFirstItemValue))
                                )
                        );
                }

                [Test]
                public void
When_I_Invoke_With_IList_And_Assert_It_Was_Called_Using_List_Element_Then_Test_Passes
() {
                        IList parameters = new List<String> { "xxx" };
                        String expectedFirstItemValue = (String)parameters[0];

                        Printer mockPrinter = 
MockRepository.GenerateMock<Printer>();

                        mockPrinter.Print(parameters);

                        mockPrinter.AssertWasCalled(
                                printer =>
                                printer.Print(
                                        Arg<IList>.List.Element(0, 
Is.Equal(expectedFirstItemValue))
                                )
                        );
                }

                public abstract class Printer {
                        public abstract void Print(NameValueCollection 
parameters);
                        public abstract void Print(IList parameters);
                }
        }

On 5 Aug, 08:36, Iain Waddell <[email protected]> wrote:
> > What am I doing wrong? I am trying to assert a method is being invoked
> > with a NameValueCollection argument containing a specific element
> > value.
>
> I think a complete test case would help.
>
> Iain
--~--~---------~--~----~------------~-------~--~----~
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