First...if you're presenting you want to look long and hard at AAA.
Record/Replay (IMO) is harder for newbies to learn.

Secondly I would say you want to verify the contact name of the object
passed is what you want to verify since the class under test is doing
some parsing work.

I can comment more if you can tell me where you think you're going wrong

Tim

On 5/22/09, Jamie Phillips <[email protected]> wrote:
>
> I'm preparing a presentation on Rhino Mocks, Dependency Injection and
> MSTest and I got a bit unstuck in my demo code where I want to
> validate the arguments being passed to the method on my mock object. I
> cannot figure out the best way to achieve this. The code under test
> does the following:
>
>         /// <summary>
>         /// Inserts a new customer instance in to the database
>         /// </summary>
>         /// <param name="i_customer">The Customer instance to insert.</
> param>
>         public void Insert(Customer i_customer)
>         {
>             if (i_customer == null)
>
>                 throw new ArgumentNullException();
>
>             if (!string.IsNullOrEmpty(i_customer.ContactName) &&
> i_customer.ContactName.Contains(" "))
>             {
>                 string[] names = i_customer.ContactName.Split(' ');
>                 if (names.Length > 1)
>                 {
>                     names[names.Length - 1] = names[names.Length -
> 1].ToUpper();
>                 }
>                 i_customer.ContactName = string.Join(" ", names);
>             }
>             m_customerRepository.Insert(i_customer);
>         }
>
>
> And what I want to do in my Test Method is verify that the customer
> instance that is passed in to the .Insert method of the
> customerRepository (shown in the code snippet above):
>
>         [TestMethod]
>         public void TestInsertValidCustomerWithSurname()
>         {
>             // Create the mock instance
>             ICustomerRepository customerRepository =
> m_mockRepository.DynamicMock<ICustomerRepository>();
>
>             Customer newEntry = new Customer()
>                                     {
>                                         Address = "123 High Road",
>                                         City = "SomeCity",
>                                         CompanyName = "Acompany",
>                                         ContactName = "James Person",
>                                         ContactTitle = "Manager",
>                                         Country = "United States",
>                                         CustomerID = "987654321",
>                                         Fax = "123-456-7891",
>                                         Phone = "123-456-7892",
>                                         PostalCode = "01234",
>                                         Region = "NorthEast"
>                                     };
>
>             // Now we set our expectations - when a null is passed the
> underlying method should throw an exception
>             Expect.Call(() => customerRepository.Insert(newEntry));
>
>             // Replay our expectations
>             m_mockRepository.ReplayAll();
>
>             // Create a real instance of the EmloyeeConnector that we
> want to put under test
>             CustomerManager manager = new CustomerManager
> (customerRepository);
>
>             manager.Insert(newEntry);
>         }
>
>
>
> But I can’t figure out what is the best way to fir the validation of
> the newEntry.ContactName property in the Expect.Call(() =>
> customerRepository.Insert(newEntry))? Does anyone have a suggestion?
>
> >
>

-- 
Sent from my mobile device

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