Example #1
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);
        }
        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);
        }
        public void GetEnvironmentVariablesShouldReturnNoEnvVaribles()
        {
            this.implMock = new Mock <IDynamicCoverageDataCollectorImpl>();
            this.environmentMock.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Unix);
            this.collector = new TestableDynamicCoverageDataCollector(this.vanguardLocationProviderMock.Object, null, this.environmentMock.Object);

            this.collector.Initialize(
                null,
                this.eventsMock.Object,
                this.sinkMock.Object,
                this.loggerMock.Object,
                this.agentContextMock.Object);
            var envVars = this.collector.GetEnvironmentVariables();

            Assert.IsFalse(envVars.Any(), "No environment variables set on unix.");
        }
        public void InitializeShouldLogWarningIfCurrentOperatingSystemIsUnix()
        {
            this.environmentMock.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Unix);
            this.collector = new TestableDynamicCoverageDataCollector(this.vanguardLocationProviderMock.Object, null, this.environmentMock.Object);

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

            var expectedExMsg =
                "No code coverage data available. Code coverage is currently supported only on Windows.";

            this.loggerMock.Verify(l => l.LogWarning(It.IsAny <DataCollectionContext>(), expectedExMsg));
        }
        public void InitializeShouldNotRegisterForSessionEvents()
        {
            this.implMock = new Mock <IDynamicCoverageDataCollectorImpl>();
            this.environmentMock.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Unix);
            this.collector = new TestableDynamicCoverageDataCollector(this.vanguardLocationProviderMock.Object, null, this.environmentMock.Object);

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

            this.eventsMock.Raise(e => e.SessionStart += null, new SessionStartEventArgs());
            this.eventsMock.Raise(e => e.SessionEnd   += null, new SessionEndEventArgs());

            this.implMock.Verify(i => i.SessionStart(It.IsAny <object>(), It.IsAny <SessionStartEventArgs>()), Times.Never);
            this.implMock.Verify(i => i.SessionEnd(It.IsAny <object>(), It.IsAny <SessionEndEventArgs>()), Times.Never);
        }