コード例 #1
0
 public PortArgumentProcessorTests()
 {
     this.mockProcessHelper    = new Mock <IProcessHelper>();
     this.testDesignModeClient = new Mock <IDesignModeClient>();
     this.testRequestManager   = new Mock <ITestRequestManager>();
     this.executor             = new PortArgumentExecutor(CommandLineOptions.Instance, this.testRequestManager.Object);
 }
コード例 #2
0
        public void ExecutorExecuteSetsParentProcessIdOnDesignModeInitializer()
        {
            var parentProcessId = 2346;
            var parentProcessIdArgumentExecutor = new ParentProcessIdArgumentExecutor(CommandLineOptions.Instance);

            parentProcessIdArgumentExecutor.Initialize(parentProcessId.ToString());

            int actualParentProcessId = -1;

            this.executor = new PortArgumentExecutor(CommandLineOptions.Instance,
                                                     this.testRequestManager.Object,
                                                     (ppid, ph) =>
            {
                actualParentProcessId = ppid;
                return(testDesignModeClient.Object);
            },
                                                     this.mockProcessHelper.Object
                                                     );

            int port = 2345;

            this.executor.Initialize(port.ToString());
            var result = executor.Execute();

            testDesignModeClient.Verify(td =>
                                        td.ConnectToClientAndProcessRequests(port, testRequestManager.Object), Times.Once);

            Assert.AreEqual(parentProcessId, actualParentProcessId, "Parent process Id must be set correctly on design mode initializer");

            Assert.AreEqual(ArgumentProcessorResult.Success, result);
        }
コード例 #3
0
        public void ExecutorInitializeWithValidPortShouldAddPortToCommandLineOptionsAndInitializeDesignModeManger()
        {
            var executor = new PortArgumentExecutor(CommandLineOptions.Instance, TestRequestManager.Instance);
            int port     = 2345;

            executor.Initialize(port.ToString());
            Assert.AreEqual(port, CommandLineOptions.Instance.Port);
            Assert.IsNotNull(DesignModeClient.Instance);
        }
コード例 #4
0
        public void ExecutorInitializeShouldSetDesignMode()
        {
            var executor = new PortArgumentExecutor(CommandLineOptions.Instance, TestRequestManager.Instance);
            int port     = 2345;

            CommandLineOptions.Instance.ParentProcessId = 0;

            executor.Initialize(port.ToString());

            Assert.IsTrue(CommandLineOptions.Instance.IsDesignMode);
        }
コード例 #5
0
        public void ExecutorInitializeShouldSetProcessExitCallback()
        {
            this.executor = new PortArgumentExecutor(CommandLineOptions.Instance, this.testRequestManager.Object, this.mockProcessHelper.Object);
            int port      = 2345;
            int processId = Process.GetCurrentProcess().Id;

            CommandLineOptions.Instance.ParentProcessId = processId;

            this.executor.Initialize(port.ToString());

            this.mockProcessHelper.Verify(ph => ph.SetExitCallback(processId, It.IsAny <Action <object> >()), Times.Once);
        }
コード例 #6
0
        public void ExecutorInitializeWithInvalidPortShouldThrowCommandLineException()
        {
            var executor = new PortArgumentExecutor(CommandLineOptions.Instance, TestRequestManager.Instance);

            try
            {
                executor.Initialize("Foo");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is CommandLineException);
                Assert.AreEqual("The --Port|/Port argument requires the port number which is an integer. Specify the port for socket connection and receiving the event messages.", ex.Message);
            }
        }
コード例 #7
0
        public void ExecutorExecuteForFailedConnectionShouldThrowCommandLineException()
        {
            this.executor = new PortArgumentExecutor(CommandLineOptions.Instance, this.testRequestManager.Object,
                                                     (parentProcessId, ph) => testDesignModeClient.Object, this.mockProcessHelper.Object);

            testDesignModeClient.Setup(td => td.ConnectToClientAndProcessRequests(It.IsAny <int>(),
                                                                                  It.IsAny <ITestRequestManager>())).Callback(() => { throw new TimeoutException(); });

            int port = 2345;

            this.executor.Initialize(port.ToString());
            Assert.ThrowsException <CommandLineException>(() => executor.Execute());

            testDesignModeClient.Verify(td => td.ConnectToClientAndProcessRequests(port, this.testRequestManager.Object), Times.Once);
        }
コード例 #8
0
        public void ExecutorExecuteForValidConnectionReturnsArgumentProcessorResultSuccess()
        {
            this.executor = new PortArgumentExecutor(CommandLineOptions.Instance, this.testRequestManager.Object,
                                                     (parentProcessId, ph) => this.testDesignModeClient.Object, this.mockProcessHelper.Object);

            int port = 2345;

            this.executor.Initialize(port.ToString());
            var result = executor.Execute();

            this.testDesignModeClient.Verify(td =>
                                             td.ConnectToClientAndProcessRequests(port, this.testRequestManager.Object), Times.Once);

            Assert.AreEqual(ArgumentProcessorResult.Success, result);
        }