Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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 -----]


Posted 07-23-2008 10:38 AM by Derik Whittaker
Filed under: , ,

[Advertisement]

Comments

Darrell Mozingo wrote re: RhinoMocks new Arrange, Act, Assert does not seem to work under MSTest....odd
on 07-23-2008 3:30 PM

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.

Dew Drop - July 24, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - July 24, 2008 | Alvin Ashcraft's Morning Dew
on 07-24-2008 1:28 PM

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

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)