예제 #1
0
 private void CompareWithDefaultConfig()
 {
     Assert.AreEqual(
         DynamicCoverageDataCollectorImplTests.GetDefaultCodeCoverageConfig().Replace(" ", string.Empty)
         .Replace(Environment.NewLine, string.Empty),
         File.ReadAllText(this.aConfigFileName).Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty));
 }
예제 #2
0
        public void InitializeShouldInitializeVanguardWithRightCoverageSettings()
        {
            XmlElement configElement =
                DynamicCoverageDataCollectorImplTests.CreateXmlElement(@"<Configuration><CodeCoverage></CodeCoverage></Configuration>");

            this.directoryHelperMock.Setup(d => d.CreateDirectory(It.IsAny <string>()))
            .Callback <string>((path) =>
            {
                this.tempSessionDir = path;
                Directory.CreateDirectory(path);
            });

            this.fileHelperMock.Setup(f => f.WriteAllText(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((path, content) => { File.WriteAllText(path, content); });

            this.collectorImpl.Initialize(configElement, this.dataCollectionSinkMock.Object, this.dataCollectionLoggerMock.Object);

            XmlDocument defaultDocument = new XmlDocument();

            defaultDocument.LoadXml(DynamicCoverageDataCollectorImplTests.GetDefaultCodeCoverageConfig());

            Assert.AreEqual(DynamicCoverageDataCollectorImplTests.DefaultConfigFileName, Path.GetFileName(this.aConfigFileName));

            XmlDocument currentDocument = new XmlDocument();

            currentDocument.LoadXml(File.ReadAllText(this.aConfigFileName));

            var codeCoverageNodes = new Tuple <XmlNode, XmlNode>(currentDocument.DocumentElement, defaultDocument.DocumentElement);

            this.CompareResults(codeCoverageNodes.Item1, codeCoverageNodes.Item2, "./ModulePaths/Exclude");
            this.CompareResults(codeCoverageNodes.Item1, codeCoverageNodes.Item2, "./Functions/Exclude");
            this.CompareResults(codeCoverageNodes.Item1, codeCoverageNodes.Item2, "./Attributes/Exclude");
            this.CompareResults(codeCoverageNodes.Item1, codeCoverageNodes.Item2, "./Sources/Exclude");
        }
예제 #3
0
        public DynamicCoverageDataCollectorTests()
        {
            this.vanguardLocationProviderMock = new Mock <IProfilersLocationProvider>();
            this.implMock         = new Mock <IDynamicCoverageDataCollectorImpl>();
            this.eventsMock       = new Mock <IDataCollectionEvents>();
            this.sinkMock         = new Mock <TraceCollector.IDataCollectionSink>();
            this.loggerMock       = new Mock <IDataCollectionLogger>();
            this.agentContextMock = new Mock <IDataCollectionAgentContext>();
            this.environmentMock  = new Mock <IEnvironment>();
            this.collector        = new TestableDynamicCoverageDataCollector(this.vanguardLocationProviderMock.Object, this.implMock.Object, this.environmentMock.Object);

            this.vanguardLocationProviderMock.Setup(u => u.GetVanguardProfilerX86Path()).Returns(@"covrun86");
            this.vanguardLocationProviderMock.Setup(u => u.GetVanguardProfilerX64Path()).Returns(@"covrun64");
            this.vanguardLocationProviderMock.Setup(u => u.GetVanguardProfilerConfigX86Path()).Returns(@"config86");
            this.vanguardLocationProviderMock.Setup(u => u.GetVanguardProfilerConfigX64Path()).Returns(@"config64");
            this.vanguardLocationProviderMock.Setup(u => u.GetClrInstrumentationEngineX86Path()).Returns(@"clrie86");
            this.vanguardLocationProviderMock.Setup(u => u.GetClrInstrumentationEngineX64Path()).Returns(@"clrie64");

            this.implMock.Setup(i => i.CodeCoverageDepsJsonFilePath).Returns(@"C:\temp\codecoverage.deps.json");

            this.environmentMock.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Windows);
            var configElement = DynamicCoverageDataCollectorImplTests.CreateXmlElement(DynamicCoverageDataCollectorTests.DefaultConfig);

            this.collector.Initialize(configElement, this.eventsMock.Object, this.sinkMock.Object, this.loggerMock.Object, this.agentContextMock.Object);
        }
예제 #4
0
        public void GetEnvironmentVariablesShouldReturnRightEnvVariblesClrInstrumentationEngineEnabledForNetCoreThroughEnvVar()
        {
            Environment.SetEnvironmentVariable("VANGUARD_CLR_IE_INSTRUMENTATION_NETCORE", "1");
            Environment.SetEnvironmentVariable("VANGUARD_CLR_IE_INSTRUMENTATION_NETFRAMEWORK", "0");

            var configElement = DynamicCoverageDataCollectorImplTests.CreateXmlElement(DynamicCoverageDataCollectorTests.DefaultConfig);

            this.collector.Initialize(configElement, this.eventsMock.Object, this.sinkMock.Object, this.loggerMock.Object, this.agentContextMock.Object);

            var expectedEnvVariables = new Dictionary <string, string>
            {
                { "CORECLR_ENABLE_PROFILING", "1" },
                { "CORECLR_PROFILER_PATH_32", "clrie86" },
                { "CORECLR_PROFILER_PATH_64", "clrie64" },
                { "CORECLR_PROFILER", "{324F817A-7420-4E6D-B3C1-143FBED6D855}" },
                { "CODE_COVERAGE_SESSION_NAME", "MTM_123" },
                { "COR_PROFILER_PATH_32", "covrun86" },
                { "COR_PROFILER_PATH_64", "covrun64" },
                { "COR_ENABLE_PROFILING", "1" },
                { "COR_PROFILER", "{E5F256DC-7959-4DD6-8E4F-C11150AB28E0}" },
                { "MicrosoftInstrumentationEngine_ConfigPath32_VanguardInstrumentationProfiler", "config86" },
                { "MicrosoftInstrumentationEngine_ConfigPath64_VanguardInstrumentationProfiler", "config64" },
                { "MicrosoftInstrumentationEngine_LogLevel", "Errors" },
                { "MicrosoftInstrumentationEngine_LogLevel_{2A1F2A34-8192-44AC-A9D8-4FCC03DCBAA8}", "Errors" },
                { "MicrosoftInstrumentationEngine_DisableCodeSignatureValidation", "1" },
                { "MicrosoftInstrumentationEngine_FileLogPath", @"GENERATED" },
                { "VANGUARD_DOTNET_ADDITIONAL_DEPS", @"C:\temp\codecoverage.deps.json" }
            };

            this.implMock.Setup(i => i.GetSessionName()).Returns("MTM_123");

            var envVars = this.collector.GetEnvironmentVariables();

            VerifyEnvironmentVariables(expectedEnvVariables, envVars);
        }
        public DynamicCoverageDataCollectorTests()
        {
            this.vanguardLocationProviderMock = new Mock <IVanguardLocationProvider>();
            this.implMock         = new Mock <IDynamicCoverageDataCollectorImpl>();
            this.eventsMock       = new Mock <IDataCollectionEvents>();
            this.sinkMock         = new Mock <TraceCollector.IDataCollectionSink>();
            this.loggerMock       = new Mock <IDataCollectionLogger>();
            this.agentContextMock = new Mock <IDataCollectionAgentContext>();
            this.environmentMock  = new Mock <IEnvironment>();
            this.collector        = new TestableDynamicCoverageDataCollector(this.vanguardLocationProviderMock.Object, this.implMock.Object, this.environmentMock.Object);
            this.vanguardLocationProviderMock.Setup(u => u.GetVanguardDirectory()).Returns(Directory.GetCurrentDirectory);
            this.environmentMock.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Windows);
            var configElement = DynamicCoverageDataCollectorImplTests.CreateXmlElement(DynamicCoverageDataCollectorTests.DefaultConfig);

            this.collector.Initialize(configElement, this.eventsMock.Object, this.sinkMock.Object, this.loggerMock.Object, this.agentContextMock.Object);
        }
예제 #6
0
        public void SessionStartShouldUseAutoGenrateCoverageFileNameIfNotSpecified()
        {
            var sessionStartEventArgs = new SessionStartEventArgs();
            var coverageFilePath      = string.Empty;

            this.collectorImpl.Initialize(null, this.dataCollectionSinkMock.Object, this.dataCollectionLoggerMock.Object);
            this.vanguardMock.Setup(v => v.Start(It.IsAny <string>(), It.IsAny <DataCollectionContext>()))
            .Callback <string, DataCollectionContext>((filePath, dcContext) =>
            {
                coverageFilePath = filePath;
            });
            this.collectorImpl.SessionStart(null, sessionStartEventArgs);

            StringAssert.StartsWith(Path.GetDirectoryName(coverageFilePath), this.atempDirectory);
            StringAssert.Contains(coverageFilePath, DynamicCoverageDataCollectorImplTests.GetAutoGenerageCodeCoverageFileNamePrefix());
        }
예제 #7
0
        public void InitializeShouldInitializeDefaultConfigIfNoCodeCoverageConfigExists()
        {
            XmlElement configElement =
                DynamicCoverageDataCollectorImplTests.CreateXmlElement($"<Configuration><Framework>.NETCoreApp,Version=v1.1</Framework></Configuration>");

            this.directoryHelperMock.Setup(d => d.CreateDirectory(It.IsAny <string>()))
            .Callback <string>((path) =>
            {
                this.tempSessionDir = path;
                Directory.CreateDirectory(path);
            });

            this.fileHelperMock.Setup(f => f.WriteAllText(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((path, content) => { File.WriteAllText(path, content); });

            this.collectorImpl.Initialize(configElement, this.dataCollectionSinkMock.Object, this.dataCollectionLoggerMock.Object);

            this.CompareWithDefaultConfig();
        }
예제 #8
0
        public void InitializeShouldInitializeVanguardWithRightCoverageSettings()
        {
            var        expectedContent = "<CodeCoverage>CoverageSettingsContent</CodeCoverage>";
            XmlElement configElement   =
                DynamicCoverageDataCollectorImplTests.CreateXmlElement($"<Configuration>{expectedContent}</Configuration>");

            this.directoryHelperMock.Setup(d => d.CreateDirectory(It.IsAny <string>()))
            .Callback <string>((path) =>
            {
                this.tempSessionDir = path;
                Directory.CreateDirectory(path);
            });

            this.fileHelperMock.Setup(f => f.WriteAllText(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((path, content) => { File.WriteAllText(path, content); });

            this.collectorImpl.Initialize(configElement, this.dataCollectionSinkMock.Object, this.dataCollectionLoggerMock.Object);

            Assert.AreEqual(DynamicCoverageDataCollectorImplTests.DefaultConfigFileName, Path.GetFileName(this.aConfigFileName));
            Assert.AreEqual(expectedContent, File.ReadAllText(this.aConfigFileName));
        }