Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



RhinoMocks new Arrange, Act, Assert does not seem to work under MSTest....odd

-- UPDATE See text in red below --

Ok, I am in NO way trying to say that this is either Rhino's issue or MSTest.  I am simply blogging this with the intent that someone can shed some insight as to what may be going on.  Although, since I know that the AAA logic of Rhino works with the EXACT same code under NUnit i have to believe it has something to do with the MSTest works.

So here is my propblem:

I have a test where i want to mock out and set an expectation on a repository.  When I tried the code via the AAA syntax my expectation would only return a null.  When I changed to use Record/Playback everything worked well.  Odd.

Here is the syntax for AAA (non-working)

var mockRepository = new MockRepository();
var mockStatusCheckRepository = mockRepository.DynamicMock();

mockStatusCheckRepository.Expect( x => x.GetCustomerAuditInformation( "", "" ) ).IgnoreArguments().Return( new CustomerAuditInformation { NeedsInitialDataCreated = true } ).Repeat.Once();
var information = mockStatusCheckRepository.GetCustomerAuditInformation( "", "" );
// Returns null

I was able to get this working by NOT using the instance of MockRepoistory, instead using the Static Methods.  Belows Code works

var mockStatusCheckRepository = MockRepository.GenerateMock();

mockStatusCheckRepository.Expect( x => x.GetCustomerAuditInformation( "", "" ) ).IgnoreArguments().Return( new CustomerAuditInformation { NeedsInitialDataCreated = true } ).Repeat.Once();

var information = mockStatusCheckRepository.GetCustomerAuditInformation( "", "" )

So, this may just be a case of me not fully understanding the new AAA syntax and how to use it, but I know that using the instance stuff works under NUnit... odd


Here is the syntax for the Record/Playback (working) - Can use the AAA syntax above as well

var mockRepository = new MockRepository();
var mockStatusCheckRepository = mockRepository.DynamicMock();

using ( mockRepository.Record() )
{
    mockStatusCheckRepository.Expect( x => x.GetCustomerAuditInformation( "", "" ) ).IgnoreArguments().Return( new CustomerAuditInformation { NeedsInitialDataCreated = true } ).Repeat.Once();

}

using ( mockRepository.Playback() )
{
    var information = mockStatusCheckRepository.GetCustomerAuditInformation( "", "" );
}

Cany anyone shed some light on this?  Is there a way around this?

Till next time,

[----- Remember to check out DimeCasts.Net -----]



Comments

Darrell Mozingo said:

I think any use of the mock repository object (for Strick mocks, ordered mocking, a single verify for multiple mocks, etc) requires the Record/Playback model to be used. That's been my experiences so far, anyway.

For normal Dynamic Mocks or Stubs, though, you can just use the static methods on the MockRepository and the new AAA syntax.

# July 23, 2008 3:30 PM

Dew Drop - July 24, 2008 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - July 24, 2008 | Alvin Ashcraft's Morning Dew

# July 24, 2008 1:28 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Red-Gate!

This Blog

Syndication

News