public VanguardTests() { TestCase testcase = new TestCase { Id = Guid.NewGuid() }; this.dataCollectionContext = new DataCollectionContext(testcase); this.dataCollectionLoggerMock = new Mock <IDataCollectionLogger>(); this.processJobObject = new ProcessJobObject(); this.vanguardCommandBuilderMock = new Mock <IVanguardCommandBuilder>(); this.vanguardLocationProviderMock = new Mock <IProfilersLocationProvider>(); this.vanguard = new Vanguard(this.vanguardLocationProviderMock.Object, this.vanguardCommandBuilderMock.Object, this.processJobObject); this.sessionName = Guid.NewGuid().ToString(); this.configFileName = string.Format(VanguardTests.ConfigFileNameFormat, Path.GetTempPath(), this.sessionName); this.outputDir = Path.GetDirectoryName(this.configFileName); Directory.CreateDirectory(this.outputDir); File.WriteAllText(this.configFileName, VanguardTests.ConfigXml); this.outputFileName = Path.Combine(this.outputDir, Guid.NewGuid() + ".coverage"); this.vanguardCommandBuilderMock.Setup(c => c.GenerateCommandLine(VanguardCommand.Shutdown, this.sessionName, It.IsAny <string>(), It.IsAny <string>())) .Returns(VanguardTests.GetShutdownCommand(this.sessionName)); this.vanguard.Initialize(this.sessionName, this.configFileName, this.dataCollectionLoggerMock.Object); this.vanguardLocationProviderMock.Setup(c => c.GetVanguardPath()).Returns(Path.Combine(Directory.GetCurrentDirectory(), "CodeCoverage", "CodeCoverage.exe")); }
public void StartShouldThrowOnTimeout() { Environment.SetEnvironmentVariable(EnvironmentHelper.VstestConnectionTimeout, "0"); var expectedErrorMessage = "Failed to receive running event from CodeCoverage.exe in 0 seconds, This may occur due to machine slowness, please set environment variable VSTEST_CONNECTION_TIMEOUT to increase timeout."; this.vanguardCommandBuilderMock .Setup(c => c.GenerateCommandLine( VanguardCommand.Collect, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(VanguardTests.GetCollectCommand(this.sessionName, this.outputFileName, this.configFileName)); var exception = Assert.ThrowsException <VanguardException>(() => this.vanguard.Start(this.outputFileName, this.dataCollectionContext)); Assert.AreEqual(expectedErrorMessage, exception.Message); }
public void StartShouldStartVanguardProcessWithCollectCommand() { var cts = new CancellationTokenSource(); var numOfProcessCreatedTask = NumberOfProcessLaunchedUtility.NumberOfProcessCreated( cts, VanguardTests.CodeCoverageExeFileName); this.vanguardCommandBuilderMock.Setup(c => c.GenerateCommandLine(VanguardCommand.Collect, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(VanguardTests.GetCollectCommand(this.sessionName, this.outputFileName, this.configFileName)); this.vanguard.Start(this.outputFileName, this.dataCollectionContext); cts.Cancel(); // TODO find the reason why additional process launched when collecting code coverage. Assert.IsTrue(numOfProcessCreatedTask.Result == 1 || numOfProcessCreatedTask.Result == 2, "Number of process created:{0} expected is 1 or 2."); }