public void TestInit()
 {
     this.mockTestEventsPublisher     = new Mock <ITestEventsPublisher>();
     this.mockFileHelper              = new Mock <IFileHelper>();
     this.testPluginCache             = TestPluginCache.Instance;
     this.inProcDataCollectionManager = new TestableInProcDataCollectionExtensionManager(this.settingsXml, this.mockTestEventsPublisher.Object, this.defaultCodebase, this.testPluginCache, this.mockFileHelper.Object);
 }
        protected InProcDataCollectionExtensionManager(string runSettings, ITestEventsPublisher testEventsPublisher, string defaultCodeBase, TestPluginCache testPluginCache, IFileHelper fileHelper)
        {
            this.InProcDataCollectors     = new Dictionary <string, IInProcDataCollector>();
            this.inProcDataCollectionSink = new InProcDataCollectionSink();
            this.defaultCodeBase          = defaultCodeBase;
            this.fileHelper    = fileHelper;
            this.codeBasePaths = new List <string> {
                this.defaultCodeBase
            };

            // Get Datacollector codebase paths from test plugin cache
            var extensionPaths = testPluginCache.GetExtensionPaths(DataCollectorEndsWithPattern);

            foreach (var extensionPath in extensionPaths)
            {
                this.codeBasePaths.Add(Path.GetDirectoryName(extensionPath));
            }

            // Initialize InProcDataCollectors
            this.InitializeInProcDataCollectors(runSettings);

            if (this.IsInProcDataCollectionEnabled)
            {
                testEventsPublisher.TestCaseEnd   += this.TriggerTestCaseEnd;
                testEventsPublisher.TestCaseStart += this.TriggerTestCaseStart;
                testEventsPublisher.TestResult    += this.TriggerUpdateTestResult;
                testEventsPublisher.SessionStart  += this.TriggerTestSessionStart;
                testEventsPublisher.SessionEnd    += this.TriggerTestSessionEnd;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InProcDataCollectionExtensionManager"/> class.
 /// </summary>
 /// <param name="runSettings">
 /// The run settings.
 /// </param>
 /// <param name="testEventsPublisher">
 /// The data collection test case event manager.
 /// </param>
 /// <param name="defaultCodeBase">
 /// The default codebase to be used by inproc data collector
 /// </param>
 public InProcDataCollectionExtensionManager(string runSettings, ITestEventsPublisher testEventsPublisher, string defaultCodeBase, TestPluginCache testPluginCache)
     : this(runSettings, testEventsPublisher, defaultCodeBase, testPluginCache, new FileHelper())
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InProcDataCollector"/> class.
        /// </summary>
        /// <param name="codeBase">
        /// </param>
        /// <param name="assemblyQualifiedName">
        /// </param>
        /// <param name="interfaceTypeInfo">
        /// </param>
        /// <param name="configXml">
        /// </param>
        /// <param name="assemblyLoadContext">
        /// </param>
        internal InProcDataCollector(string codeBase, string assemblyQualifiedName, TypeInfo interfaceTypeInfo, string configXml, IAssemblyLoadContext assemblyLoadContext, TestPluginCache testPluginCache)
        {
            this.configXml           = configXml;
            this.assemblyLoadContext = assemblyLoadContext;

            var assembly = this.LoadInProcDataCollectorExtension(codeBase);

            Func <Type, bool> filterPredicate;

            if (Path.GetFileName(codeBase) == Constants.CoverletDataCollectorCodebase)
            {
                // If we're loading coverlet collector we skip to check the version of assembly
                // to allow upgrade throught nuget package
                filterPredicate = (x) => x.FullName.Equals(Constants.CoverletDataCollectorTypeName) && interfaceTypeInfo.IsAssignableFrom(x.GetTypeInfo());

                // Coverlet collector is consumed as nuget package we need to add assemblies directory to resolver to correctly load references.
                Debug.Assert(Path.IsPathRooted(codeBase), "Absolute path expected");
                testPluginCache.AddResolverSearchDirectories(new string[] { Path.GetDirectoryName(codeBase) });
            }
            else
            {
                filterPredicate = (x) => x.AssemblyQualifiedName.Equals(assemblyQualifiedName) && interfaceTypeInfo.IsAssignableFrom(x.GetTypeInfo());
            }

            this.dataCollectorType     = assembly?.GetTypes().FirstOrDefault(filterPredicate);
            this.AssemblyQualifiedName = this.dataCollectorType?.AssemblyQualifiedName;
        }
 public TestableInProcDataCollectionExtensionManager(string runSettings, ITestEventsPublisher mockTestEventsPublisher, string defaultCodebase, TestPluginCache testPluginCache, IFileHelper fileHelper)
     : base(runSettings, mockTestEventsPublisher, defaultCodebase, testPluginCache, fileHelper)
 {
 }