Example #1
0
        public static void replace_callback()
        {
            setup();

            test.ITesting obj = new test.Testing();
            obj.SetCallback(twice);
            Test.Assert(called == false, "set_callback should not call the callback");

            int x = obj.CallCallback(42);

            Test.Assert(called, "call_callback must call a callback");
            Test.AssertEquals(42 * 2, x);

            bool new_called = false;

            obj.SetCallback(y => {
                new_called = true;
                return(y * y);
            });

            Test.Assert(new_called == false, "set_callback should not call the callback");

            x = obj.CallCallback(42);
            Test.Assert(new_called, "call_callback must call a callback");
            Test.AssertEquals(42 * 42, x);
        }
Example #2
0
        public static void set_callback_basic()
        {
            setup();
            test.ITesting obj = new test.Testing();
            obj.SetCallback(twice);

            Test.Assert(called == false, "set_callback should not call the callback");

            int x = obj.CallCallback(42);

            Test.Assert(called, "call_callback must call a callback");
            Test.AssertEquals(42 * 2, x);
        }
Example #3
0
        public static void set_callback_with_lambda()
        {
            setup();

            test.ITesting obj = new test.Testing();
            obj.SetCallback(y => {
                called = true;
                return(y + 4);
            });

            Test.Assert(called == false, "set_callback should not call the callback");

            int x = obj.CallCallback(37);

            Test.Assert(called, "call_callback must call a callback");
            Test.AssertEquals(37 + 4, x);
        }