Esempio n. 1
0
        public async Task SerializedResultInvokedAsyncMethodResult()
        {
            var    eventCount       = 0;
            object serializedResult = null;

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

            var result = await proxy.AsyncMethodCall(1, "one");

            Thread.Sleep(1000);

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

            void EventProcessor(IDictionary <string, object> @event)
            {
                eventCount++;
                serializedResult = @event[nameof(CaptureOptions.SerializedResult)];
            }
        }
Esempio n. 2
0
        public async Task ExpiredResultYieldsMultipleActualInvocations()
        {
            var instance = new ForTestingPurposes();
            var proxy    = new PerMethodAdapter <IForTestingPurposes>()
                           .Cache(x => x.AsyncMethodCall(It.IsAny <int>(), "zero"), While.Result.True <string>((s, dt) => false))
                           .Adapt(instance);

            // ReSharper disable once NotAccessedVariable
            // ReSharper disable once RedundantAssignment
            await proxy.AsyncMethodCall(0, "zero");

            // I hate to have to do this, but otherwise the second
            // invocation may complete before the first invocation
            // is added to cache.
            Thread.Sleep(2000);

            await proxy.AsyncMethodCall(0, "zero");

            Assert.Equal <uint>(2, instance.AsyncMethodCallInvocationCount);
        }
Esempio n. 3
0
        public async Task MultipleCachedAsyncInvocationsYieldsSingleInstanceInvocation()
        {
            var instance = new ForTestingPurposes();
            var proxy    = new PerMethodAdapter <IForTestingPurposes>()
                           .Cache(x => x.AsyncMethodCall(It.IsAny <int>(), "zero"), For.Ever())
                           .Adapt(instance);

            // ReSharper disable once NotAccessedVariable
            // ReSharper disable once RedundantAssignment
            var result = await proxy.AsyncMethodCall(0, "zero");

            // I hate to have to do this, but otherwise the second
            // invocation may complete before the first invocation
            // is added to cache.
            Thread.Sleep(2000);

            result = await proxy.AsyncMethodCall(0, "zero");

            Assert.Equal <uint>(1, instance.AsyncMethodCallInvocationCount);
            Assert.Equal("0zero", result);
        }