public void Cannot_Execute_internal_Method_from_external_object() { var calculator = new TestCalculator(); var engine = new Engine().SetValue("calculator", calculator); engine.Invoking(e => e.Execute(@" calculator.InternalAdd(1,2); ")).Should().Throw <JavaScriptException>().WithMessage("Object has no method 'InternalAdd'"); }
public void RewardTraining_CourseNotFound() { var tester = RewardTrainingTestData.Create(); tester.NewString = Guid.NewGuid().ToString(); TestCalculator calc = new TestCalculator(tester.MockDB.Object); Assert.Throws <InvalidOperationException>(() => tester.RunRewardTraining()); }
public void Cannot_Execute_internal_Method_from_external_object() { var calculator = new TestCalculator(); using var engine = new V8ScriptEngine(); engine.AddHostObject("calculator", calculator); engine.Invoking(e => e.Execute(@" calculator.InternalAdd(1,2); ")).Should().Throw <ScriptEngineException>().WithMessage("TypeError: calculator.InternalAdd is not a function"); }
public void Execute_Method_from_external_object_and_return_value_without_function() { var calculator = new TestCalculator(); using var engine = new V8ScriptEngine(); engine.AddHostObject("calculator", calculator); engine.Execute(@"var res = calculator.Add(1,2)"); int value = engine.Script.res; value.Should().Be(calculator.Add(1, 2)); }
public void Execute_Method_from_external_object_and_return_value_without_function() { var calculator = new TestCalculator(); var engine = new Engine().SetValue("calculator", calculator); engine.Execute(@" calculator.Add(1,2); "); var value = engine.GetCompletionValue(); value.ToObject().As <double>().Should().Be(calculator.Add(1, 2)); }
public void Execute_Method_from_external_object_and_return_value() { var calculator = new TestCalculator(); var engine = new Engine().SetValue("calculator", calculator); engine.Execute(@" function calc() { return calculator.Add(1,2); }; var result = calc(); "); var value = engine.GetValue("result"); value.ToObject().As <double>().Should().Be(calculator.Add(1, 2)); var a = JsValue.FromObject(engine, calculator); _output.WriteLine(a.ToString()); }
public void Execute_Method_from_external_object_and_return_value() { var calculator = new TestCalculator(); using var engine = new V8ScriptEngine(); engine.AddHostObject("calculator", calculator); engine.Execute(@" function calc() { return calculator.Add(1,2); }; var result = calc(); "); var value = (int)engine.Script.result; value.Should().Be(calculator.Add(1, 2)); _output.WriteLine(value.ToString()); }
public bool RunRewardTraining() { TestCalculator calc = new TestCalculator(this.MockDB.Object); return(calc.Test_RewardTraining(Member, Courses, myAwards, TrainingRule, Completed, Expiry, NewString)); }
// ReSharper disable once UnusedParameter.Global public string GetFor(TestCalculator input) { return "OK"; }
public void Should_get_the_correct_parameter_value_if_the_value_is_not_null() { var input = new TestCalculator(); var methodCallData = Reflection.GetMethodCallData((TestCalculator c) => c.GetFor(input)); methodCallData.ParameterValues.Count.ShouldBeEqualTo(1); methodCallData.ParameterValues.Values.First().ShouldBeEqualTo(input.ToString()); }