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>()); }
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>()); } }