コード例 #1
0
        public EventSubscriptionItem Map(EventSubscriptionJsonSection section)
        {
            if (string.IsNullOrEmpty(section.HandlerType))
            {
                throw new ConfigurationException(
                          $"\"{nameof(EventSubscriptionJsonSection.HandlerType)}\" configuration property of event subscription section is not specified.");
            }

            Type handlerType = TypeFinder.FindInAssemblies(section.HandlerType, _assembliesToFindEventHandlerTypes);

            if (string.IsNullOrEmpty(section.EventType))
            {
                return(CreateSubscription(handlerType, section.ExtraPropertiesMap));
            }
            else
            {
                Type eventType = TypeFinder.FindInAssemblies(section.EventType, _assembliesToFindEventTypes);
                return(CreateSubscription(eventType, handlerType, section.ExtraPropertiesMap));
            }
        }
コード例 #2
0
        public Attribute Map(AttributeJsonSection section)
        {
            if (string.IsNullOrEmpty(section.Type))
            {
                throw new ConfigurationException(
                          "\"type\" configuration property of attribute section is not specified.");
            }

            string typeName = NormalizeAttributeTypeName(section.Type);

            Type attributeType = TypeFinder.FindInAssemblies(typeName, _assembliesToFindAttributeTypes);

            if (!typeof(Attribute).IsAssignableFrom(attributeType))
            {
                throw new ConfigurationException(
                          $"\"type\"=\"{section.Type}\" configuration property of attribute section doesn't reference an attribute type.");
            }

            var valuesMap = section.ExtraPropertiesMap.ToDictionary(
                x => x.Key,
                x => PostProcessConfigurationValue(x.Key, x.Value));

            return((Attribute)_objectCreator.Create(attributeType, valuesMap, s_alternativeParameterNamesMap));
        }
コード例 #3
0
 public void TypeFinder_FindInAssemblies_Throws_NotFound(string typeName)
 {
     Assert.Throws <TypeNotFoundException>(() =>
                                           TypeFinder.FindInAssemblies(typeName, assembliesToFindIn));
 }
コード例 #4
0
 public Type TypeFinder_FindInAssemblies(string typeName)
 {
     return(TypeFinder.FindInAssemblies(typeName, assembliesToFindIn));
 }
コード例 #5
0
        public static AtataContextBuilder Map <TConfig>(TConfig config, AtataContextBuilder builder)
            where TConfig : JsonConfig <TConfig>
        {
            if (config.DriverInitializationStage != null)
            {
                builder.UseDriverInitializationStage(config.DriverInitializationStage.Value);
            }

            if (config.BaseUrl != null)
            {
                builder.UseBaseUrl(config.BaseUrl);
            }

            if (config.Culture != null)
            {
                builder.UseCulture(config.Culture);
            }

            if (config.TimeZone != null)
            {
                builder.UseTimeZone(config.TimeZone);
            }

            if (config.ArtifactsPath != null)
            {
                builder.UseArtifactsPath(config.ArtifactsPath);
            }

            if (config.BaseRetryTimeout != null)
            {
                builder.UseBaseRetryTimeout(TimeSpan.FromSeconds(config.BaseRetryTimeout.Value));
            }

            if (config.BaseRetryInterval != null)
            {
                builder.UseBaseRetryInterval(TimeSpan.FromSeconds(config.BaseRetryInterval.Value));
            }

            if (config.ElementFindTimeout != null)
            {
                builder.UseElementFindTimeout(TimeSpan.FromSeconds(config.ElementFindTimeout.Value));
            }

            if (config.ElementFindRetryInterval != null)
            {
                builder.UseElementFindRetryInterval(TimeSpan.FromSeconds(config.ElementFindRetryInterval.Value));
            }

            if (config.WaitingTimeout != null)
            {
                builder.UseWaitingTimeout(TimeSpan.FromSeconds(config.WaitingTimeout.Value));
            }

            if (config.WaitingRetryInterval != null)
            {
                builder.UseWaitingRetryInterval(TimeSpan.FromSeconds(config.WaitingRetryInterval.Value));
            }

            if (config.VerificationTimeout != null)
            {
                builder.UseVerificationTimeout(TimeSpan.FromSeconds(config.VerificationTimeout.Value));
            }

            if (config.VerificationRetryInterval != null)
            {
                builder.UseVerificationRetryInterval(TimeSpan.FromSeconds(config.VerificationRetryInterval.Value));
            }

            if (config.DefaultAssemblyNamePatternToFindTypes != null)
            {
                builder.UseDefaultAssemblyNamePatternToFindTypes(config.DefaultAssemblyNamePatternToFindTypes);
            }

            if (config.AssemblyNamePatternToFindComponentTypes != null)
            {
                builder.UseAssemblyNamePatternToFindComponentTypes(config.AssemblyNamePatternToFindComponentTypes);
            }

            if (config.AssemblyNamePatternToFindAttributeTypes != null)
            {
                builder.UseAssemblyNamePatternToFindAttributeTypes(config.AssemblyNamePatternToFindAttributeTypes);
            }

            if (config.AssemblyNamePatternToFindEventTypes != null)
            {
                builder.UseAssemblyNamePatternToFindEventTypes(config.AssemblyNamePatternToFindEventTypes);
            }

            if (config.AssemblyNamePatternToFindEventHandlerTypes != null)
            {
                builder.UseAssemblyNamePatternToFindEventHandlerTypes(config.AssemblyNamePatternToFindEventHandlerTypes);
            }

            Lazy <Assembly[]> lazyAssembliesToFindTypesIn = new Lazy <Assembly[]>(
                () => AssemblyFinder.FindAllByPattern(builder.BuildingContext.DefaultAssemblyNamePatternToFindTypes),
                isThreadSafe: false);

            if (config.AssertionExceptionType != null)
            {
                builder.UseAssertionExceptionType(
                    TypeFinder.FindInAssemblies(config.AssertionExceptionType, lazyAssembliesToFindTypesIn.Value));
            }

            if (config.AggregateAssertionExceptionType != null)
            {
                builder.UseAggregateAssertionExceptionType(
                    TypeFinder.FindInAssemblies(config.AggregateAssertionExceptionType, lazyAssembliesToFindTypesIn.Value));
            }

            if (config.AggregateAssertionStrategyType != null)
            {
                builder.UseAggregateAssertionStrategy(
                    ActivatorEx.CreateInstance <IAggregateAssertionStrategy>(
                        TypeFinder.FindInAssemblies(config.AggregateAssertionStrategyType, lazyAssembliesToFindTypesIn.Value)));
            }

            if (config.WarningReportStrategyType != null)
            {
                builder.UseWarningReportStrategy(
                    ActivatorEx.CreateInstance <IWarningReportStrategy>(
                        TypeFinder.FindInAssemblies(config.WarningReportStrategyType, lazyAssembliesToFindTypesIn.Value)));
            }

            if (config.UseNUnitTestName)
            {
                builder.UseNUnitTestName();
            }

            if (config.UseNUnitTestSuiteName)
            {
                builder.UseNUnitTestSuiteName();
            }

            if (config.UseNUnitTestSuiteType)
            {
                builder.UseNUnitTestSuiteType();
            }

            if (config.LogNUnitError)
            {
                builder.LogNUnitError();
            }

            if (config.TakeScreenshotOnNUnitError)
            {
                if (config.TakeScreenshotOnNUnitErrorTitle != null)
                {
                    builder.TakeScreenshotOnNUnitError(config.TakeScreenshotOnNUnitErrorTitle);
                }
                else
                {
                    builder.TakeScreenshotOnNUnitError();
                }
            }

            if (config.OnCleanUpAddArtifactsToNUnitTestContext)
            {
                builder.OnCleanUpAddArtifactsToNUnitTestContext();
            }

            if (config.OnCleanUpAddDirectoryFilesToNUnitTestContext != null)
            {
                builder.OnCleanUpAddDirectoryFilesToNUnitTestContext(config.OnCleanUpAddDirectoryFilesToNUnitTestContext);
            }

            if (config.UseNUnitAggregateAssertionStrategy)
            {
                builder.UseNUnitAggregateAssertionStrategy();
            }

            if (config.UseNUnitWarningReportStrategy)
            {
                builder.UseNUnitWarningReportStrategy();
            }

            if (config.UseAllNUnitFeatures)
            {
                builder.UseAllNUnitFeatures();
            }

            if (config.LogConsumers != null)
            {
                foreach (var item in config.LogConsumers)
                {
                    MapLogConsumer(item, builder);
                }
            }

            if (config.ScreenshotConsumers != null)
            {
                foreach (var item in config.ScreenshotConsumers)
                {
                    MapScreenshotConsumer(item, builder);
                }
            }

            if (config.Drivers != null)
            {
                foreach (var item in config.Drivers)
                {
                    MapDriver(item, builder);
                }
            }

            if (config.Attributes != null)
            {
                MapAttributes(config.Attributes, builder);
            }

            if (config.EventSubscriptions != null)
            {
                MapEventSubscriptions(config.EventSubscriptions, builder);
            }

            return(builder);
        }