Exemplo n.º 1
0
        private void FindTypesByMethodReturnValueAndRegisterInterceptor <TReturned, TInterceptor>(IIocRegistrator reg,
                                                                                                  ITypeFinder typeFinder)
            where TInterceptor : IInterceptor
        {
            var methodInfos = GetMethodInfos <TReturned>(typeFinder);

            if (!methodInfos.Any())
            {
                throw new AutomationException(
                          "Failed to find test logic component. Please validate you have instance of an object with methods that retuns the type " +
                          typeof(TReturned));
            }

            ValidateThatAllMethodsAreVirtualOrImplementInterface(methodInfos);
            var declarTypes      = methodInfos.Select(bi => bi.DeclaringType).Distinct();
            var interceptorTypes = new[] { typeof(TInterceptor) };

            declarTypes.ForEachItem(dt =>
            {
                var firstLevelInterfaces = GetFirstLevelInterfaces(dt).ToArray();
                if (firstLevelInterfaces.Any())
                {
                    foreach (var fli in firstLevelInterfaces)
                    {
                        reg.RegisterType(dt, fli, LifeCycle.PerDependency, null, interceptorTypes);
                    }
                }
                else
                {
                    reg.RegisterType(dt, LifeCycle.PerDependency, interceptorTypes);
                }
            });
        }
Exemplo n.º 2
0
        private void RegisterPubSubComponents(IIocRegistrator reg, ITypeFinder typeFinder)
        {
            reg.RegisterType <EventPublisher, IEventPublisher>(LifeCycle.SingleInstance);
            reg.RegisterType <SubscriptionService, ISubscriptionService>(LifeCycle.SingleInstance);

            RegisterSubscribersByType(reg, typeFinder, typeof(IEventSubscriber <>));
            RegisterSubscribersByType(reg, typeFinder, typeof(IEventAsyncSubscriber <>));
        }
Exemplo n.º 3
0
        private void RegisterServices(IIocRegistrator reg, ITypeFinder typeFinder)
        {
            //Extensibility
            RegisterPubSubComponents(reg, typeFinder);
            reg.RegisterType <PluginService, IPluginService>(LifeCycle.PerDependency);
            reg.RegisterType <PluginManager, IPluginManager>(LifeCycle.PerDependency);

            //Monitoring
            reg.RegisterType <MonitorResultService, IMonitorResultService>(LifeCycle.PerDependency);
        }
Exemplo n.º 4
0
        private void RegisterSubscribersByType(IIocRegistrator registrator, ITypeFinder typeFinder,
                                               Type subscriberType)
        {
            var consumerTypes = typeFinder.FindClassesOfType(subscriberType).ToArray();

            foreach (var consumer in consumerTypes)
            {
                var services = consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType &&
                                  ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, subscriberType);

                registrator.RegisterType(consumer, services, LifeCycle.PerLifetime);
            }
        }
Exemplo n.º 5
0
        private void RegisterCommanders(IIocRegistrator reg, ITypeFinder typeFinder)
        {
            reg.RegisterInstance(new TestContextStepPartInterceptor());

            var commanderTypes = typeFinder.FindClassesOfType <ICommander>();

            if (!commanderTypes.Any())
            {
                throw new AutomationException("Failed to find commander implementors. Please register commanders");
            }

            foreach (var ct in commanderTypes)
            {
                var firstLevelCommanderInterfaces = GetFirstLevelInterfaces(ct)
                                                    .Where(t => typeof(ICommander).IsAssignableFrom(t));

                firstLevelCommanderInterfaces.ForEachItem(flci =>
                                                          reg.RegisterType(ct, flci, LifeCycle.PerDependency,
                                                                           interceptorTypes: new[] { typeof(TestContextStepPartInterceptor) }));
            }
        }
Exemplo n.º 6
0
 private void RegisterRepositories(IIocRegistrator reg, ITypeFinder typeFinder)
 {
     reg.RegisterType <MonitorResultMemoryRepository, IMonitorResultRepository>(LifeCycle.PerDependency);
 }