Example #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();
            }
        }
Example #2
0
 public static MockStorage AutoBodyBy(MockStorage ms)
 {
     { var m = PEnvironment.GetCommandLineArgs().BodyBy(ms); m.Setup(_ => _()).Returns(new[] { Guid.NewGuid().ToString() }); ms.Set(PEnvironment.GetCommandLineArgs, m); }
     { var m = PEnvironment.CurrentDirectoryGet().BodyBy(ms); m.Setup(_ => _()).Returns(Guid.NewGuid().ToString()); ms.Set(PEnvironment.CurrentDirectoryGet, m); }
     return(ms);
 }