public void RestartCurrentProcess_should_throw_exception_as_it_is_except_for_Win32Exception() { using (new IndirectionsContext()) { // Arrange var ms = new MockStorage(MockBehavior.Strict); PEnvironmentMixin.AutoBodyBy(ms); var curProcMainMod = new PProxyProcessModule(); curProcMainMod.AutoBodyBy(ms); var curProc = new PProxyProcess(); curProc.AutoBodyBy(ms); curProc.MainModuleGet().Body = @this => curProcMainMod; PProcessMixin.AutoBodyBy(ms). Customize(m => m. Do(PProcess.StartProcessStartInfo).Setup(_ => _(It.IsAny<ProcessStartInfo>())).Throws(new FileNotFoundException()) ); PProcess.GetCurrentProcess().Body = () => curProc; // Act, Assert ExceptionAssert.Throws<FileNotFoundException>(() => ULProcessMixin.RestartCurrentProcess()); } }
public void RestartCurrentProcess_should_organize_command_line_arguments_if_they_contain_double_quote() { using (new IndirectionsContext()) { // Arrange var ms = new MockStorage(MockBehavior.Strict); PEnvironmentMixin.AutoBodyBy(ms). Customize(m => m. Do(PEnvironment.GetCommandLineArgs).Setup(_ => _()).Returns(new[] { Guid.NewGuid().ToString(), "a a", "\"b\"bb", "c" }) ); var curProcMainMod = new PProxyProcessModule(); curProcMainMod.AutoBodyBy(ms); var curProc = new PProxyProcess(); curProc.AutoBodyBy(ms); curProc.MainModuleGet().Body = @this => curProcMainMod; PProcessMixin.AutoBodyBy(ms). Customize(m => m. Do(PProcess.StartProcessStartInfo).Setup(_ => _(It.Is<ProcessStartInfo>(x => x.Arguments == "\"a a\" \"\\\"b\\\"bb\" \"c\"" ))).Returns(new PProxyProcess()) ); PProcess.GetCurrentProcess().Body = () => curProc; // Act var result = ULProcessMixin.RestartCurrentProcess(); // Assert Assert.IsTrue(result); } }
public void RestartCurrentProcess_should_return_false_if_user_cancelled_starting_process() { using (new IndirectionsContext()) { // Arrange var ms = new MockStorage(MockBehavior.Strict); PEnvironmentMixin.AutoBodyBy(ms); var curProcMainMod = new PProxyProcessModule(); curProcMainMod.AutoBodyBy(ms); var curProc = new PProxyProcess(); curProc.AutoBodyBy(ms); curProc.MainModuleGet().Body = @this => curProcMainMod; PProcessMixin.AutoBodyBy(ms). Customize(m => m. Do(PProcess.StartProcessStartInfo).Setup(_ => _(It.IsAny<ProcessStartInfo>())).Throws(new Win32Exception(1223)) ); PProcess.GetCurrentProcess().Body = () => curProc; // Act var result = ULProcessMixin.RestartCurrentProcess(); // Assert Assert.IsFalse(result); } }
public void RestartCurrentProcess_should_start_new_process_and_close_current_process() { using (new IndirectionsContext()) { // Arrange var ms = new MockStorage(MockBehavior.Strict); PEnvironment.GetCommandLineArgs().BodyBy(ms).Expect(_ => _(), Times.Once()).Returns(new[] { "file name" }); PEnvironment.CurrentDirectoryGet().BodyBy(ms).Expect(_ => _(), Times.Once()).Returns("current directory"); var curProcMainMod = new PProxyProcessModule(); curProcMainMod.AutoBodyBy(ms). Customize(m => m. Do(curProcMainMod.FileNameGet).Expect(_ => _(curProcMainMod), Times.Once()).Returns("file path") ); var curProc = new PProxyProcess(); curProc.StartInfoGet().BodyBy(ms).Expect(_ => _(curProc), Times.Once()).Returns(new ProcessStartInfo() { UserName = "******" }); curProc.MainModuleGet().BodyBy(ms).Expect(_ => _(curProc), Times.Once()).Returns(curProcMainMod); curProc.CloseMainWindow().BodyBy(ms).Expect(_ => _(curProc), Times.Once()).Returns(true); PProcess.GetCurrentProcess().BodyBy(ms).Expect(_ => _(), Times.Once()).Returns(curProc); PProcess.StartProcessStartInfo().BodyBy(ms).Expect(_ => _(It.Is <ProcessStartInfo>(x => x.UserName == "urasandesu" && x.UseShellExecute == true && x.WorkingDirectory == "current directory" && x.FileName == "file path" )), Times.Once()).Returns(new PProxyProcess()); // Act var result = ULProcessMixin.RestartCurrentProcess(); // Assert Assert.IsTrue(result); ms.Verify(); } }
public void RestartCurrentProcessWith_should_invoke_additionalSetup() { using (new IndirectionsContext()) { // Arrange var ms = new MockStorage(MockBehavior.Strict); PEnvironmentMixin.AutoBodyBy(ms); var curProcMainMod = new PProxyProcessModule(); curProcMainMod.AutoBodyBy(ms); var procStartInfo = new ProcessStartInfo(); var curProc = new PProxyProcess(); curProc.AutoBodyBy(ms); curProc.StartInfoGet().Body = @this => procStartInfo; curProc.MainModuleGet().Body = @this => curProcMainMod; PProcessMixin.AutoBodyBy(ms). Customize(m => m. Do(PProcess.StartProcessStartInfo).Expect(_ => _(It.Is<ProcessStartInfo>(x => x.Verb == "runas" )), Times.Once()).Returns(new PProxyProcess()) ); PProcess.GetCurrentProcess().Body = () => curProc; var additionalSetup = ms.Create<Action<ProcessStartInfo>>().Object; Mock.Get(additionalSetup).Setup(_ => _(It.IsAny<ProcessStartInfo>())).Callback(() => procStartInfo.Verb = "runas"); // Act var result = ULProcessMixin.RestartCurrentProcessWith(additionalSetup); // Assert Assert.IsTrue(result); ms.Verify(); } }