public void DeclareVariableWithErrorRemoteValue()
        {
            RemoteValueFake remoteValue =
                RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue");

            remoteValue.AddValueFromExpression($"auto $test=5; $test",
                                               RemoteValueFakeUtil.CreateError("declaration error"));

            var natvisScope = new NatvisScope();

            natvisScope.AddScopedName("test", "$test");

            IVariableInformation varInfo = _varInfoFactory.Create(remoteValue);
            var exception = Assert.ThrowsAsync <ExpressionEvaluationFailed>(
                async() =>
                await _evaluator.DeclareVariableAsync(varInfo, "test", "5", natvisScope));

            Assert.That(exception.Message, Does.Contain("test"));
            Assert.That(exception.Message, Does.Contain("5"));
            Assert.That(exception.Message, Does.Contain("declaration error"));

            string logOutput = _nLogSpy.GetOutput();

            Assert.That(logOutput, Does.Contain("test"));
            Assert.That(logOutput, Does.Contain("5"));
            Assert.That(logOutput, Does.Contain("declaration error"));
        }
        public async Task CloneContextVariablesAsync(string expr, string transformedExpr,
                                                     string expectedValue)
        {
            RemoteValueFake remoteValue =
                RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue");
            RemoteValueFake exprResult = RemoteValueFakeUtil.CreateSimpleInt("x", 1);

            exprResult.SetClone(RemoteValueFakeUtil.CreateSimpleInt("y", 2));

            remoteValue.AddValueFromExpression(transformedExpr, exprResult);

            IVariableInformation varInfo = _varInfoFactory.Create(remoteValue);

            var natvisScope = new NatvisScope();

            natvisScope.AddScopedName("$i", "1U");
            natvisScope.AddScopedName("var", "$var_0");
            natvisScope.AddContextVariable("$var_0", exprResult);

            IVariableInformation result =
                await _evaluator.EvaluateExpressionAsync(expr, varInfo, natvisScope, "myVar");

            Assert.That(await result.ValueAsync(), Is.EqualTo(expectedValue));
            Assert.That(result.DisplayName, Is.EqualTo("myVar"));
        }
        public async Task LldbEvalWithContextVarsAsync()
        {
            _optionPageGrid.ExpressionEvaluationEngine =
                ExpressionEvaluationEngineFlag.LLDB_EVAL_WITH_FALLBACK;

            RemoteValue mockVariable = CreateMockVariable();

            var natvisScope = new NatvisScope();
            var contextVar  = RemoteValueFakeUtil.CreateSimpleInt("var", 14);

            natvisScope.AddScopedName("var", "$var_0");
            natvisScope.AddContextVariable("$var_0", contextVar);

            await _evaluator.EvaluateExpressionAsync(
                "2 + var", _varInfoFactory.Create(mockVariable), natvisScope, "result");

            await mockVariable.Received(1).EvaluateExpressionLldbEvalAsync(
                Arg.Is("2 + $var_0"), Arg.Is(natvisScope.ContextVariables));

            Assert.That(natvisScope.ContextVariables.Count, Is.EqualTo(1));
            Assert.That(natvisScope.ContextVariables.ContainsKey("$var_0"));
            Assert.That(natvisScope.ContextVariables["$var_0"], Is.EqualTo(contextVar));

            await mockVariable.DidNotReceive().EvaluateExpressionAsync(Arg.Any <string>());
        }
        public async Task UseLldbEvalAsync(ExpressionEvaluationEngineFlag engineFlag)
        {
            _optionPageGrid.ExpressionEvaluationEngine = engineFlag;

            RemoteValue mockVariable = CreateMockVariable();
            var         natvisScope  = new NatvisScope();

            await _evaluator.EvaluateExpressionAsync("2 + 2", _varInfoFactory.Create(mockVariable),
                                                     natvisScope, "result");

            await mockVariable.Received(1).EvaluateExpressionLldbEvalAsync(
                Arg.Is("2 + 2"), Arg.Is(natvisScope.ContextVariables));
        }
        public async Task IndexerAccessWithTokenReplacementAsync()
        {
            RemoteValueFake remoteValue =
                RemoteValueFakeUtil.CreateSimpleIntArray("myArray", 3, 4, 5, 6);

            var natvisScope = new NatvisScope();

            natvisScope.AddScopedName("$i", "2");

            IVariableInformation varInfo     = _varInfoFactory.Create(remoteValue);
            IVariableInformation exprVarInfo =
                await _evaluator.EvaluateExpressionAsync("[$i]", varInfo, natvisScope, null);

            Assert.That(exprVarInfo.DisplayName, Is.EqualTo("[2]"));
            Assert.That(await exprVarInfo.ValueAsync(), Is.EqualTo("5"));
        }
        public async Task UseLldbEvalWithConstantSubstituteTokensAsync()
        {
            _optionPageGrid.ExpressionEvaluationEngine = ExpressionEvaluationEngineFlag.LLDB_EVAL;

            RemoteValue mockVariable = CreateMockVariable();

            var natvisScope = new NatvisScope();

            natvisScope.AddScopedName("$T1", "int");
            natvisScope.AddScopedName("$i", "2U");

            await _evaluator.EvaluateExpressionAsync(
                "($T1)3.14 + $i", _varInfoFactory.Create(mockVariable), natvisScope, "result");

            await mockVariable.Received(1).EvaluateExpressionLldbEvalAsync(
                Arg.Is("(int)3.14 + 2U"), Arg.Is(natvisScope.ContextVariables));
        }
        public async Task DeclareVariableAsync()
        {
            RemoteValueFake remoteValue  = RemoteValueFakeUtil.CreateSimpleChar("testVar", 'c');
            RemoteValueFake createdValue = RemoteValueFakeUtil.CreateSimpleInt("$test", 22);

            remoteValue.AddValueFromExpression("auto $test=var1+var2; $test", createdValue);
            remoteValue.AddValueFromExpression("$test", createdValue);

            var natvisScope = new NatvisScope();

            natvisScope.AddScopedName("test", "$test");

            IVariableInformation varInfo = _varInfoFactory.Create(remoteValue);
            await _evaluator.DeclareVariableAsync(varInfo, "test", "var1+var2", natvisScope);

            Assert.That(natvisScope.ContextVariables, Does.ContainKey("$test"));
            Assert.That(natvisScope.ContextVariables["$test"], Is.EqualTo(createdValue));
        }
        public async Task ChangeLldbEvalFlagInRuntimeAsync()
        {
            _optionPageGrid.ExpressionEvaluationEngine = ExpressionEvaluationEngineFlag.LLDB;

            RemoteValue mockVariable = CreateMockVariable();
            var         natvisScope  = new NatvisScope();

            await _evaluator.EvaluateExpressionAsync("2 + 2", _varInfoFactory.Create(mockVariable),
                                                     natvisScope, "result");

            await mockVariable.DidNotReceiveWithAnyArgs().EvaluateExpressionLldbEvalAsync(
                Arg.Any <string>());

            await mockVariable.Received(1).EvaluateExpressionAsync(Arg.Is("2 + 2"));

            mockVariable.ClearReceivedCalls();

            // Change the configuration flag
            _optionPageGrid.ExpressionEvaluationEngine = ExpressionEvaluationEngineFlag.LLDB_EVAL;

            await _evaluator.EvaluateExpressionAsync("3 + 3", _varInfoFactory.Create(mockVariable),
                                                     natvisScope, "result");

            await mockVariable.Received(1).EvaluateExpressionLldbEvalAsync(
                Arg.Is("3 + 3"), Arg.Is(natvisScope.ContextVariables));

            mockVariable.ClearReceivedCalls();

            // Change the configuration flag back to LLDB
            _optionPageGrid.ExpressionEvaluationEngine = ExpressionEvaluationEngineFlag.LLDB;

            await _evaluator.EvaluateExpressionAsync("4 + 4", _varInfoFactory.Create(mockVariable),
                                                     natvisScope, "result");

            await mockVariable.DidNotReceiveWithAnyArgs().EvaluateExpressionLldbEvalAsync(
                Arg.Any <string>());

            await mockVariable.Received(1).EvaluateExpressionAsync(Arg.Is("4 + 4"));
        }
        public async Task LldbEvalWithFallbackAsync(LldbEvalErrorCode lldbEvalErrorCode)
        {
            _optionPageGrid.ExpressionEvaluationEngine =
                ExpressionEvaluationEngineFlag.LLDB_EVAL_WITH_FALLBACK;

            RemoteValue mockVariable = CreateMockVariable();
            RemoteValue errorValue   = RemoteValueFakeUtil.CreateLldbEvalError(lldbEvalErrorCode);
            var         natvisScope  = new NatvisScope();

            mockVariable
            .EvaluateExpressionLldbEvalAsync(Arg.Any <string>(),
                                             Arg.Any <IDictionary <string, RemoteValue> >())
            .Returns(errorValue);

            await _evaluator.EvaluateExpressionAsync("expr", _varInfoFactory.Create(mockVariable),
                                                     natvisScope, "result");

            await mockVariable.Received(1).EvaluateExpressionLldbEvalAsync(
                Arg.Is("expr"), Arg.Is(natvisScope.ContextVariables));

            mockVariable.DidNotReceiveWithAnyArgs().GetValueForExpressionPath(Arg.Any <string>());
            await mockVariable.Received(1).EvaluateExpressionAsync(Arg.Is("expr"));
        }