/// <summary> /// Initializes a new instance of the <see cref="BlameCollectorTests"/> class. /// </summary> public BlameCollectorTests() { // Initializing mocks this.mockLogger = new Mock <DataCollectionLogger>(); this.mockDataColectionEvents = new Mock <DataCollectionEvents>(); this.mockDataCollectionSink = new Mock <DataCollectionSink>(); this.mockBlameReaderWriter = new Mock <IBlameReaderWriter>(); this.mockProcessDumpUtility = new Mock <IProcessDumpUtility>(); this.mockInactivityTimer = new Mock <IInactivityTimer>(); this.mockFileHelper = new Mock <IFileHelper>(); this.blameDataCollector = new TestableBlameCollector( this.mockBlameReaderWriter.Object, this.mockProcessDumpUtility.Object, this.mockInactivityTimer.Object, this.mockFileHelper.Object); // Initializing members TestCase testcase = new TestCase { Id = Guid.NewGuid() }; this.dataCollectionContext = new DataCollectionContext(testcase); this.configurationElement = null; this.context = new DataCollectionEnvironmentContext(this.dataCollectionContext); this.filepath = Path.Combine(Path.GetTempPath(), "Test"); FileStream stream = File.Create(this.filepath); stream.Dispose(); }
public void InitializeWithDumpForHangShouldCaptureKillTestHostOnTimeoutEvenIfAttachingDumpFails() { this.blameDataCollector = new TestableBlameCollector( this.mockBlameReaderWriter.Object, this.mockProcessDumpUtility.Object, null, this.mockFileHelper.Object); var dumpFile = "abc_hang.dmp"; var hangBasedDumpcollected = new ManualResetEventSlim(); this.mockFileHelper.Setup(x => x.Exists(It.Is <string>(y => y == "abc_hang.dmp"))).Returns(true); this.mockFileHelper.Setup(x => x.GetFullPath(It.Is <string>(y => y == "abc_hang.dmp"))).Returns("abc_hang.dmp"); this.mockProcessDumpUtility.Setup(x => x.StartHangBasedProcessDump(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <Action <string> >())); this.mockProcessDumpUtility.Setup(x => x.GetDumpFiles()).Returns(new[] { dumpFile }); this.mockDataCollectionSink.Setup(x => x.SendFileAsync(It.IsAny <FileTransferInformation>())).Callback(() => hangBasedDumpcollected.Set()).Throws(new Exception("Some other exception")); this.blameDataCollector.Initialize( this.GetDumpConfigurationElement(false, false, true, 0), this.mockDataColectionEvents.Object, this.mockDataCollectionSink.Object, this.mockLogger.Object, this.context); hangBasedDumpcollected.Wait(1000); this.mockProcessDumpUtility.Verify(x => x.StartHangBasedProcessDump(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <Action <string> >()), Times.Once); this.mockProcessDumpUtility.Verify(x => x.GetDumpFiles(), Times.Once); this.mockDataCollectionSink.Verify(x => x.SendFileAsync(It.Is <FileTransferInformation>(y => y.Path == dumpFile)), Times.Once); }