public void BailsOnNullReturnedFromFactory()
        {
            IResultFactory resultFactory = A.Fake <IResultFactory>();

            ResultFactoryRegistry.RegisterResultMode("resultMode", resultFactory);

            // verify factory registry does not allow nulls to be returned
            A.CallTo(() => resultFactory.CreateResult("resultMode", "resultText")).Returns(null);
            Assert.Throws <ArgumentNullException>(() => ResultFactoryRegistry.CreateResult("resultMode:resultText"));
        }
        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 SelectsFactoryByResultMode()
        {
            IResultFactory resultFactory = A.Fake <IResultFactory>();

            ResultFactoryRegistry.RegisterResultMode("resultMode", resultFactory);

            Result result = new Result();

            // verify factory registry does not allow nulls to be returned
            A.CallTo(() => resultFactory.CreateResult("resultMode", "resultText")).Returns(result);
            Assert.AreSame(result, 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 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");
            }
        }
        /// <summary>
        /// Obtain the named result instance from the <see cref="Results"/> dictionary. If necessary, the actual representation of the result
        /// will be converted to an <see cref="IResult"/> instance by this method.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        protected IResult GetResult(string name)
        {
            object val = _results[name];

            if (val == null)
            {
                return(null);
            }
            else if (val is IResult)
            {
                return((IResult)val);
            }
            else if (val is String)
            {
                return(ResultFactoryRegistry.CreateResult((string)val));
            }

            return(HandleUnknownResultType(name, val));
        }
        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"));
            }
        }
        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"));
                }
            }
        }
Example #9
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" );
            }
        }