Пример #1
0
        public void ClassProxyTargetOnlyVirtualMethodsAreCached()
        {
            var instance = new ForTestingPurposes();

            var proxy = new PerMethodAdapter <ForTestingPurposes>()
                        .Cache(x => x.MethodCall(It.IsAny <int>(), "zero"), For.Ever())
                        .Cache(x => x.VirtualMethodCall(It.IsAny <int>(), "zero"), For.Ever())
                        .Adapt(instance);

            proxy.MethodCall(0, "zero");
            proxy.MethodCall(0, "zero");
            proxy.VirtualMethodCall(0, "zero");
            proxy.VirtualMethodCall(0, "zero");

            Assert.Equal <uint>(2, proxy.MethodCallInvocationCount);
            Assert.Equal <uint>(1, instance.VirtualMethodCallInvocationCount);
            Assert.Equal <uint>(0, instance.MethodCallInvocationCount);
        }
Пример #2
0
        public void DefaultOptionsYieldExpectedDictionarySize()
        {
            var eventCount = 0;
            var itemCount  = 0;

            var proxy = new PerMethodAdapter <ForTestingPurposes>
                        (
                Process.Lean(EventProcessor)
                        )
                        .Profile(x => x.VirtualMethodCall(It.IsAny <int>(), It.IsAny <string>()))
                        .Adapt(new ForTestingPurposes());

            proxy.VirtualMethodCall(0, "zero");

            Assert.Equal(1, eventCount);
            Assert.Equal(BitFunctions.CountSet((int)CaptureOptions.Default), itemCount);

            void EventProcessor(IDictionary <string, object> @event)
            {
                eventCount++;
                itemCount = @event.Count;
            }
        }