Ejemplo n.º 1
0
        public void WhenGlobalServiceSpecified_ThenExtensionMethodUsesIt()
        {
            var service = Mock.Of <IAdapterService>(x => x.Adapt(It.IsAny <IFoo>()) == Mock.Of <IAdaptable <IFoo> >());

            AdaptersInitializer.SetService(service);

            var adaptable = Mock.Of <IFoo>().Adapt();

            Assert.NotNull(adaptable);

            adaptable.As <IBar>();

            Mock.Get(service).Verify(x => x.Adapt(It.IsAny <IFoo>()));
            Mock.Get(adaptable).Verify(x => x.As <IBar>());
        }
Ejemplo n.º 2
0
        public void WhenTransientServiceSpecified_ThenOverridesGlobalService()
        {
            var transient = Mock.Of <IAdapterService>(x => x.Adapt(It.IsAny <IFoo>()) == Mock.Of <IAdaptable <IFoo> >());

            using (AdaptersInitializer.SetTransientService(transient))
            {
                var adaptable = Mock.Of <IFoo>().Adapt();

                Assert.NotNull(adaptable);

                adaptable.As <IBar>();

                Mock.Get(transient).Verify(x => x.Adapt(It.IsAny <IFoo>()));
                Mock.Get(adaptable).Verify(x => x.As <IBar>());
            }
        }