示例#1
0
        public async Task UpdateItemAsync_RemovesItemFromCache()
        {
            var repository        = GetMockRepository();
            var cachingRepository = new CachingWithRetriesRepository <TesTask>(repository.Object);

            TesTask tesTask = null;
            var     success = await cachingRepository.TryGetItemAsync("tesTaskId1", item => tesTask = item);

            await cachingRepository.UpdateItemAsync(tesTask);

            var success2 = await cachingRepository.TryGetItemAsync("tesTaskId1", item => tesTask = item);

            repository.Verify(mock => mock.TryGetItemAsync("tesTaskId1", It.IsAny <Action <TesTask> >()), Times.Exactly(2));
            repository.Verify(mock => mock.UpdateItemAsync(It.IsAny <TesTask>()), Times.Once());
            Assert.IsTrue(success);
            Assert.IsTrue(success2);
        }
示例#2
0
        public async Task UpdateItemAsync_RemovesItemFromCache()
        {
            var repository        = GetMockRepository();
            var cachingRepository = new CachingWithRetriesRepository <TesTask>(repository.Object);
            RepositoryItem <TesTask>           repositoryItem = null;
            Action <RepositoryItem <TesTask> > action         = item => repositoryItem = item;

            var success = await cachingRepository.TryGetItemAsync("tesTask1", action);

            await cachingRepository.UpdateItemAsync("tesTask1", repositoryItem);

            var success2 = await cachingRepository.TryGetItemAsync("tesTask1", action);

            repository.Verify(mock => mock.TryGetItemAsync("tesTask1", It.IsAny <Action <RepositoryItem <TesTask> > >()), Times.Exactly(2));
            repository.Verify(mock => mock.UpdateItemAsync(It.IsAny <string>(), It.IsAny <RepositoryItem <TesTask> >()), Times.Once());
            Assert.AreEqual(success, success2);
        }
示例#3
0
        public async Task UpdateItemAsync_ClearsAllItemsPredicateCacheKeys()
        {
            var repository        = GetMockRepository();
            var cachingRepository = new CachingWithRetriesRepository <TesTask>(repository.Object);
            RepositoryItem <TesTask>           repositoryItem = null;
            Expression <Func <TesTask, bool> > predicate      = t => t.State == TesState.QUEUEDEnum ||
                                                                t.State == TesState.INITIALIZINGEnum ||
                                                                t.State == TesState.RUNNINGEnum ||
                                                                (t.State == TesState.CANCELEDEnum && t.IsCancelRequested);

            var items = await cachingRepository.GetItemsAsync(predicate);

            await cachingRepository.UpdateItemAsync("updateItem", repositoryItem);

            var items2 = await cachingRepository.GetItemsAsync(predicate);

            repository.Verify(mock => mock.GetItemsAsync(It.IsAny <Expression <Func <TesTask, bool> > >()), Times.Exactly(2));
            repository.Verify(mock => mock.UpdateItemAsync(It.IsAny <string>(), It.IsAny <RepositoryItem <TesTask> >()), Times.Once());
            Assert.AreEqual(items, items2);
        }