public async Task GetItemsAsync_UsesCache() { 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); var items2 = await cachingRepository.GetItemsAsync(predicate); repository.Verify(mock => mock.GetItemsAsync(It.IsAny <Expression <Func <TesTask, bool> > >()), Times.Once()); Assert.AreEqual(items, items2); Assert.AreEqual(3, items.Count()); }
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); }
public async Task GetItemsAsync_ThrowsException_DoesNotSetCache() { SystemClock.SleepAsync = (_, __) => Task.FromResult(true); SystemClock.Sleep = (_, __) => { }; var repository = GetMockRepository(); var cachingRepository = new CachingWithRetriesRepository <TesTask>(repository.Object); Expression <Func <TesTask, bool> > predicate = t => t.WorkflowId.Equals("doesNotExist"); await Assert.ThrowsExceptionAsync <Exception>(async() => await cachingRepository.GetItemsAsync(predicate)); repository.Verify(mock => mock.GetItemsAsync(predicate), Times.Exactly(4)); }