void when_the_hook_is_called()
        {
            before = () =>
            {
                _notifier = new ReflectionDetourNotifier(HookFactory, _subject.Managed);
                _notifier.Hook.Apply();
            };

            act = () => _result = _subject.Managed(2.0);

            context["and the return value is modified in an event handler"] = () =>
            {
                before = () => _notifier.DetourCalled += (s, e) => e.ReturnValue = ExpectedValue;

                it["should return the modified value"] = () => _result.should_be(ExpectedValue);
                it["should call the original"]         = () => _subject.WasManagedCalled.should_be_true();
            };

            context["and the original shall not be called"] = () =>
            {
                before = () => _notifier.DetourCalled += (s, e) =>
                {
                    e.CallOriginal = false;
                    e.ReturnValue  = ExpectedValue;
                };

                it["should not call the original"] = () => _subject.WasManagedCalled.should_be_false();
            };

            after = () => _notifier.Dispose();
        }
Esempio n. 2
0
        void when_the_hooked_function_is_called()
        {
            act = () => _result = _subject.Managed(2.0);

            context["and the hook was applied"] = () =>
            {
                before = () =>
                {
                    _hook.Apply();
                    GC.Collect();
                };

                it["should call the hook function"] = () => _result.should_be(1);
                it["should be applied"]             = () => _hook.IsApplied.should_be_true();

                context["and then removed again"] = () =>
                {
                    before = () => _hook.Remove();

                    it["should call the original function"] = () => _result.should_be(2);
                    it["should not be applied"]             = () => _hook.IsApplied.should_be_false();
                };
            };

            after = () => _hook.Dispose();
        }