コード例 #1
0
        public void AddMapping_ThrowsAnException_WhenTheMappingRefersToAServiceYouDontSupport()
        {
            IServiceProvider provider =
                new FactoryServiceProvider<Object>();

            SetupComplete();
            provider.AddMapping(typeof (IA));
        }
コード例 #2
0
        public void GetService_CallsTheConstructorThatIsAttributed_WhenThereIsMoreThanOneConstructorAndOnlyOneIsAttributed()
        {
            IServiceProvider provider =
                new FactoryServiceProvider<TwoConstructorsAttributes>();

            IA ia = NewStub<IA>();
            IB ib = NewStub<IB>();

            SetupResult.For(context.HasService(typeof (IA))).Return(true);
            SetupResult.For(context.GetService(typeof (IA))).Return(ia);
            SetupResult.For(context.HasService(typeof (IB))).Return(true);
            SetupResult.For(context.GetService(typeof (IB))).Return(ib);
            SetupComplete();

            IC service = (IC) provider.GetService(typeof (IC), typeof (IC), context);

            Assert.AreEqual(ia, service.A);
            Assert.AreEqual(ib, service.B);
        }
コード例 #3
0
        public void GetService_ThrowsException_WhenThereAreMultipleConstructorsThatAreAttributed()
        {
            IServiceProvider provider =
                new FactoryServiceProvider<TwoConstructorsTwoAttributes>();

            SetupComplete();
            provider.GetService(typeof (IC), typeof (IC), context);
        }
コード例 #4
0
        public void GetService_ThrowsException_WhenThereAreMultipleConstructorsButNoneAreAttributed()
        {
            IServiceProvider provider =
                new FactoryServiceProvider<TwoConstructorsNoAttributes>();
            IA ia = NewStub<IA>();
            IB ib = NewStub<IB>();

            SetupResult.For(context.HasService(typeof (IA))).Return(true);
            SetupResult.For(context.GetService(typeof (IA))).Return(ia);
            SetupResult.For(context.HasService(typeof (IB))).Return(true);
            SetupResult.For(context.GetService(typeof (IB))).Return(ib);
            SetupComplete();
            provider.GetService(typeof (IC), typeof (IC), context);
        }