コード例 #1
0
        public async Task InitializeAsync()
        {
            var initializationFileName = UseDefaultInitializationFile ? "CSharpInteractive.rsp" : null;

            await Host.ResetAsync(InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName, CultureInfo.InvariantCulture, DefaultPlatform));

            // assert and remove logo:
            var output      = SplitLines(await ReadOutputToEnd());
            var errorOutput = await ReadErrorOutputToEnd();

            AssertEx.AssertEqualToleratingWhitespaceDifferences("", errorOutput);

            var expectedOutput = new List <string>();

            expectedOutput.Add(string.Format(CSharpScriptingResources.LogoLine1, CommonCompiler.GetProductVersion(typeof(CSharpReplServiceProvider))));

            if (UseDefaultInitializationFile)
            {
                expectedOutput.Add(string.Format(InteractiveHostResources.Loading_context_from_0, initializationFileName));
            }

            expectedOutput.Add(InteractiveHostResources.Type_Sharphelp_for_more_information);

            AssertEx.Equal(expectedOutput, output);

            // remove logo:
            ClearOutput();
        }
コード例 #2
0
        private async Task TestKillAfterAsync(int milliseconds)
        {
            using var host = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: 1, joinOutputWritingThreadsOnDisposal: true);
            var options = InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Desktop64);

            host.InteractiveHostProcessCreated += new Action <Process>(proc =>
            {
                _ = Task.Run(async() =>
                {
                    await Task.Delay(milliseconds).ConfigureAwait(false);

                    try
                    {
                        proc.Kill();
                    }
                    catch
                    {
                    }
                });
            });

            await host.ResetAsync(options).ConfigureAwait(false);

            for (int j = 0; j < 10; j++)
            {
                await host.ExecuteAsync("1+1").ConfigureAwait(false);
            }
        }
コード例 #3
0
        public async Task Bitness()
        {
            await Host.ExecuteAsync(@"System.IntPtr.Size");

            AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd());
            AssertEx.AssertEqualToleratingWhitespaceDifferences("8\r\n", await ReadOutputToEnd());

            await Host.ResetAsync(InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Desktop32));

            AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd());
            AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadOutputToEnd());

            await Host.ExecuteAsync(@"System.IntPtr.Size");

            AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd());
            AssertEx.AssertEqualToleratingWhitespaceDifferences("4\r\n", await ReadOutputToEnd());

            var result = await Host.ResetAsync(InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Core));

            AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd());
            AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadOutputToEnd());

            await Host.ExecuteAsync(@"System.IntPtr.Size");

            AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd());
            AssertEx.AssertEqualToleratingWhitespaceDifferences("8\r\n", await ReadOutputToEnd());
        }
コード例 #4
0
        public async Task RestartHost()
        {
            ClearOutput();

            await Host.ResetAsync(
                InteractiveHostOptions.CreateFromDirectory(
                    TestUtils.HostRootPath,
                    initializationFileName: null,
                    CultureInfo.InvariantCulture,
                    InteractiveHostPlatform.Desktop64
                    )
                );
        }