Пример #1
0
        public void ThenWrapWithType_throws_exception_if_impl_type_does_not_derive_from_service(IResolver resolver,
                                                                                                ServiceImpl1 initialImpl)
        {
            var wrapped = new AutofacDecoratorCustomizer(resolver, typeof(IServiceInterface), initialImpl);
            var sut     = new AutofacGenericDecoratorCustomizer <IServiceInterface>(wrapped, initialImpl);

            Assert.That(() => sut.ThenWrapWithType(typeof(DifferentImpl)), Throws.ArgumentException);
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        public void ThenWrapWithType_passes_params_to_resolver(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(typeof(ServiceImpl2), It.Is <IEnumerable <Parameter> >(p => parameters.All(y => p.Contains(y)))))
            .Returns(impl);

            var result = (AutofacGenericDecoratorCustomizer <IServiceInterface>)sut.ThenWrapWithType(typeof(ServiceImpl2), parameters);

            Assert.That(result?.Implementation, Is.SameAs(impl));
        }