示例#1
0
        public async Task BreakpointsSet_ConditionMultiple()
        {
            // In this tests, 2 of the breakpoints have their conditions satisfied
            // while 1 does not.
            int i = 10;

            using (var app = StartTestApp(debugEnabled: true, methodEvaluation: true))
            {
                var debuggee    = Polling.GetDebuggee(app.Module, app.Version);
                var breakpoint1 = SetBreakpointAndSleep(debuggee.Id, TestApplication.MainClass,
                                                        TestApplication.EchoBottomLine, $"testList[1] == \"List{i}1\"");
                var breakpoint2 = SetBreakpointAndSleep(debuggee.Id, TestApplication.MainClass,
                                                        TestApplication.EchoBottomLine, $"testList[1] == \"List{i}2\"");
                var breakpoint3 = SetBreakpointAndSleep(debuggee.Id, TestApplication.MainClass,
                                                        TestApplication.EchoBottomLine, $"testDictionary[Key{i}2] == 2");

                using (HttpClient client = new HttpClient())
                {
                    await client.GetAsync(TestApplication.GetEchoUrl(app, i));

                    Assert.Throws <TimeoutException>(() =>
                                                     Polling.GetBreakpoint(debuggee.Id, breakpoint2.Id));

                    var newBp1 = Polling.GetBreakpoint(debuggee.Id, breakpoint1.Id);
                    Assert.True(newBp1.IsFinalState);

                    var newBp3 = Polling.GetBreakpoint(debuggee.Id, breakpoint3.Id);
                    Assert.True(newBp3.IsFinalState);
                }
            }
        }
        /// <summary>
        /// Start the test application.
        /// </summary>
        /// <param name="debugEnabled">True if the debugger should be started with and attached
        ///     to the app</param>
        /// <param name="waitForStart">Optional. True if this method should block until the
        ///     application is started and can be queried.  Defaults to true.</param>
        /// <param name="methodEvaluation">Optional. True if method evaluation should be performed
        ///     when evaluating condition.  Defaults to false.</param>
        /// <returns>A test application.</returns>
        public TestApplication StartTestApp(bool debugEnabled, bool waitForStart = true,
                                            bool methodEvaluation = false)
        {
            var app = new TestApplication(debugEnabled, methodEvaluation);

            if (waitForStart)
            {
                using (HttpClient client = new HttpClient())
                {
                    // Allow the app a chance to start up as it may not start
                    // right away.  This generally takes less than 5 seconds
                    // but we give more time as sometimes it can take longer
                    // and is outside our control in most cases.
                    int attempts = 30;
                    for (int i = 0; i < attempts; i++)
                    {
                        try
                        {
                            client.GetAsync(app.AppUrlBase).Wait();
                            break;
                        }
                        catch (AggregateException) when(i < attempts - 1)
                        {
                            Thread.Sleep(TimeSpan.FromSeconds(1));
                        }
                    }
                }
            }
            return(app);
        }
示例#3
0
        public async Task BreakpointHit_IndexerAccessCondition()
        {
            int    i         = 10;
            string condition = $"testList[1] == \"List{i}1\"";

            using (var app = StartTestApp(debugEnabled: true))
            {
                Debuggee           debuggee   = Polling.GetDebuggee(app.Module, app.Version);
                DebuggerBreakpoint breakpoint = SetBreakpointAndSleep(
                    debuggee.Id, TestApplication.MainClass,
                    TestApplication.EchoBottomLine, condition);

                // Checks that the breakpoint has a condition.
                Assert.Equal(breakpoint.Condition, condition);

                using (HttpClient client = new HttpClient())
                {
                    await client.GetAsync(TestApplication.GetEchoUrl(app, i));
                }

                DebuggerBreakpoint newBp = Polling.GetBreakpoint(debuggee.Id, breakpoint.Id);

                // Check that the breakpoint has been hit.
                Assert.True(newBp.IsFinalState);
            }
        }
示例#4
0
        public async Task BreakpointHit_FunctionEvaluationFailure()
        {
            string condition = "NonExistentFunc() == \"Hello, World!\"";

            using (var app = StartTestApp(debugEnabled: true, methodEvaluation: true))
            {
                Debuggee           debuggee   = Polling.GetDebuggee(app.Module, app.Version);
                DebuggerBreakpoint breakpoint = SetBreakpointAndSleep(
                    debuggee.Id, TestApplication.MainClass,
                    TestApplication.LoopMiddle, condition);

                // Checks that the breakpoint has a condition.
                Assert.Equal(breakpoint.Condition, condition);

                using (HttpClient client = new HttpClient())
                {
                    await client.GetAsync(TestApplication.GetLoopUrl(app, 10));
                }

                DebuggerBreakpoint newBp = Polling.GetBreakpoint(debuggee.Id, breakpoint.Id);

                // Checks that the breakpoint has been hit.
                Assert.True(newBp.IsFinalState);
                // However, it should have error status set to true.
                Assert.True(newBp.Status.IsError);
                Assert.Empty(newBp.StackFrames);
            }
        }
示例#5
0
        public async Task BreakpointHit_FunctionEvaluationNotPerformedForExpression()
        {
            string[] expression = { "Hello()" };
            using (var app = StartTestApp(debugEnabled: true))
            {
                Debuggee           debuggee   = Polling.GetDebuggee(app.Module, app.Version);
                DebuggerBreakpoint breakpoint = SetBreakpointAndSleep(
                    debuggee.Id, TestApplication.MainClass,
                    TestApplication.LoopMiddle, null, expression);

                using (HttpClient client = new HttpClient())
                {
                    await client.GetAsync(TestApplication.GetLoopUrl(app, 10));
                }

                DebuggerBreakpoint newBp = Polling.GetBreakpoint(debuggee.Id, breakpoint.Id);

                // Checks that the breakpoint has been hit.
                Assert.True(newBp.IsFinalState);
                // However, it should have error status set to true.
                Assert.True(newBp.Status.IsError);
                Assert.Contains("Method call for condition or expression evaluation is disabled.", newBp.Status.Description.Format);
                Assert.Empty(newBp.StackFrames);
            }
        }
示例#6
0
        public async Task BreakpointHit_FunctionEvaluation()
        {
            string condition = "Hello() == \"Hello, World!\"";

            using (var app = StartTestApp(debugEnabled: true, methodEvaluation: true))
            {
                Debuggee           debuggee   = Polling.GetDebuggee(app.Module, app.Version);
                DebuggerBreakpoint breakpoint = SetBreakpointAndSleep(
                    debuggee.Id, TestApplication.MainClass,
                    TestApplication.LoopMiddle, condition);

                // Checks that the breakpoint has a condition.
                Assert.Equal(breakpoint.Condition, condition);

                using (HttpClient client = new HttpClient())
                {
                    await client.GetAsync(TestApplication.GetLoopUrl(app, 10));
                }

                DebuggerBreakpoint newBp = Polling.GetBreakpoint(debuggee.Id, breakpoint.Id);

                // Checks that the breakpoint has been hit.
                Assert.True(newBp.IsFinalState);
                // Checks that "i" is 0 when the breakpoint is hit.
                Debugger.V2.StackFrame firstFrame = newBp.StackFrames[0];
                DebuggerVariable       iVariable  = firstFrame.Locals.First(local => local.Name == "i");
                Assert.Equal("0", iVariable.Value);
            }
        }
示例#7
0
        public async Task BreakpointHit_MultipleExpressions()
        {
            string[] expressions = { "testList[3]", "testDictionary[\"Key103\"]" };
            using (var app = StartTestApp(debugEnabled: true, methodEvaluation: true))
            {
                Debuggee           debuggee   = Polling.GetDebuggee(app.Module, app.Version);
                DebuggerBreakpoint breakpoint = SetBreakpointAndSleep(
                    debuggee.Id, TestApplication.MainClass,
                    TestApplication.EchoBottomLine, null, expressions);

                // Checks that the breakpoint has evaluated expression.

                using (HttpClient client = new HttpClient())
                {
                    await client.GetAsync(TestApplication.GetEchoUrl(app, 10));
                }

                DebuggerBreakpoint newBp = Polling.GetBreakpoint(debuggee.Id, breakpoint.Id);

                // Checks that the breakpoint has been hit.
                Assert.True(newBp.IsFinalState);

                // Checks that the expressions have correct values.
                Assert.Equal(2, newBp.EvaluatedExpressions.Count);
                Assert.Equal(expressions[1], newBp.EvaluatedExpressions[0].Name);
                Assert.Equal("3", newBp.EvaluatedExpressions[0].Value);

                Assert.Equal(expressions[0], newBp.EvaluatedExpressions[1].Name);
                Assert.Equal("List103", newBp.EvaluatedExpressions[1].Value);
            }
        }
示例#8
0
        public async Task BreakpointHit_Comment()
        {
            using (var app = StartTestApp(debugEnabled: true))
            {
                Debuggee           debuggee   = Polling.GetDebuggee(app.Module, app.Version);
                DebuggerBreakpoint breakpoint = SetBreakpointAndSleep(
                    debuggee.Id, TestApplication.MainClass, TestApplication.LoopMiddleComment);

                using (HttpClient client = new HttpClient())
                {
                    await client.GetAsync(TestApplication.GetLoopUrl(app, 10));
                }

                DebuggerBreakpoint newBp = Polling.GetBreakpoint(debuggee.Id, breakpoint.Id);

                // Check that the breakpoint has been hit.
                Assert.True(newBp.IsFinalState);

                // Check that the breakpoint line is at the next line.
                Assert.Equal(TestApplication.LoopMiddle, newBp.Location.Line);
            }
        }
示例#9
0
        public async Task BreakpointHit_IndexerAccessConditionFailed()
        {
            int    i         = 10;
            string condition = $"testList[1] == \"List{i}2\"";

            using (var app = StartTestApp(debugEnabled: true, methodEvaluation: true))
            {
                Debuggee           debuggee   = Polling.GetDebuggee(app.Module, app.Version);
                DebuggerBreakpoint breakpoint = SetBreakpointAndSleep(
                    debuggee.Id, TestApplication.MainClass,
                    TestApplication.EchoBottomLine, condition);

                // Checks that the breakpoint has a condition.
                Assert.Equal(breakpoint.Condition, condition);

                using (HttpClient client = new HttpClient())
                {
                    await client.GetAsync(TestApplication.GetEchoUrl(app, i));
                }

                Assert.Throws <TimeoutException>(() =>
                                                 Polling.GetBreakpoint(debuggee.Id, breakpoint.Id));
            }
        }
 /// <summary>Get the loop url with 'i' appended.</summary>
 public static string GetLoopUrl(TestApplication app, int i) => $"{app.AppUrlLoop}/{i}";
 /// <summary>Get the echo url with 'i' appended.</summary>
 public static string GetEchoUrl(TestApplication app, int i) => $"{app.AppUrlEcho}/{i}";