Пример #1
0
        public void SetGenericCache_HappyPath_CallsCorrespondingMethodInConfiguration()
        {
            var genericCacheImplementationMock = new Mock <ICacheImplementation>();

            _sut.SetGenericCache(genericCacheImplementationMock.Object);

            _cacheConfigurationMock
            .Verify(c => c.SetGenericCache(It.IsAny <ICacheImplementation>()), Times.Once);
        }
Пример #2
0
        public async Task RetrieveOrStoreAsync_MultipleCallsForTheSameKey_CallsEntityFetcherOnlyOnce()
        {
            CacheBuilder
            .SetGenericCache(new DictionaryCacheImplementation());

            var entityFetcherMock = new Mock <Func <string, Task <User> > >();

            entityFetcherMock
            .Setup(f => f(KEY))
            .Returns(Task.Delay(500).ContinueWith(_ => User.Test));

            var tasks = Enumerable.Range(0, 10)
                        .Select(_ => Cache.RetrieveOrStoreAsync(KEY, entityFetcherMock.Object))
                        .ToList();
            await Task.WhenAll(tasks);

            entityFetcherMock.Verify(f => f(KEY), Times.Once);
        }
Пример #3
0
 protected BaseTest()
 {
     CacheBuilder.SetGenericCache(CacheImplementationMock.Object);
 }