Alex,

thanks for that, and the point is conceeded:

The code as posted represents the "Arrange" aspect of the AAA test,
and the remainder was not posted, because at the time of posting, it
seemed superfluous to the issue I am trying to resolve.

I also agree that there are quite a number of items being stubbed, but
this is due to the complexity of the framework (Prism V2).

This is class definition for the object under test:

    public class StatusBarModule
    {
        public StatusBarModule(IUnityContainer container)
        {
            Container = container;
            RegionManager = Container.Resolve<IRegionManager>();
            TheEventAggregator = Container.Resolve<IEventAggregator>
();
        }

        public IUnityContainer Container { get; private set; }
        public IRegionManager RegionManager { get; private set; }
        protected IEventAggregator TheEventAggregator { get; private
set; }

        public void
RegisterViewsAndServicesNotLoadedThroughConfiguration() { }

        public void RaiseAnyPertinentEventsEtc() { }

        public string ConfigurationContainerName { get { return
"Status"; } }

        public void Initialize()
        {
            var section = (UnityConfigurationSection)
ConfigurationManager.GetSection("Unity");
            if (section != null && section.Containers
[ConfigurationContainerName] != null)
                section.Containers
[ConfigurationContainerName].Configure(Container);

            RegisterViewsAndServicesNotLoadedThroughConfiguration();
            RegisterViewsWithRegions();
            RaiseAnyPertinentEventsEtc();
        }

        public void RegisterViewsWithRegions()
        {
            RegionManager.RegisterViewWithRegion
(RegionNames.StatusBarRegion, () =>
Container.Resolve<IStatusBarViewPresenter>().View);
        }

    }

And this is the full test:

        [Test]
        public void
WhenInstantiated_ShouldRegisterIStatusBarViewWithRegionManager()
        {
            var unity = MockRepository.GenerateStub<IUnityContainer>
();
            var presenter =
MockRepository.GenerateStub<IStatusBarViewPresenter>();
            var view = MockRepository.GenerateStub<IStatusBarView>();
            presenter.View = view;

            var eventAggregator =
MockRepository.GenerateStub<IEventAggregator>();
            var regionManager =
MockRepository.GenerateStub<IRegionManager>();
            var region = MockRepository.GenerateStub<IRegion>();
            var regionCollection =
MockRepository.GenerateMock<IRegionCollection>();
            regionCollection.Add(RegionNames.StatusBarRegion, region);

            regionManager.Stub(r => r.Regions).Return
(regionCollection);

            unity.Stub(container => container.Resolve<IEventAggregator>
()).Return(eventAggregator);
            unity.Stub(container => container.Resolve<IRegionManager>
()).Return(regionManager);
            unity.Stub(container =>
container.Resolve<IStatusBarViewPresenter>()).Return(presenter);

            new StatusBarModule(unity).Initialize(); //
RegionManager.Regions doesn't contain any regions!!

            unity.AssertWasCalled(container =>
container.Resolve<IEventAggregator>());
            unity.AssertWasCalled(container =>
container.Resolve<IRegionManager>());
            unity.AssertWasCalled(container =>
container.Resolve<IStatusBarViewPresenter>());
            regionManager.AssertWasCalled(manager =>
manager.RegisterViewWithRegion(RegionNames.StatusBarRegion, () =>
presenter.View));
        }

As you can see, the actual line fo code that I am testing is

            RegionManager.RegisterViewWithRegion
(RegionNames.StatusBarRegion, () =>
Container.Resolve<IStatusBarViewPresenter>().View);

Though now having described the whole scenario, I'm thinking that
really, what I am testing is whether or not the
"RegisterViewsWithRegions()" member is called; however without
stubbing the other required operands I cannot see how I would go about
defining that test.

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