Пример #1
0
        public void MultipleNonCachedInvocationsYieldsMultipleInvocations()
        {
            var instance = new ForTestingPurposes();
            var proxy    = new PerMethodAdapter <IForTestingPurposes>().Adapt(instance);

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

            Assert.Equal <uint>(3, instance.MethodCallInvocationCount);
        }
Пример #2
0
        public void MultipleCachedInvocationsYieldsSingleActualInvocation()
        {
            var instance = new ForTestingPurposes();
            var proxy    = new PerMethodAdapter <IForTestingPurposes>()
                           .Cache(x => x.MethodCall(0, "zero"), For.Ever())
                           .Adapt(instance);

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

            Assert.Equal <uint>(1, instance.MethodCallInvocationCount);
        }
Пример #3
0
        public void ExpiredInvocationsYieldsMultipleInvocations()
        {
            var instance = new ForTestingPurposes();
            var proxy    = new PerMethodAdapter <IForTestingPurposes>()
                           .Cache(x => x.MethodCall(0, "zero"), While.Result.True <string>((result, dt) => false))
                           .Adapt(instance);

            proxy.MethodCall(0, "zero");
            proxy.MethodCall(0, "zero");
            proxy.MethodCall(1, "one");
            proxy.MethodCall(2, "two");

            Assert.Equal <uint>(4, instance.MethodCallInvocationCount);
        }
Пример #4
0
        public void MultipleCacheExpectationsYieldExpectedResult()
        {
            var instance = new ForTestingPurposes();
            var proxy    = new PerMethodAdapter <IForTestingPurposes>()
                           .Cache(x => x.MethodCall(It.IsAny <int>(), "zero"), For.Ever())
                           .Adapt(instance);

            proxy.MethodCall(0, "zero");
            var result0 = proxy.MethodCall(0, "zero");

            proxy.MethodCall(1, "zero");
            var result1 = proxy.MethodCall(1, "zero");

            Assert.Equal <uint>(2, instance.MethodCallInvocationCount);
            Assert.Equal("0zero", result0);
            Assert.Equal("1zero", result1);
        }
Пример #5
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);
        }
Пример #6
0
        public void NonProfiledMethodDoesNotProfile()
        {
            var eventCount = 0;

            var proxy = new PerMethodAdapter <IForTestingPurposes>
                        (
                Process.Lean(EventProcessor)
                        )
                        .Adapt(new ForTestingPurposes());

            proxy.MethodCall(0, "zero");

            Assert.Equal(0, eventCount);

            void EventProcessor(IDictionary <string, object> @event)
            {
                eventCount++;
            }
        }
Пример #7
0
        public void MixedFuzzyInvocationsYieldsMultipleInvocations()
        {
            var instance = new ForTestingPurposes();

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

            proxy.MethodCall(0, "zero");
            proxy.MethodCall(0, "zero");
            proxy.MethodCall(1, "zero");
            proxy.MethodCall(1, "zero");
            proxy.MethodCall(2, "zero");
            proxy.MethodCall(2, "zero");

            Assert.Equal <uint>(3, instance.MethodCallInvocationCount);
        }
Пример #8
0
        public void DeclaringTypeMatchesInvokedMethod()
        {
            var    eventCount = 0;
            object typeName   = null;

            var proxy = new PerMethodAdapter <IForTestingPurposes>
                        (
                Process.Lean(EventProcessor)
                        )
                        .Profile(x => x.MethodCall(0, "zero"), CaptureOptions.DeclaringTypeName)
                        .Adapt(new ForTestingPurposes());

            proxy.MethodCall(0, "zero");

            Assert.Equal(1, eventCount);
            Assert.Equal(typeof(ForTestingPurposes).FullName, typeName);

            void EventProcessor(IDictionary <string, object> @event)
            {
                eventCount++;
                typeName = @event[nameof(CaptureOptions.DeclaringTypeName)];
            }
        }
Пример #9
0
        public void SerializedResultMatchesFuzzyInvokedMethodResult()
        {
            var    eventCount       = 0;
            object serializedResult = null;

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

            var result = proxy.MethodCall(7, "eight");

            Assert.Equal(1, eventCount);
            Assert.Equal(result, JsonConvert.DeserializeObject((string)serializedResult));

            void EventProcessor(IDictionary <string, object> @event)
            {
                eventCount++;
                serializedResult = @event[nameof(CaptureOptions.SerializedResult)];
            }
        }