public void CreateEvaluateCommandWithVariableId() { // Arrange const int commandId = 3; var resultFactoryMock = new Mock<IEvaluationResultFactory>(); const int variableId = 2; // Act var evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, variableId); // Assert Assert.AreEqual(commandId, evaluateCommand.Id); Assert.AreEqual( string.Format( "{{\"command\":\"evaluate\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"expression\":\"variable.toString()\",\"frame\":0,\"global\":false,\"disable_break\":true,\"additional_context\":[{{\"name\":\"variable\",\"handle\":{1}}}],\"maxStringLength\":-1}}}}", commandId, variableId), evaluateCommand.ToString()); }
public void CreateEvaluateCommand() { // Arrange const int commandId = 3; var resultFactoryMock = new Mock<IEvaluationResultFactory>(); const string expression = "expression"; // Act var evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression); // Assert Assert.AreEqual(commandId, evaluateCommand.Id); Assert.AreEqual( string.Format( "{{\"command\":\"evaluate\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"expression\":\"{1}\",\"frame\":0,\"global\":false,\"disable_break\":true,\"maxStringLength\":-1}}}}", commandId, expression), evaluateCommand.ToString()); }
public void ProcessEvaluateResponse() { // Arrange const int commandId = 3; var resultFactoryMock = new Mock<IEvaluationResultFactory>(); resultFactoryMock.Setup(factory => factory.Create(It.IsAny<INodeVariable>())) .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null)); const string expression = "expression"; var stackFrame = new NodeStackFrame(0); var evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame); // Act evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponse()); // Assert Assert.AreEqual(commandId, evaluateCommand.Id); Assert.IsNotNull(evaluateCommand.Result); resultFactoryMock.Verify(factory => factory.Create(It.IsAny<INodeVariable>()), Times.Once); }
private void ReportException(ExceptionEvent exceptionEvent, string errorCode = null) { DebuggerClient.RunWithRequestExceptionsHandled(async () => { string exceptionName = exceptionEvent.ExceptionName; if (!string.IsNullOrEmpty(errorCode)) { exceptionName = string.Format("{0}({1})", exceptionName, errorCode); } // UNDONE Handle break on unhandled, once just my code is supported // Node has a catch all, so there are no uncaught exceptions // For now just break always or never //if (exceptionTreatment == ExceptionHitTreatment.BreakNever || // (exceptionTreatment == ExceptionHitTreatment.BreakOnUnhandled && !uncaught)) { ExceptionHitTreatment exceptionTreatment = _exceptionHandler.GetExceptionHitTreatment(exceptionName); if (exceptionTreatment == ExceptionHitTreatment.BreakNever) { await AutoResumeAsync(false).ConfigureAwait(false); return; } // We need to get the backtrace before we break, so we request the backtrace // and follow up with firing the appropriate event for the break bool running = await PerformBacktraceAsync().ConfigureAwait(false); Debug.Assert(!running); // Handle followup EventHandler<ExceptionRaisedEventArgs> exceptionRaised = ExceptionRaised; if (exceptionRaised == null) { return; } string description = exceptionEvent.Description; if (description.StartsWith("#<") && description.EndsWith(">")) { // Serialize exception object to get a proper description var tokenSource = new CancellationTokenSource(_timeout); var evaluateCommand = new EvaluateCommand(CommandId, _resultFactory, exceptionEvent.ExceptionId); if (await TrySendRequestAsync(evaluateCommand, tokenSource.Token).ConfigureAwait(false)) { description = evaluateCommand.Result.StringValue; } } var exception = new NodeException(exceptionName, description); exceptionRaised(this, new ExceptionRaisedEventArgs(MainThread, exception, exceptionEvent.Uncaught)); }); }
internal async Task<bool> TestPredicateAsync(string expression, CancellationToken cancellationToken = new CancellationToken()) { DebugWriteCommand("TestPredicate: " + expression); string predicateExpression = string.Format("Boolean({0})", expression); var evaluateCommand = new EvaluateCommand(CommandId, _resultFactory, predicateExpression); return await TrySendRequestAsync(evaluateCommand, cancellationToken).ConfigureAwait(false) && evaluateCommand.Result != null && evaluateCommand.Result.Type == NodeExpressionType.Boolean && evaluateCommand.Result.StringValue == "true"; }
internal async Task<NodeEvaluationResult> SetVariableValueAsync( NodeStackFrame stackFrame, string name, string value, CancellationToken cancellationToken = new CancellationToken()) { DebugWriteCommand("Set Variable Value"); // Create a new value var evaluateValueCommand = new EvaluateCommand(CommandId, _resultFactory, value, stackFrame); await _client.SendRequestAsync(evaluateValueCommand, cancellationToken).ConfigureAwait(false); int handle = evaluateValueCommand.Result.Handle; // Set variable value var setVariableValueCommand = new SetVariableValueCommand(CommandId, _resultFactory, stackFrame, name, handle); await _client.SendRequestAsync(setVariableValueCommand, cancellationToken).ConfigureAwait(false); return setVariableValueCommand.Result; }
internal async Task<NodeEvaluationResult> ExecuteTextAsync( NodeStackFrame stackFrame, string text, CancellationToken cancellationToken = new CancellationToken()) { DebugWriteCommand("Execute Text Async"); var evaluateCommand = new EvaluateCommand(CommandId, _resultFactory, text, stackFrame); await _client.SendRequestAsync(evaluateCommand, cancellationToken).ConfigureAwait(false); return evaluateCommand.Result; }
public void ProcessEvaluateResponseWithReferenceError() { // Arrange const int commandId = 3; var resultFactoryMock = new Mock<IEvaluationResultFactory>(); resultFactoryMock.Setup(factory => factory.Create(It.IsAny<INodeVariable>())); const string expression = "hello"; var stackFrame = new NodeStackFrame(0); var evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame); Exception exception = null; // Act try { evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponseWithReferenceError()); } catch (Exception e) { exception = e; } // Assert Assert.IsNotNull(exception); Assert.IsInstanceOfType(exception, typeof (DebuggerCommandException)); Assert.AreEqual("ReferenceError: hello is not defined", exception.Message); Assert.IsNull(evaluateCommand.Result); resultFactoryMock.Verify(factory => factory.Create(It.IsAny<INodeVariable>()), Times.Never); }