Woah, Nellie.NET!

From my simple mind to… mine…

Rhino Mocks’ new Arrange, Act, Assert model…

leave a comment »

The difference between mocks and stubs in Rhino Mock’s new triple-A model is so subtle, that I can’t really distinguish between the two (except in ordering scenarios, apparently).

Oh well… 🙂

I love the syntax. In my test:

        public class When_creating_a_replication_context_based_on_information_in_the_session
            #region Setup/Teardown

            public void Setup_context()
                session = MockRepository.GenerateStub<HttpSessionStateBase>();
                session.Stub(x => x["replicatedSite"]).Return("bar");

                HttpRequestBase request = MockRepository.GenerateStub<HttpRequestBase>();
                request.Stub(x => x["replicatedSite"]).Return(null);

                HttpContextBase context = MockRepository.GenerateStub<HttpContextBase>();
                context.Stub(x => x.Session).Return(session);
                context.Stub(x => x.Request).Return(request);

                context.Stub(x => x.Session).Return(session);
                session.Stub(x => x.Add("replicatedSite", "bar"));

                replicationContextFactory = new HttpParamsReplicationContextFactory(context);
                replicationContext = replicationContextFactory.Create();


            private HttpParamsReplicationContextFactory replicationContextFactory;
            private ReplicationContext replicationContext;
            private HttpSessionStateBase session;

            public void Should_return_instance_of_subdomain_replication_context()
                Assert.That(replicationContext.GetType().ToString(), Is.EqualTo("LinearJunction.Replication.Domain.SimpleReplicationContext"));

            public void Should_return_replicated_site()
                Assert.That(replicationContext.ReplicatedSite, Is.EqualTo("bar"));

            public void Should_set_NEW_replicated_site_into_session()
                session.AssertWasCalled(x => x.Add("replicatedSite", "bar"));

Written by Nelson

October 8, 2008 at 2:46 am

Posted in .NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: