コード例 #1
0
        public void CanMapInterfacesToConcreteTypes()
        {
            MockBuilderContext  ctx      = new MockBuilderContext();
            TypeMappingStrategy strategy = new TypeMappingStrategy();

            ctx.Policies.Set <ITypeMappingPolicy>(new TypeMappingPolicy(typeof(SalesFoo), null), typeof(IFoo), "sales");
            ctx.Policies.Set <ITypeMappingPolicy>(new TypeMappingPolicy(typeof(Foo), null), typeof(IFoo), "marketing");
            ctx.InnerChain.Add(strategy);

            MockStrategy mock = new MockStrategy();

            ctx.InnerChain.Add(mock);

            strategy.BuildUp <IFoo>(ctx, null, "sales");

            Assert.IsTrue(mock.WasRun);
            Assert.AreEqual(typeof(SalesFoo), mock.IncomingType);

            mock.WasRun       = false;
            mock.IncomingType = null;

            strategy.BuildUp <IFoo>(ctx, null, "marketing");

            Assert.IsTrue(mock.WasRun);
            Assert.AreEqual(typeof(Foo), mock.IncomingType);
        }
コード例 #2
0
        public void IncompatibleTypes()
        {
            MockBuilderContext  ctx      = new MockBuilderContext();
            TypeMappingStrategy strategy = new TypeMappingStrategy();

            ctx.Policies.Set <ITypeMappingPolicy>(new TypeMappingPolicy(typeof(object), null), typeof(IFoo), "sales");
            ctx.InnerChain.Add(strategy);

            strategy.BuildUp <IFoo>(ctx, null, "sales");
        }