Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
 public static MockStorage AutoBodyBy(MockStorage ms)
 {
     { var m = PProcess.GetCurrentProcess().BodyBy(ms); m.Setup(_ => _()).Returns(new PProxyProcess()); ms.Set(PProcess.GetCurrentProcess, m); }
     { var m = PProcess.StartProcessStartInfo().BodyBy(ms); m.Setup(_ => _(It.IsAny <ProcessStartInfo>())).Returns(new PProxyProcess()); ms.Set(PProcess.StartProcessStartInfo, m); }
     return(ms);
 }