Пример #1
0
        private IIndexStrategy CreateResolver(object source)
        {
            IIndexStrategy resolver = null;

            var numericIndex = 0;

            if (int.TryParse(_index, out numericIndex))
            {
                var dict = source as IDictionary;
                var list = source as IList;
                if (dict != null)
                {
                    resolver = new NumericDictStrategy(numericIndex);
                }
                else if (list != null)
                {
                    resolver = new ListStrategy(numericIndex);
                }
            }

            // Numeric failed, try text
            if (resolver == null)
            {
                if (source is IDictionary)
                {
                    resolver = new TextDictStrategy(_index);
                }
                else
                {
                    resolver = new NullStrategy();
                }
            }

            return(resolver);
        }
Пример #2
0
        public void CreationParameterCanCreateObjectsOfAGivenID()
        {
            MockBuilderContext ctx = new MockBuilderContext();
            NullStrategy strategy = new NullStrategy();
            ctx.InnerChain.Add(strategy);

            CreationParameter param = new CreationParameter(typeof (object), "foo");
            param.GetValue(ctx);

            Assert.AreEqual("foo", strategy.IDRequested);
        }
Пример #3
0
        public void CreationParameterUsesStrategyChainToCreateObjects()
        {
            MockBuilderContext ctx = new MockBuilderContext();
            NullStrategy strategy = new NullStrategy();
            ctx.InnerChain.Add(strategy);

            CreationParameter param = new CreationParameter(typeof (object));
            param.GetValue(ctx);

            Assert.IsTrue(strategy.WasCalled);
            Assert.AreEqual(typeof (object), strategy.TypeRequested);
        }
        public void CreationParameterCanCreateObjectsOfAGivenID()
        {
            MockBuilderContext ctx      = new MockBuilderContext();
            NullStrategy       strategy = new NullStrategy();

            ctx.InnerChain.Add(strategy);

            CreationParameter param = new CreationParameter(typeof(object), "foo");

            param.GetValue(ctx);

            Assert.AreEqual("foo", strategy.IDRequested);
        }
        public void CreationParameterUsesStrategyChainToCreateObjects()
        {
            MockBuilderContext ctx      = new MockBuilderContext();
            NullStrategy       strategy = new NullStrategy();

            ctx.InnerChain.Add(strategy);

            CreationParameter param = new CreationParameter(typeof(object));

            param.GetValue(ctx);

            Assert.IsTrue(strategy.WasCalled);
            Assert.AreEqual(typeof(object), strategy.TypeRequested);
        }