コード例 #1
0
        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());
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 public static MockStorage AutoBodyBy(this PProxyProcess proc, MockStorage ms)
 {
     { var m = proc.StartInfoGet().BodyBy(ms); m.Setup(_ => _(It.IsAny <Process>())).Returns(new ProcessStartInfo()); ms.Set(proc.StartInfoGet, m); }
     { var m = proc.MainModuleGet().BodyBy(ms); m.Setup(_ => _(It.IsAny <Process>())).Returns(new PProxyProcessModule()); ms.Set(proc.MainModuleGet, m); }
     { var m = proc.CloseMainWindow().BodyBy(ms); m.Setup(_ => _(It.IsAny <Process>())).Returns(true); ms.Set(proc.CloseMainWindow, m); }
     return(ms);
 }
コード例 #5
0
ファイル: ULProcessMixinTest.cs プロジェクト: poizan42/Prig
        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();
            }
        }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
ファイル: ULProcessMixinTest.cs プロジェクト: urasandesu/Prig
        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();
            }
        }
コード例 #8
0
ファイル: ULProcessMixinTest.cs プロジェクト: urasandesu/Prig
        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);
            }
        }
コード例 #9
0
ファイル: ULProcessMixinTest.cs プロジェクト: urasandesu/Prig
        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
                Assert.Throws<FileNotFoundException>(() => ULProcessMixin.RestartCurrentProcess());
            }
        }
コード例 #10
0
ファイル: ULProcessMixinTest.cs プロジェクト: urasandesu/Prig
        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();
            }
        }
コード例 #11
0
ファイル: ULProcessMixinTest.cs プロジェクト: urasandesu/Prig
        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);
            }
        }