コード例 #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 void CachingDecorator_CacheOnlyOneMethod_OneMethodCachedAndTheOtherIsNot()
        {
            var cached = _fakeSimpleProvider.Cached <ISimpleProvider>(
                _cacheDuration,
                typeof(ISimpleProvider).GetMethod(nameof(_fakeSimpleProvider.Provide1)),
                m => $"{m.MethodInfo.Name}, {m.Args[0]}");

            cached.Provide1(_sampleParam1);
            cached.Provide1(_sampleParam1);
            cached.Provide2(_sampleParam1);
            cached.Provide2(_sampleParam1);

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