public void ResultModeValuesHavePredefinedFactories()
        {
            IResultFactory defaultFactory = A.Fake <IResultFactory>();

            ResultFactoryRegistry.SetDefaultFactory(defaultFactory);

            foreach (string resultMode in Enum.GetNames(typeof(ResultMode)))
            {
                Assert.IsNotNull(ResultFactoryRegistry.CreateResult(resultMode + ":resultText"));
            }
        }
        public void SetDefaultFactory()
        {
            IResultFactory resultFactory = A.Fake <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
            A.CallTo(() => resultFactory.CreateResult(null, "resultText")).Returns(new Result());
            A.CallTo(() => resultFactory.CreateResult("resultMode", "resultText")).Returns(new Result());

            ResultFactoryRegistry.CreateResult("resultText");
            ResultFactoryRegistry.CreateResult("resultMode:resultText");
        }
        public void ResultModeValuesHavePredefinedFactories()
        {
            MockRepository mocks          = new MockRepository();
            IResultFactory defaultFactory = (IResultFactory)mocks.CreateMock(typeof(IResultFactory));

            ResultFactoryRegistry.SetDefaultFactory(defaultFactory);

            // verify factory registry knows all ResultModes
            using (Record(mocks))
            {
                // defaultFactory must never be called!
            }

            using (Playback(mocks))
            {
                foreach (string resultMode in Enum.GetNames(typeof(ResultMode)))
                {
                    Assert.IsNotNull(ResultFactoryRegistry.CreateResult(resultMode + ":resultText"));
                }
            }
        }
Ejemplo n.º 4
0
        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" );
            }
        }