Пример #1
0
        public static void replace_callback()
        {
            setup();

            var obj = new Dummy.TestObject();

            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);
            obj.Dispose();
        }
Пример #2
0
        public static void set_callback_basic()
        {
            setup();
            var obj = new Dummy.TestObject();

            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);
        }
Пример #3
0
        public static void set_callback_with_lambda()
        {
            setup();

            var obj = new Dummy.TestObject();

            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);
        }