Exemplo n.º 1
0
        public async Task DeleteItemAsync_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.DeleteItemAsync("tesTask1");

            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.DeleteItemAsync("tesTask1"), Times.Once());
            Assert.AreEqual(success, success2);
        }
Exemplo n.º 2
0
        public async Task DeleteItemAsync_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.DeleteItemAsync("tesTaskId1");

            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.DeleteItemAsync("tesTaskId1"), Times.Once());
            Assert.IsTrue(success);
            Assert.IsTrue(success2);
        }
Exemplo n.º 3
0
        public async Task DeleteItemAsync_ClearsAllItemsPredicateCacheKeys()
        {
            var repository        = GetMockRepository();
            var cachingRepository = new CachingWithRetriesRepository <TesTask>(repository.Object);
            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.DeleteItemAsync("deleteItem");

            var items2 = await cachingRepository.GetItemsAsync(predicate);

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