Esempio n. 1
0
        public void verifica_se_ReadLine_com_isSensitive_está_movimentando_o_cursor_corretamente(
            int posiçãoInicialCursorTop, int posiçãoInicialCursorLeft, string texto)
        {
            // Arrange, Given

            var console      = new SimulationForIConsole(texto) as IConsole;
            var inputConsole = new InputConsole(console);

            console.CursorTop  = posiçãoInicialCursorTop;
            console.CursorLeft = posiçãoInicialCursorLeft;

            // Act, When

            inputConsole.ReadLine(true);

            // Assert, Then

            var esperadoParaCursorTop = posiçãoInicialCursorTop + 1 + texto.Length / console.BufferWidth;

            if (esperadoParaCursorTop > console.BufferHeight)
            {
                esperadoParaCursorTop = console.BufferHeight - 1;
            }

            console.CursorTop.Should().Be(esperadoParaCursorTop);
            console.CursorLeft.Should().Be(0);
        }
        public void fazer_teste_de_cobertura_chegar_a_100_porcento()
        {
            // Arrange, Given

            var console = new SimulationForIConsole(string.Empty) as IConsole;

            // Act, When

            Action definirValorForaDoRangeParaCursorTop  = () => console.CursorTop = -1;
            Action definirValorForaDoRangeParaCursorLeft = () => console.CursorLeft = -1;

            // Assert, Then

            definirValorForaDoRangeParaCursorTop.Should().ThrowExactly <ArgumentOutOfRangeException>();
            definirValorForaDoRangeParaCursorLeft.Should().ThrowExactly <ArgumentOutOfRangeException>();
        }
Esempio n. 3
0
        public void ao_final_de_ReadLine_deve_escrever_o_texto_e_avançar_uma_linha(bool isSensitive)
        {
            // Arrange, Given

            var texto         = this.Fixture <string>();
            var console       = new SimulationForIConsole(texto);
            var inputConsole  = new InputConsole(console);
            var textoEsperado = !isSensitive ? texto : new string('*', texto.Length);

            // Act, When

            inputConsole.ReadLine(isSensitive);

            // Assert, Then

            console.OQueFoiEscrito.Should().Be(textoEsperado + Environment.NewLine);
        }
Esempio n. 4
0
        public void verifica_se_Read_está_posicionamento_o_cursor_na_posição_inicial_e_apagando_o_texto_digitado(
            bool isSensitive, int posiçãoInicialCursorTop, int posiçãoInicialCursorLeft, string texto)
        {
            // Arrange, Given

            var console      = new SimulationForIConsole(texto);
            var inputConsole = new InputConsole(console);
            var cursorTop    = console.CursorTop = posiçãoInicialCursorTop;
            var cursorLeft   = console.CursorLeft = posiçãoInicialCursorLeft;

            // Act, When

            inputConsole.Read(isSensitive);

            // Assert, Then

            console.CursorTop.Should().Be(cursorTop);
            console.CursorLeft.Should().Be(cursorLeft);
        }
Esempio n. 5
0
        public void confere_posicionamento_do_cursor_ao_usar_backspace_com_ReadLine_isSensitive(string texto,
                                                                                                int posiçãoEsperadaAntesDoEnterDeCursorTop, int posiçãoEsperadaAntesDoEnterDeCursorLeft)
        {
            // Arrange, Given

            var console      = new SimulationForIConsole(texto);
            var inputConsole = new InputConsole(console);

            const int posiçãoInicialDeCursorTop = 10;

            console.CursorTop = posiçãoInicialDeCursorTop;

            string TextoComBackspaceProcessado()
            {
                var resultado = new StringBuilder();

                foreach (var ch in texto)
                {
                    if (ch != '\b')
                    {
                        resultado.Append(ch);
                    }
                    else if (resultado.Length > 0)
                    {
                        resultado.Remove(resultado.Length - 1, 1);
                    }
                }

                return(resultado.ToString());
            }

            var textoComBackspaceProcessado = TextoComBackspaceProcessado();

            // Act, When

            inputConsole.ReadLine(true);

            // Assert, Then

            var historicoCursorTop  = console.Historico["CursorTop"];
            var historicoCursorLeft = console.Historico["CursorLeft"];

            historicoCursorTop[^ 2].Should().Be(posiçãoInicialDeCursorTop + posiçãoEsperadaAntesDoEnterDeCursorTop);