Esempio n. 1
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); });
        }