예제 #1
0
        /// <summary>
        /// Registers the hooks in the execution context.
        /// </summary>
        private void RegisterHooks()
        {
            ExecutionContext.Instance.ClearHooks();

            List <Type> hooks = TypeLocatorHelper.GetImplementedTypes <IHook>(_testAssembly);

            foreach (Type type in hooks)
            {
                int priority = 0;

                HookPriorityAttribute hookPriorityAttribute =
                    (HookPriorityAttribute)Attribute.GetCustomAttribute(type, typeof(HookPriorityAttribute));

                if (hookPriorityAttribute != null)
                {
                    priority = hookPriorityAttribute.Priority;
                }

                ExecutionContext.Instance.RegisterHook(
                    new HookInstance
                {
                    Instance = ClassActivatorHelper <IHook> .CreateInstance(type),
                    Priority = priority
                });
            }
        }
예제 #2
0
        /// <summary>
        /// Creates the test filter.
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="features">The features.</param>
        /// <returns><see cref="TestFilter"/>.</returns>
        public static TestFilter CreateTestFilter(Assembly assembly, List <string> features)
        {
            ITestFilterBuilder filterBuilder = new TestFilterBuilder();

            List <string> filters = features.Select(feature =>
                                                    $"class = {TypeLocatorHelper.GetTypeByAttributeAndName(assembly, typeof(DescriptionAttribute), feature)}")
                                    .ToList();

            filterBuilder.SelectWhere(string.Join(" || ", filters));

            return(filterBuilder.GetFilter());
        }
예제 #3
0
        /// <summary>
        /// Gets the plugins.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>List of plugins.</returns>
        private List <T> GetPlugins <T>()
        {
            List <T> plugins = new List <T>();

            foreach (Assembly assembly in _pluginAssemblies)
            {
                List <Type> types = TypeLocatorHelper.GetImplementedTypes <T>(assembly);

                types.ForEach(x =>
                {
                    plugins.Add(ClassActivatorHelper <T> .CreateInstance(x));
                });
            }

            return(plugins);
        }
예제 #4
0
        /// <summary>
        /// Creates the configuration file.
        /// </summary>
        /// <param name="deploymentFolderLocation">The deployment folder location.</param>
        /// <param name="testAssemblyName">Name of the test assembly.</param>
        /// <param name="packageLocation">The package location.</param>
        /// <param name="packageName">Name of the package.</param>
        private void CreateConfigurationFile(
            string deploymentFolderLocation,
            string testAssemblyName,
            string packageLocation,
            string packageName)
        {
            string packageFileFullName = Path.Combine(packageLocation, $"{packageName}.zip");
            string configFileFullName  = Path.Combine(packageLocation, $"{packageName}.json");

            PackageConfiguration packageConfiguration =
                new PackageConfiguration
            {
                TestAssemblyName = testAssemblyName,
                Hash             = CryptographyHelper.GetMd5HashFromFile(packageFileFullName)
            };

            List <string> assemblyFeatures =
                TypeLocatorHelper.GetFeatureTypes(Assembly.LoadFrom(Path.Combine(deploymentFolderLocation, testAssemblyName)))
                .Select(x => x.Name.Substring(0, x.Name.Length - 7))
                .ToList();

            if (!assemblyFeatures.Any())
            {
                throw new Exception($"No feature have been found in the test assembly {Path.Combine(packageLocation, testAssemblyName)}");
            }

            List <Feature> features = assemblyFeatures.Select(assemblyFeature => new Feature
            {
                Id   = CryptographyHelper.GetMd5HashFromString($"{testAssemblyName} - {assemblyFeature}"),
                Name = assemblyFeature
            })
                                      .ToList();

            packageConfiguration.Features = features;

            File.WriteAllText(
                configFileFullName,
                JsonConvert.SerializeObject(packageConfiguration, Formatting.Indented));
        }