Пример #1
0
        public void GetDumpFileWillThrowExceptionIfNoDumpfile()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { });
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);

            this.mockHangDumperFactory.Setup(x => x.Create(It.IsAny <string>()))
            .Returns(new Mock <IHangDumper>().Object);

            this.mockCrashDumperFactory.Setup(x => x.Create(It.IsAny <string>()))
            .Returns(new Mock <ICrashDumper>().Object);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockHangDumperFactory.Object,
                this.mockCrashDumperFactory.Object);

            processDumpUtility.StartTriggerBasedProcessDump(processId, guid, testResultsDirectory, false, ".NETCoreApp,Version=v5.0");

            var ex = Assert.ThrowsException <FileNotFoundException>(() => processDumpUtility.GetDumpFile());

            Assert.AreEqual(ex.Message, Resources.Resources.DumpFileNotGeneratedErrorMessage);
        }
Пример #2
0
        public void GetDumpFileWillThrowExceptionIfNoDumpfile()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { });
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);
            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()))
            .Returns(this.mockProcDumpProcess.Object);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartTriggerBasedProcessDump(processId, guid, testResultsDirectory);

            var ex = Assert.ThrowsException <FileNotFoundException>(() => processDumpUtility.GetDumpFile());

            Assert.AreEqual(ex.Message, Resources.Resources.DumpFileNotGeneratedErrorMessage);
        }
Пример #3
0
        public void StartProcessDumpForHangWillStartProcDumpExeWithCorrectParams()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var filename             = $"{process}_{processId}_{guid}_hangdump.dmp";
            var args                 = $"-accepteula -n 1 -ma {processId} {filename}";
            var testResultsDirectory = "D:\\TestResults";

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()))
            .Returns(this.mockProcDumpProcess.Object);
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);
            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { Path.Combine(testResultsDirectory, filename) });

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartHangBasedProcessDump(processId, guid, testResultsDirectory, isFullDump: true);

            this.mockProcessHelper.Verify(x => x.LaunchProcess(It.IsAny <string>(), args, It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()), Times.Once);
            Assert.AreEqual(Path.Combine(testResultsDirectory, filename), processDumpUtility.GetDumpFile());
        }
Пример #4
0
        public void GetDumpFileWillWaitForProcessToExitAndGetDumpFile()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { "dump.dmp" });
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);
            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()))
            .Returns(this.mockProcDumpProcess.Object);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartTriggerBasedProcessDump(processId, guid, testResultsDirectory);
            processDumpUtility.GetDumpFile();

            this.mockProcessHelper.Verify(x => x.WaitForProcessExit(It.IsAny <Process>()), Times.Once);
        }
Пример #5
0
        public void StartProcessDumpWillStartProcDumpExeWithCorrectParamsAndGetDumpFileReturnsFullPath()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var filename             = $"{process}_{processId}_{guid}.dmp";
            var args                 = $"-accepteula -e 1 -g -t -f STACK_OVERFLOW -f ACCESS_VIOLATION {processId} {filename}";
            var testResultsDirectory = "D:\\TestResults";

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null))
            .Returns(this.mockProcDumpProcess.Object);
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);

            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { Path.Combine(testResultsDirectory, filename) });

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartProcessDump(processId, guid, testResultsDirectory);

            this.mockProcessHelper.Verify(x => x.LaunchProcess(It.IsAny <string>(), args, It.IsAny <string>(), null, null, null), Times.Once);
            Assert.AreEqual(Path.Combine(testResultsDirectory, filename), processDumpUtility.GetDumpFile());
        }
Пример #6
0
        public void GetDumpFileWillReturnEmptyIfProcDumpDidntStart()
        {
            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null))
            .Throws(new Exception());

            var processDumpUtility = new ProcessDumpUtility(this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockPlatformEnvironment.Object);

            Assert.ThrowsException <Exception>(() => processDumpUtility.StartProcessDump(12345, "guid", "D:\\TestResults"));
            Assert.AreEqual(string.Empty, processDumpUtility.GetDumpFile());
        }
Пример #7
0
        public void GetDumpFileWillWaitForProcessToExitAndGetDumpFile()
        {
            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { "dump.dmp" });

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null))
            .Returns(this.mockProcDumpProcess.Object);

            var processDumpUtility = new ProcessDumpUtility(this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockPlatformEnvironment.Object);

            processDumpUtility.StartProcessDump(12345, "guid", "D:\\TestResults");
            processDumpUtility.GetDumpFile();

            this.mockProcessHelper.Verify(x => x.WaitForProcessExit(It.IsAny <Process>()), Times.Once);
        }
Пример #8
0
        public void GetDumpFileWillThrowExceptionIfNoDumpfile()
        {
            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { });

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null))
            .Returns(this.mockProcDumpProcess.Object);

            var processDumpUtility = new ProcessDumpUtility(this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockPlatformEnvironment.Object);

            processDumpUtility.StartProcessDump(12345, "guid", "D:\\TestResults");

            var ex = Assert.ThrowsException <FileNotFoundException>(() => processDumpUtility.GetDumpFile());

            Assert.AreEqual(ex.Message, Resources.Resources.DumpFileNotGeneratedErrorMessage);
        }
Пример #9
0
        public void GetDumpFileWillReturnEmptyIfProcDumpDidntStart()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()))
            .Throws(new Exception());
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            Assert.ThrowsException <Exception>(() => processDumpUtility.StartTriggerBasedProcessDump(processId, guid, testResultsDirectory));
            Assert.AreEqual(string.Empty, processDumpUtility.GetDumpFile());
        }