Esempio n. 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());
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        public void MockStorage_should_provide_fluent_setup_through_MockProxy()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var ms = new MockStorage(MockBehavior.Strict);
                PProcess.StartStringString().BodyBy(ms).Expect(_ => _("file name", "arguments")).Returns(Process.GetCurrentProcess());

                // Act
                var proc = Process.Start("file name", "arguments");

                // Assert
                Assert.AreEqual(Process.GetCurrentProcess().Id, proc.Id);
                ms.Verify();
            }
        }
        public void AutoConfiguredMoqPrigCustomization_can_create_auto_mocked_instance_prig_type()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var ms      = new MockStorage(MockBehavior.Strict);
                var fixture = new Fixture().Customize(new AutoConfiguredMoqPrigCustomization(ms));

                var curProc = fixture.Create <PProxyProcess>();
                PProcess.GetCurrentProcess().Body = () => curProc;


                // Act
                var result = Process.GetCurrentProcess().StartInfo.FileName;


                // Assert
                Assert.That(result, Is.StringMatching(AutoStringPattern));
            }
        }
Esempio n. 6
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. 7
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();
            }
        }
 bool comparison(PProcess a, PProcess b)
 {
     return(a.ProcessPriority > b.ProcessPriority);
 }
Esempio n. 9
0
        /// <summary>
        /// Adds a new method to run for all packets of the given identifier
        /// </summary>
        /// <param name="id">Identifier byte</param>
        /// <param name="method">Method to add to the list of callables</param>
        public static void Put(byte id, PProcess method)
        {
            __CheckDelegateExist(id);

            __ID_PROCESSERS[id] += method;
        }
Esempio n. 10
0
        /// <summary>
        /// Adds a new method to run for all packets of the given identifier AND specifier
        /// </summary>
        /// <param name="id">Identifier byte</param>
        /// <param name="specifier">Specifier byte</param>
        /// <param name="method">Method to add to the list of callables</param>
        public static void Put(byte id, byte specifier, PProcess method)
        {
            __CheckDelegateExist(id, specifier);

            __SPEC_PROCESSERS[id][specifier] += method;
        }
Esempio n. 11
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);
 }