예제 #1
0
        public void TestInitialConnectionPromptsAfterEachWrite()
        {
            var connection = new FakeConnection()
            {
                AtNewLine = true
            };
            var session = new Session(connection);

            // Ensure we Begin the session state with some introductory output, followed by the registered prompt.
            Assert.AreEqual(connection.FakeMessagesSent.Count, 1);
            Assert.AreEqual(connection.FakeMessagesSent[0], $"Begin FakeSessionState!{AnsiSequences.NewLine}FakePrompt > ");

            // Ensure writing another string from the prompt cursor position, writes the new text to a new line and can add in the prompt too.
            connection.ResetMessages();
            connection.AtNewLine = false;
            session.Write(new OutputBuilder().AppendLine("test 1"), true);
            Assert.AreEqual(connection.FakeMessagesSent.Count, 1);
            Assert.AreEqual(connection.FakeMessagesSent[0], $"{AnsiSequences.NewLine}test 1{AnsiSequences.NewLine}FakePrompt > ");

            // Ensure writing another string from the prompt cursor position, writes the new text to a new line and can omit adding the prompt too.
            connection.ResetMessages();
            connection.AtNewLine = false;
            session.Write(new OutputBuilder().AppendLine("test 2"), false);
            Assert.AreEqual(connection.FakeMessagesSent.Count, 1);
            Assert.AreEqual(connection.FakeMessagesSent[0], $"{AnsiSequences.NewLine}test 2{AnsiSequences.NewLine}");

            // Ensure writing a string from a new line position already, does not append an extra opening line.
            connection.ResetMessages();
            connection.AtNewLine = true;
            session.Write(new OutputBuilder().Append("test 3"), false);
            Assert.AreEqual(connection.FakeMessagesSent.Count, 1);
            Assert.AreEqual(connection.FakeMessagesSent[0], $"test 3");
        }