public async Task PtyMessageHandler_Handle_OpenNewCreatesANewTerminalWithTheGivenCommand()
        {
            // Given
            var terminal = new Terminal
            {
                Id      = Guid.NewGuid().ToString(),
                Command = "hello",
            };

            MockConfig.SetupGet(c => c["Command"]).Returns("hello");

            var mockProcess = new Mock <IProcess>();
            var process     = mockProcess.Object;

            mockProcess.SetupGet(p => p.IsRunning).Returns(true);

            MockEngine
            .Setup(e => e.StartNew("hello", It.IsAny <IReadOnlyList <string> >())).Returns(terminal);

            MockEngine
            .Setup(e => e.TryGetProcess(terminal, out process)).Returns(true);

            // When
            var request = new OpenNewTabRequest();
            var handler = new PtyMessageHandler(MockEngine.Object, MockConfig.Object, MockLogger.Object);
            var result  = await handler.Handle(request);

            // Then
            MockEngine.Verify(e => e.StartNew("hello", new List <string>()));
        }
        public async Task PtyMessageHandler_Handle_LogsAnErrorWhenTheProcessIsNotFound()
        {
            // Given
            var terminal = new Terminal
            {
                Id      = Guid.NewGuid().ToString(),
                Command = "bash",
            };
            var request     = new OpenNewTabRequest();
            var mockProcess = new Mock <IProcess>();
            var process     = mockProcess.Object;

            MockEngine
            .Setup(e => e.StartNew()).Returns(terminal);

            MockEngine
            .Setup(e => e.TryGetProcess(terminal, out process)).Returns(false);

            // When
            var handler = new PtyMessageHandler(MockEngine.Object, MockConfig.Object, MockLogger.Object);
            var result  = await handler.Handle(request);

            // Then
            MockLogger.Verify(l =>
                              l.LogError("Error ({messageName}): can't find terminal with id {terminalId}", nameof(ResizeTabRequest), terminal.Id));
        }
        public async Task PtyMessageHandler_Handle_OpenNewTabRequestReturnsOpenNewTabReplyOnSuccess()
        {
            // Given
            var terminal = new Terminal
            {
                Id      = Guid.NewGuid().ToString(),
                Command = "bash",
            };
            var request     = new OpenNewTabRequest();
            var mockProcess = new Mock <IProcess>();
            var process     = mockProcess.Object;

            mockProcess.SetupGet(p => p.IsRunning).Returns(true);

            MockEngine
            .Setup(e => e.StartNew()).Returns(terminal);

            MockEngine
            .Setup(e => e.TryGetProcess(terminal, out process)).Returns(true);

            // When
            var handler = new PtyMessageHandler(MockEngine.Object, MockConfig.Object, MockLogger.Object);
            var result  = await handler.Handle(request);

            // Then
            var reply = Assert.IsType <OpenNewTabReply>(result);

            Assert.Equal(terminal.Id, reply.Id);
        }
        public async Task PtyMessageHandler_Handle_ReturnsAnErrorMessageOnOpenNewTabRequestWhenProcessIsNotFound()
        {
            // Given
            var terminal = new Terminal
            {
                Id      = Guid.NewGuid().ToString(),
                Command = "bash",
            };
            var request     = new OpenNewTabRequest(id: "123", title: string.Empty);
            var mockProcess = new Mock <IProcess>();
            var process     = mockProcess.Object;

            MockEngine
            .Setup(e => e.StartNew()).Returns(terminal);

            MockEngine
            .Setup(e => e.TryGetProcess(terminal, out process)).Returns(false);

            // When
            var handler = new PtyMessageHandler(MockEngine.Object, MockConfig.Object, MockLogger.Object);
            var result  = await handler.Handle(request);

            // Then
            var error = Assert.IsType <ErrorReply>(result);

            Assert.NotNull(error.Id);
            Assert.Equal(request.Id, error.ParentId);
            Assert.Equal($"Can't find terminal with id {terminal.Id}.", error.Message);
        }
Exemplo n.º 5
0
        public async Task PtyEndpoint_Handles_OpenNewTabRequest()
        {
            // Given
            var mockEngine = _testHost.MockEngine;

            var terminal = new Terminal
            {
                Id      = Guid.NewGuid().ToString(),
                Command = "bash",
            };

            mockEngine
            .Setup(engine => engine.StartNew()).Returns(terminal);

            var mockProcess = new Mock <IProcess>();
            var process     = mockProcess.Object;

            mockProcess.SetupGet(p => p.IsRunning).Returns(true);

            mockEngine
            .Setup(engine => engine.TryGetProcess(terminal, out process))
            .Returns(true);

            // When
            using var cts = new CancellationTokenSource(timeOut);
            var request = new OpenNewTabRequest(id: "456", title: "title");
            await socket.SendBinaryMessageAsync(writer, request, cts.Token);

            var response = await socket.ReceiveMessageAsync(reader, cts.Token);

            // Then
            var newTab = Assert.IsType <OpenNewTabReply>(response);

            Assert.Equal(terminal.Id, newTab.Id);
            Assert.Equal(request.Id, newTab.ParentId);
            mockEngine.Verify(engine => engine.StartNew());
        }