Пример #1
0
 public void Init()
 {
     _fakeSimpleProvider            = new FakeSimpleProvider();
     _fakeAsyncProvider             = new FakeAsyncProvider();
     _fakeReferenceObjectProvider   = new FakeReferenceObjectProvider();
     _fakeMultiProvider             = new FakeMultipleParameterProvider();
     _cachedSimpleProvider          = _fakeSimpleProvider.Cached <ISimpleProvider>(_cacheDuration);
     _cachedAsyncProvider           = _fakeAsyncProvider.Cached <IAsyncProvider>(_cacheDuration);
     _cachedReferenceObjectProvider = _fakeReferenceObjectProvider.Cached <IReferenceObjectProvider>(_cacheDuration);
     _cachedMultiProvider           = _fakeMultiProvider.Cached <IMultipleParameterProvider>(_cacheDuration);
 }
Пример #2
0
        public async Task CachingDecorator_AsyncCacheOnlyOneMethod_OneMethodCachedAndTheOtherIsNot()
        {
            var cached = _fakeAsyncProvider.Cached <IAsyncProvider>(
                _cacheDuration,
                typeof(IAsyncProvider).GetMethod(nameof(_fakeAsyncProvider.Provide1)),
                m => $"{m.MethodInfo.Name}, {m.Args[0]}");

            await cached.Provide1(_sampleParam1);

            await cached.Provide1(_sampleParam1);

            await cached.Provide2(_sampleParam1);

            await cached.Provide2(_sampleParam1);

            Assert.AreEqual(1, _fakeAsyncProvider.CallsMadeOnProvide1.Count);
            Assert.AreEqual(2, _fakeAsyncProvider.CallsMadeOnProvide2.Count);
        }