Exemplo n.º 1
0
        public void Should_handle_input_of_1024_chars()
        {
            var sut   = new ConsoleTextWriter();
            var input = new string('x', 1024);

            sut.WriteLine(input);
        }
        public void ParseGlobalJson()
        {
            var textWriter  = new ConsoleTextWriter();
            var tool        = new GlobalJsonFileLocator(textWriter);
            var parseResult = tool.Parse();

            (parseResult?.GlobalJsonFile.Sdk?.Version ?? throw new ArgumentNullException()).ShouldBe("2.2.100");
        }
        public void AcquireSdk()
        {
            using var sw = new StringWriter();
            Console.SetOut(sw);

            var textWriter         = new ConsoleTextWriter();
            var installerLauncher  = new TestInstallerLauncher();
            var platformIdentifier = new TestPlatformIdentifier();
            var dotnetInfo         = new TestDotnetInfo();

            var options = new HttpClientInterceptorOptions();

            _ = new HttpRequestInterceptionBuilder()
                .Requests()
                .ForHttps()
                .ForGet()
                .ForHost("raw.githubusercontent.com")
                .ForPath("/dotnet/core/master/release-notes/releases-index.json")
                .Responds()
                .WithContentStream(() => File.OpenRead("./TestReleaseData/releases-index.json"))
                .RegisterWith(options);

            _ = new HttpRequestInterceptionBuilder()
                .Requests()
                .ForHttps()
                .ForHost("dotnetcli.blob.core.windows.net")
                .ForGet()
                .ForPath("/dotnet/release-metadata/2.2/releases.json")
                .Responds()
                .WithContentStream(() => File.OpenRead("./TestReleaseData/2.2-releases.json"))
                .RegisterWith(options);

            _ = new HttpRequestInterceptionBuilder()
                .Requests()
                .ForHttps()
                .ForHost("download.visualstudio.microsoft.com")
                .ForGet()
                .ForPath("/download/pr/29457b8f-6262-4c4b-8a54-eef308346842/3c7ec575796a2ef0e826a07ca4d13084/dotnet-sdk-2.2.100-osx-x64.pkg")
                .Responds()
                .WithContentStream(() => new MemoryStream(Encoding.UTF8.GetBytes("install me")))
                .RegisterWith(options);

            using var httpClient = options.ThrowsOnMissingRegistration().CreateHttpClient();

            var a = new GlobalJsonVersion(textWriter);

            new SdkAcquirer(httpClient, textWriter, installerLauncher, platformIdentifier, dotnetInfo)
            .Acquire(a).Wait();

            var installerPath = installerLauncher.LastLaunchedInstaller;

            installerPath.ShouldNotBeNullOrEmpty();
            File.ReadAllLines(installerPath).ShouldHaveSingleItem().ShouldBe("install me");
        }
Exemplo n.º 4
0
 public ConsoleControl()
 {
     InitializeComponent();
     _tokenSource   = new CancellationTokenSource();
     _input         = new LockedQueue <string>(-1, _tokenSource.Token);
     _error         = new ConsoleTextWriter(this, true);
     _output        = new ConsoleTextWriter(this, false);
     _console       = new ConsoleImpl(this, _input);
     _history       = new List <string>();
     this.Disposed += ConsoleControl_Disposed;
     _consoleThread = new Thread(consoleThread_DoWork);
 }
Exemplo n.º 5
0
 public ConsoleControl()
 {
     InitializeComponent();
     _tokenSource = new CancellationTokenSource();
     _input = new LockedQueue<string>(-1, _tokenSource.Token);
     _error = new ConsoleTextWriter(this, true);
     _output = new ConsoleTextWriter(this, false);
     _console = new ConsoleImpl(this, _input);
     _history = new List<string>();
     this.Disposed += ConsoleControl_Disposed;
     _consoleThread = new Thread(consoleThread_DoWork);
 }
Exemplo n.º 6
0
        public void TestImplicit()
        {
            var consoleText = new ConsoleText();

            consoleText.Append(ConsoleStyle.Red, true);
            consoleText.Append("a");
            consoleText.Append(ConsoleStyle.Rgb(10, 20, 30).ToString());
            consoleText.Append("b");
            consoleText.Append(ConsoleStyle.Reset.ToString());
            consoleText.Append("c");


            var output = new StringWriter();
            var writer = new ConsoleTextWriter(output);

            consoleText.Render(writer);
            writer.Commit();

            Assert.AreEqual("\x1b[0m\x1b[31ma\x1b[0m\x1b[38;2;10;20;30mb\x1b[0m\x1b[31mc", output.ToString());
        }
Exemplo n.º 7
0
        /// <summary>
        /// SOLID:
        ///  Falhas:
        ///  - Apenas escreve no ecrã. E se quisermos escrever num ficheiro?
        ///  - Apenas escreve "Olá MUndo"...e se quisermos escrever outras coisa?
        ///  - E se quisermos a acrescentar mais "features"?
        ///  - ????
        /// </summary>
        static void Main1()
        {
            //1
            //Console.WriteLine("Ola Mundo");
            //2
            IGetMessage mensagem = new ConsoleGetMessage();
            ITextWriter writer   = new ConsoleTextWriter();


            //auxiliar
            PrepareMessage msg = new PrepareMessage(mensagem, writer);

            msg.Go();

            ITextWriter    writer2 = new FileTextWriter();
            PrepareMessage msg2    = new PrepareMessage(mensagem, writer2);

            msg2.Go();

            Console.ReadKey();
        }
Exemplo n.º 8
0
        internal void Start(bool makeChildOfCurrentSIP)
        {
            // TODO: Nothing here is synchronized!!! Need C# lock construct!!!
            if (_state != SIPState.NotStarted)
            {
                throw new NotSupportedException("SIP already started");
            }

            SIPManager.RegisterSIP(this);

            // the init process has no parent
            if (!makeChildOfCurrentSIP)
            {
                CurrentSIP.AddChild(this);
            }

            // setup input/output/error
            if (Output == null)
            {
                Output = new ConsoleTextWriter();
            }
            if (Error == null)
            {
                Error = new ConsoleTextWriter();
            }

            ResourceManager.RegisterSIP(this);
            _startThread.Start();
            _state = SIPState.Running;
        }
Exemplo n.º 9
0
        public void Should_handle_null_values()
        {
            var sut = new ConsoleTextWriter();

            sut.WriteLine(null);
        }
Exemplo n.º 10
0
 public override void Write(char value)
 {
     FileTextWriter.Write(value);
     FileTextWriter.Flush();
     ConsoleTextWriter.Write(value);
 }
Exemplo n.º 11
0
 public override void WriteLine(char[] buffer, int index, int count)
 {
     FileTextWriter.WriteLine(buffer, index, count);
     FileTextWriter.Flush();
     ConsoleTextWriter.WriteLine(buffer, index, count);
 }