public void Perform_MustStartClient()
        {
            var result   = default(OperationResult);
            var response = new AuthenticationResponse {
                ProcessId = 1234
            };
            var communication = new CommunicationResult <AuthenticationResponse>(true, response);

            process.SetupGet(p => p.Id).Returns(response.ProcessId);
            processFactory.Setup(f => f.StartNew(It.IsAny <string>(), It.IsAny <string[]>())).Returns(process.Object).Callback(clientReady);
            proxy.Setup(p => p.RequestAuthentication()).Returns(communication);
            proxy.Setup(p => p.Connect(It.IsAny <Guid>(), true)).Returns(true);

            result = sut.Perform();

            Assert.AreEqual(process.Object, sessionContext.ClientProcess);
            Assert.AreEqual(proxy.Object, sessionContext.ClientProxy);
            Assert.AreEqual(OperationResult.Success, result);
        }
        public void Perform_MustFailStartupImmediatelyIfClientTerminates()
        {
            const int ONE_SECOND = 1000;

            var after           = default(DateTime);
            var before          = default(DateTime);
            var result          = default(OperationResult);
            var terminateClient = new Action(() => Task.Delay(100).ContinueWith(_ => process.Raise(p => p.Terminated += null, 0)));

            processFactory.Setup(f => f.StartNew(It.IsAny <string>(), It.IsAny <string[]>())).Returns(process.Object).Callback(terminateClient);
            sut = new ClientOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, ONE_SECOND);

            before = DateTime.Now;
            result = sut.Perform();
            after  = DateTime.Now;

            Assert.IsTrue(after - before < new TimeSpan(0, 0, ONE_SECOND));
            Assert.AreEqual(OperationResult.Failed, result);
        }