www.codinghillbilly.com   kyle.baley.org  Subscribe / Contact
 
 
 
 
LATEST POSTS
Thursday, December 20, 2007
using MbUnit.Framework;
using Rhino.Mocks;
namespace Suvius.Applications.LoveDoctor.Tests
{
    public class CritterFixationFixture
    {
        private ISpeciesSelectorPresenterView view;
        private MockRepository mocks;
        private SpeciesSelectorPresenter presenter;

        [ SetUp ]
        public void SetUp( )
        {
            mocks = new MockRepository( );
            view = mocks.DynamicMock<ISpeciesSelectorPresenterView>( );
            presenter = new SpeciesSelectorPresenter( view );
        }

        [ Test ]
        public void Should_initialize_view_with_list_of_projects( )
        {
            using ( mocks.Record( ) )
            {
                view.LoadCritters( );
            }
            using ( mocks.Playback( ) )
            {
                presenter.InitializeView( );
            }
        }
    }

    public class SpeciesSelectorPresenter
    {
        private readonly ISpeciesSelectorPresenterView _view;

        public SpeciesSelectorPresenter( ISpeciesSelectorPresenterView view )
        {
            _view = view;
        }

        public void InitializeView()
        {
        }
    }

    public interface ISpeciesSelectorPresenterView
    {
        void LoadCritters( );
    }
}

How's THAT for throwing you into the fray? I can see all of you now going, "whoa, there, Coding Hillbilly! I ain't e'en got me a cuppa joe yet, buddy." Sorry, folks, that's how I roll. I think slow and act fast. You gotta keep up.

The test above sets up an expectation that LoadCritters will be called on the View when we called Presenter.InitializeView. In actual fact, this isn't being done. So here's the poser: why does this test pass?

All right, I'll tell ya because I like your look. And I don't want to risk any of you actually cutting and pasting that into an IDE and coming up with some cut 'n paste error I made. Plus I gave you a hint in the post title.

The test isn't actually passing. When it hits view.LoadCritters, it fails silently and kicks out of the test completely. The reason bein' SetUp isn't being called. The reason for *that* bein' I forgot the [ TestFixture ] attribute on the class itself.

Now as to the question on why the test doesn't fail with a null reference exception: That's an easy answer. I have no idea. If you add the [ TestFixture ] attribute and comment out the code that creates the view, it does fail with the expected exception.

So I'll leave that to my loyal and, I pray, generous readers.

Kyle the Deferred

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Copyright © 2010 Kyle Baley. All rights reserved.
 
CATEGORIES
.NET General (18) alt.net (4) altnetconf (9) ASP.NET AJAX (40) ASP.NET MVC (29) Bahamas (1) Bahanet (9) BDD (1) Brownfield (18) Career (9) Castle (1) Code coverage (1) Coding Style (6) Communication (1) Community (18) Conscientious Coding (34) Continuous Integration (11) dasBlog (12) Development (16) DevTeach (4) Domain (2) Environment (4) Estimating (1) Featured (14) Flamingo (10) Games (1) Google App Engine (2) GWT (5) Hardware (6) Java (1) Javascript (7) Linq (2) Livelink (6) Lucene.NET (2) MbUnit (1) Metrics (1) Miscellaneous (24) Mocking (4) NAnt (4) NHibernate (12) NInject (1) Office (3) Office Development (6) Open Rasta (1) Patterns (5) Presenting (13) Professional Development (15) Refactoring (10) ReSharper (11) REST (2) S#arp Architecture (5) Security (3) Software (11) Sundry (18) TDD (19) Tools (21) User Interface (5) Utilities (8) Visual Studio (8) VSTO (1) Web development (12) Windows (3) Working Remotely (16) Workplace (3) Writing (4)
 
LATEST POSTS
 
POPULAR POSTS
 
 
ARCHIVE