public void WhenNotConnected_ThenTryActivateReturnsFalse()
        {
            var sampleLocator = new InstanceLocator("project", "zone", "instance");
            var broker        = new SshTerminalSessionBroker(this.serviceProvider);

            Assert.IsFalse(broker.TryActivate(sampleLocator));
        }
        public void WhenNotConnected_ThenTryActivateReturnsFals()
        {
            var broker = new SshTerminalSessionBroker(this.serviceProvider);

            Assert.IsFalse(broker.IsConnected(SampleLocator));
            Assert.IsFalse(broker.TryActivate(SampleLocator));
        }
        public async Task WhenConnected_ThenTryActivateReturnsTrue(
            [LinuxInstance] ResourceTask <InstanceLocator> testInstance,
            [Credential(Role = PredefinedRole.ComputeInstanceAdminV1)] ResourceTask <ICredential> credential)
        {
            var locator = await testInstance;

            using (var key = new RsaSshKey(new RSACng()))
                using (var gceAdapter = new ComputeEngineAdapter(
                           this.serviceProvider.GetService <IAuthorizationAdapter>()))
                    using (var keyAdapter = new AuthorizedKeyService(
                               this.serviceProvider.GetService <IAuthorizationAdapter>(),
                               new ComputeEngineAdapter(await credential),
                               new ResourceManagerAdapter(await credential),
                               new Mock <IOsLoginService>().Object))
                    {
                        var authorizedKey = await keyAdapter.AuthorizeKeyAsync(
                            locator,
                            key,
                            TimeSpan.FromMinutes(10),
                            null,
                            AuthorizeKeyMethods.InstanceMetadata,
                            CancellationToken.None)
                                            .ConfigureAwait(true);

                        var instance = await gceAdapter.GetInstanceAsync(
                            locator,
                            CancellationToken.None)
                                       .ConfigureAwait(true);

                        // Connect
                        var broker = new SshTerminalSessionBroker(this.serviceProvider);

                        ISshTerminalSession session = null;
                        await AssertRaisesEventAsync <SessionStartedEvent>(
                            async() => session = await broker.ConnectAsync(
                                locator,
                                new IPEndPoint(instance.PublicAddress(), 22),
                                authorizedKey,
                                null,
                                TimeSpan.FromSeconds(10)));

                        Assert.IsNull(this.ExceptionShown);

                        Assert.AreSame(session, SshTerminalPane.TryGetActivePane(this.mainForm));
                        Assert.AreSame(session, SshTerminalPane.TryGetExistingPane(this.mainForm, locator));
                        Assert.IsTrue(broker.IsConnected(locator));
                        Assert.IsTrue(broker.TryActivate(locator));

                        AssertRaisesEvent <SessionEndedEvent>(
                            () => session.Close());
                    }
        }