public async Task SerializedResultInvokedAsyncMethodResult() { var eventCount = 0; object serializedResult = null; var proxy = new PerInstanceAdapter <IForTestingPurposes> ( Process.Lean(EventProcessor), 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)]; } }
public async Task MultipleCachedAsyncInvocationsYieldsSingleInstanceInvocation() { var instance = new ForTestingPurposes(); var proxy = new PerInstanceAdapter <IForTestingPurposes>(For.Ever()) .Adapt(instance); // ReSharper disable once NotAccessedVariable var result = await proxy.AsyncMethodCall(0, "zero"); Thread.Sleep(2000); // ReSharper disable once RedundantAssignment result = await proxy.AsyncMethodCall(0, "zero"); Assert.Equal <uint>(1, instance.AsyncMethodCallInvocationCount); }
public async Task ExpiredResultYieldsMultipleActualInvocations() { var instance = new ForTestingPurposes(); var proxy = new PerInstanceAdapter <IForTestingPurposes>(For.Milliseconds(0)) .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); }