Exemplo n.º 1
0
        public void When_I_override_a_global_function_manually()
        {
            // Arrange.
            scriptEngine.AddCode(
                @"Public Function Add(a, b)
                 Err.Raise 1
              End Function");

            FunctionOverrider overrider = new FunctionOverrider();

            Func <object[], object> addAction = (args) => (int)args[0] + (int)args[1];

            overrider.WhenCalled(addAction);

            // Act.
            scriptEngine.AddObject("Add", overrider);
            int result = script.Add(5, 7);

            // Assert.
            result.Should().Be(12);
        }
Exemplo n.º 2
0
        public void When_I_override_a_global_method_manually()
        {
            // Arrange.
            const string ExpectedText = "Echo from C#";
            string       actualText   = null;

            scriptEngine.AddCode(
                @"Public Sub Echo(sText)
                 ' Does nothing
              End Sub");

            FunctionOverrider overrider = new FunctionOverrider();

            Action <object[]> echoAction = (args) => actualText = args[0].ToString();

            overrider.WhenCalled(echoAction);

            // Act.
            scriptEngine.AddObject("Echo", overrider);
            script.Echo(ExpectedText);

            // Assert.
            actualText.Should().BeEquivalentTo(ExpectedText);
        }