コード例 #1
0
        public void Test5_1()
        {
            var jt           = _codeControl.JTF.RunAsync(() => TestHelper.DoInput1Async(this));
            var continueWith = jt.JoinAsync().ContinueWith(async t =>
            {
                if (_codeControl.IsFaulted)
                {
                    _f.OutputHelper.WriteLine("faulted");
                }
                await _codeControl.ShutdownAsync();

                _f.OutputHelper.WriteLine("shut down secondary");
                _codeControl.SecondaryDispatcher.InvokeShutdown();
                _f.OutputHelper.WriteLine("DONE");
            }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());

            while (!jt.IsCompleted)
            {
                TestHelper.DoEvents();
                Thread.Sleep(0);
            }

            _f.OutputHelper.WriteLine("end of test");
        }
コード例 #2
0
        public static void DoInput(UnitTest1 unitTest1, string input, bool checkResult = true)
        {
            var insertionPoint = 0;


            Func <RoslynCodeControl, string, TestContext, Task> a = async(rcc, inputChar, context) =>
            {
                InputRequest ir;
                ir = inputChar == "\r\n"
                    ? new InputRequest(InputRequestKind.NewLine)
                    : new InputRequest(InputRequestKind.TextInput, inputChar);

                var done = await rcc.DoUpdateTextAsync(insertionPoint, ir);

                if (checkResult)
                {
                    Assert.Equal(inputChar, done.InputRequest.Text);

                    Assert.Single(rcc.LineInfos2);
                    var il = rcc.InsertionLine;
                    Assert.Equal(il, rcc.LineInfos2.First.Value);
                    Assert.Equal(0, il.Offset);
                    Assert.Equal(context.Length + 3, il.Length);
                    Assert.Equal(0, il.LineNumber);
                    Assert.Equal(new Point(0, 0), il.Origin);
                    var ci = il.FirstCharInfo;
                }

                unitTest1.MyFixture.Debugfn(done.ToString());
            };

            var jt = unitTest1.JTF.RunAsync(async() =>
            {
                await unitTest1.CodeControl.UpdateFormattedTextAsync();
                var context = new TestContext();
                var lines   = input.Split("\r\n");
                foreach (var line in lines)
                {
                    unitTest1.MyFixture.Debugfn(line);
                    foreach (var ch in line)
                    {
                        await a(unitTest1.CodeControl, ch.ToString(), context);
                        context.Length++;
                    }

                    await a(unitTest1.CodeControl, "\r\n", context);
                    context.Length += 2;
                }
            });

            var continueWith = jt.JoinAsync().ContinueWith(unitTest1.ContinuationFunction);

            continueWith.ContinueWith(t =>
            {
                unitTest1.CodeControl.Shutdown();
                return(t.Result);
            });

            //, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());

            while (!continueWith.IsCompleted)
            {
                TestHelper.DoEvents();
                Thread.Sleep(500);
                unitTest1.MyFixture.Debugfn("loop");
            }


#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
            if (checkResult)
            {
                Assert.True(continueWith.Result);
            }
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits

            var s = unitTest1.CodeControl.CustomTextSource;
            if (!checkResult)
            {
                return;
            }
            Assert.Collection(s.Runs, run => { Assert.IsType <SyntaxTokenTextCharacters>(run); },
                              run => { Assert.IsType <CustomTextEndOfParagraph>(run); });
            Assert.Collection(s.RunInfos, runInfo => { Assert.IsType <SyntaxTokenTextCharacters>(runInfo.TextRun); });
        }