public void SetDefaultFactory()
        {
            MockRepository mocks         = new MockRepository();
            IResultFactory resultFactory = (IResultFactory)mocks.CreateMock(typeof(IResultFactory));

            IResultFactory prevFactory = ResultFactoryRegistry.DefaultResultFactory;

            Assert.AreSame(prevFactory, ResultFactoryRegistry.SetDefaultFactory(resultFactory));
            Assert.AreSame(resultFactory, ResultFactoryRegistry.DefaultResultFactory);

            // verify default factory is used for unknown result mode
            using (Record(mocks))
            {
                Expect.Call(resultFactory.CreateResult(null, "resultText")).Return(new Result());
                Expect.Call(resultFactory.CreateResult("resultMode", "resultText")).Return(new Result());
            }

            using (Playback(mocks))
            {
                ResultFactoryRegistry.CreateResult("resultText");
                ResultFactoryRegistry.CreateResult("resultMode:resultText");
            }
        }
        public void BailsOnNullReturnedFromFactory()
        {
            MockRepository mocks         = new MockRepository();
            IResultFactory resultFactory = (IResultFactory)mocks.CreateMock(typeof(IResultFactory));

            ResultFactoryRegistry.RegisterResultMode("resultMode", resultFactory);

            // verify factory registry does not allow nulls to be returned
            using (Record(mocks))
            {
                Expect.Call(resultFactory.CreateResult("resultMode", "resultText")).Return(null);
            }

            using (Playback(mocks))
            {
                ResultFactoryRegistry.CreateResult("resultMode:resultText");
            }
        }
        public void SelectsFactoryByResultMode()
        {
            MockRepository mocks         = new MockRepository();
            IResultFactory resultFactory = (IResultFactory)mocks.CreateMock(typeof(IResultFactory));

            ResultFactoryRegistry.RegisterResultMode("resultMode", resultFactory);

            Result result = new Result();

            // verify factory registry does not allow nulls to be returned
            using (Record(mocks))
            {
                Expect.Call(resultFactory.CreateResult("resultMode", "resultText")).Return(result);
            }

            using (Playback(mocks))
            {
                Assert.AreSame(result, ResultFactoryRegistry.CreateResult("resultMode:resultText"));
            }
        }