示例#1
0
        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'");
        }
示例#2
0
        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());
        }
示例#3
0
        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");
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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());
        }
示例#7
0
        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());
        }
示例#8
0
            public bool RunRewardTraining()
            {
                TestCalculator calc = new TestCalculator(this.MockDB.Object);

                return(calc.Test_RewardTraining(Member, Courses, myAwards, TrainingRule, Completed, Expiry, NewString));
            }
示例#9
0
 // ReSharper disable once UnusedParameter.Global
 public string GetFor(TestCalculator input)
 {
     return "OK";
 }
示例#10
0
 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());
 }