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); }
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); }
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); }
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); }
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); }
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); } }
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); }
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); }