public void ThenWrapWithType_passes_params_to_resolver(IResolver resolver, ServiceImpl2 impl, Parameter[] parameters, ServiceImpl1 initialImpl) { var sut = new AutofacDecoratorCustomizer(resolver, typeof(IServiceInterface), initialImpl); Mock.Get(resolver) .Setup(x => x.Resolve(typeof(ServiceImpl2), It.Is <IEnumerable <Parameter> >(p => parameters.All(y => p.Contains(y))))) .Returns(impl); var result = sut.ThenWrapWithType(typeof(ServiceImpl2), parameters); Assert.That(result?.Implementation, Is.SameAs(impl)); }
public void ThenWrapWith_resolves_impl_from_resolver(IResolver resolver, ServiceImpl2 impl, ServiceImpl1 initialImpl) { var wrapped = new AutofacDecoratorCustomizer(resolver, typeof(IServiceInterface), initialImpl); var sut = new AutofacGenericDecoratorCustomizer <IServiceInterface>(wrapped, initialImpl); Mock.Get(resolver) .Setup(x => x.Resolve <ServiceImpl2>(It.IsAny <IEnumerable <Parameter> >())) .Returns(impl); var result = (AutofacGenericDecoratorCustomizer <IServiceInterface>)sut.ThenWrapWith <ServiceImpl2>(); Assert.That(result?.Implementation, Is.SameAs(impl)); }
public void ScopesTest() { DependenciesConfiguration configuration = new DependenciesConfiguration(); configuration.Register(typeof(IRepository), typeof(MyRepository)); configuration.Register(typeof(IService <>), typeof(ServiceImpl1 <>), Lifetime.Singleton, "1"); configuration.Register(typeof(IService <>), typeof(ServiceImpl2 <>), Lifetime.Prototype, "2"); DependencyContainer container = new DependencyContainer(configuration); IService <IRepository> serviceImpl1 = container.Resolve <IService <IRepository> >("1"); ServiceImpl2 <IRepository> serviceImpl2 = (ServiceImpl2 <IRepository>)container.Resolve <IService <IRepository> >("2"); ServiceImpl1 <IRepository> serviceImpl11 = (ServiceImpl1 <IRepository>)container.Resolve <IService <IRepository> >("1"); ServiceImpl2 <IRepository> serviceImpl22 = (ServiceImpl2 <IRepository>)container.Resolve <IService <IRepository> >("2"); Assert.AreSame(serviceImpl1, serviceImpl11); Assert.That(serviceImpl2 != serviceImpl22); }
public void ThenWrapWith_passes_impl_to_resolver_as_parameter(IResolver resolver, ServiceImpl2 impl, Parameter[] parameters, ServiceImpl1 initialImpl) { var wrapped = new AutofacDecoratorCustomizer(resolver, typeof(IServiceInterface), initialImpl); var sut = new AutofacGenericDecoratorCustomizer <IServiceInterface>(wrapped, initialImpl); Mock.Get(resolver) .Setup(x => x.Resolve <ServiceImpl2>(It.Is <IEnumerable <Parameter> >(p => p.OfType <TypedParameter>().Any(a => a.Type == typeof(IServiceInterface) && a.Value == initialImpl)))) .Returns(impl); var result = (AutofacGenericDecoratorCustomizer <IServiceInterface>)sut.ThenWrapWith <ServiceImpl2>(parameters); Assert.That(result?.Implementation, Is.SameAs(impl)); }