public async Task GetCategories_Saves_Data_To_Cache() { var cacheService = new MockCacheService(); cacheService.DataExistsAndIsValidAsyncDelegate = s => Task.FromResult(false); cacheService.SaveExternalDataAsyncDelegate = s => Task.FromResult(new Uri("http://test.org")); cacheService.SaveDataAsyncDelegate = (s, o) => { var collection = (ReadOnlyCollection<Category>)o; Assert.AreEqual("Categories0", s); Assert.AreEqual(2, collection.Count); Assert.AreEqual(1, collection[0].Id); Assert.AreEqual(2, collection[1].Id); return Task.FromResult(new Uri("http://test.org")); }; var productCatalogService = new MockProductCatalogService(); var categories = new List<Category> { new Category{ Id = 1}, new Category{ Id = 2} }; productCatalogService.GetCategoriesAsyncDelegate = (depth) => Task.FromResult(new ReadOnlyCollection<Category>(categories)); productCatalogService.GetSubcategoriesAsyncDelegate = i => Task.FromResult(new ReadOnlyCollection<Category>(null)); var target = new ProductCatalogRepository(productCatalogService, cacheService); await target.GetCategoriesAsync(0); }
public async Task GetCategories_Calls_Service_When_Cache_Miss() { var cacheService = new MockCacheService(); cacheService.GetDataDelegate = s => { throw new FileNotFoundException(); }; cacheService.SaveDataAsyncDelegate = (s, c) => Task.FromResult(new Uri("http://test.org")); var productCatalogService = new MockProductCatalogService(); var categories = new List <Category> { new Category { Id = 1 }, new Category { Id = 2 } }; productCatalogService.GetSubcategoriesAsyncDelegate = (parentId, maxProducts) => Task.FromResult(new ReadOnlyCollection <Category>(categories)); var target = new ProductCatalogRepository(productCatalogService, cacheService); var returnedCategories = await target.GetRootCategoriesAsync(0); Assert.AreEqual(2, returnedCategories.Count); Assert.AreEqual(1, returnedCategories[0].Id); Assert.AreEqual(2, returnedCategories[1].Id); }
public async Task GetCategories_Uses_Cache_When_Data_Available() { var cacheService = new MockCacheService(); cacheService.DataExistsAndIsValidAsyncDelegate = s => Task.FromResult(true); var categories = new List<Category> { new Category{ Id = 1}, new Category{ Id = 2} }; cacheService.GetDataDelegate = (string s) => { if (s == "Categories0") return new ReadOnlyCollection<Category>(categories); return new ReadOnlyCollection<Category>(null); }; var productCatalogService = new MockProductCatalogService(); productCatalogService.GetCategoriesAsyncDelegate = (depth) => Task.FromResult(new ReadOnlyCollection<Category>(null)); var target = new ProductCatalogRepository(productCatalogService, cacheService); var returnedCategories = await target.GetCategoriesAsync(0); Assert.AreEqual(2, returnedCategories.Count); Assert.AreEqual(1, returnedCategories[0].Id); Assert.AreEqual(2, returnedCategories[1].Id); }
public async Task GetCategories_Saves_Data_To_Cache() { var cacheService = new MockCacheService(); cacheService.GetDataDelegate = s => { throw new FileNotFoundException(); }; cacheService.SaveDataAsyncDelegate = (s, o) => { var collection = (ReadOnlyCollection <Category>)o; Assert.AreEqual("Categories-0-0", s); Assert.AreEqual(2, collection.Count); Assert.AreEqual(1, collection[0].Id); Assert.AreEqual(2, collection[1].Id); return(Task.FromResult(new Uri("http://test.org"))); }; var productCatalogService = new MockProductCatalogService(); var categories = new List <Category> { new Category { Id = 1 }, new Category { Id = 2 } }; productCatalogService.GetSubcategoriesAsyncDelegate = (parentId, maxProducts) => Task.FromResult(new ReadOnlyCollection <Category>(categories)); var target = new ProductCatalogRepository(productCatalogService, cacheService); await target.GetRootCategoriesAsync(0); }
public void ShouldThrowExceptionWhenNotCached() { var cacheService = new MockCacheService(); Action action = () => cacheService.Get <string>(Key); action.ShouldThrow <Exception>(); }
public async Task GetSubcategories_Uses_Cache_When_Data_Available() { var cacheService = new MockCacheService(); var categories = new List <Category> { new Category { Id = 10 }, new Category { Id = 11 } }; cacheService.GetDataDelegate = s => { if (s == "Categories-1-10") { return(new ReadOnlyCollection <Category>(categories)); } return(new ReadOnlyCollection <Category>(null)); }; var productCatalogService = new MockProductCatalogService(); productCatalogService.GetSubcategoriesAsyncDelegate = (parentId, maxProducts) => Task.FromResult(new ReadOnlyCollection <Category>(null)); var target = new ProductCatalogRepository(productCatalogService, cacheService); var returnedCategories = await target.GetSubcategoriesAsync(1, 10); Assert.AreEqual(2, returnedCategories.Count); Assert.AreEqual(10, returnedCategories[0].Id); Assert.AreEqual(11, returnedCategories[1].Id); }
public void ShouldReturnValueWhenCached() { var cacheService = new MockCacheService(); cacheService.Set(Key, Value); cacheService.Get <string>(Key).ShouldBeEquivalentTo(Value); }
public void ShouldCacheValue() { var store = new Store(); var cacheService = new MockCacheService(); using (var cacheRepository = new CacheRepository(cacheService)) { var value = cacheRepository.Get(Key, store.GetString); cacheService.Get <string>(Key).ShouldBeEquivalentTo(value); } }
public MedicalEditsBaseTest() { var mockRepository = new MockRepository().MockMedicalEditsFindPatient(); var mockSetting = new MockSettingService().MockGetMedicalEditsServiceSetting(); var mockCachSevice = new MockCacheService().MockActivityTypesCacheList(); var medicalEditsSetting = mockSetting.Object.GetMedicalEditsSetting(); var httpClient = new HttpClient() { BaseAddress = new Uri(medicalEditsSetting.Url) }; _medicalEditsClient = new MedicalEditsClient(httpClient); _medicalEditsService = new MedicalEditsService(_medicalEditsClient, mockRepository.Object, mockSetting.Object, mockCachSevice.Object); }
public async Task GetCategories_Uses_Cache_When_Data_Available() { var cacheService = new MockCacheService(); // cacheService.DataExistsAndIsValidAsyncDelegate = s => Task.FromResult(true); var categories = new List <Category> { new Category { Id = 1 }, new Category { Id = 2 } }; cacheService.GetDataDelegate = (string s) => { if (s == "Categories-0-0") { return(new ReadOnlyCollection <Category>(categories)); } return(new ReadOnlyCollection <Category>(null)); }; var productCatalogService = new MockProductCatalogService { GetSubcategoriesAsyncDelegate = (parentId, maxProducts) => Task.FromResult <ICollection <Category> >( new Collection <Category>(null)) }; var target = new ProductCatalogRepository(productCatalogService, cacheService); var returnedCategories = (await target.GetRootCategoriesAsync(0)).ToList(); Assert.AreEqual(2, returnedCategories.Count); Assert.AreEqual(1, returnedCategories[0].Id); Assert.AreEqual(2, returnedCategories[1].Id); }
public async Task GetCategories_Calls_Service_When_Cache_Miss() { var cacheService = new MockCacheService { GetDataDelegate = s => { throw new FileNotFoundException(); }, SaveDataAsyncDelegate = (s, c) => Task.FromResult(new Uri("http://test.org")) }; var productCatalogService = new MockProductCatalogService(); var categories = new List<Category> { new Category { Id = 1 }, new Category { Id = 2 } }; productCatalogService.GetSubcategoriesAsyncDelegate = (parentId, maxProducts) => Task.FromResult((ICollection<Category>)(new Collection<Category>(categories))); var target = new ProductCatalogRepository(productCatalogService, cacheService); var returnedCategories = (await target.GetRootCategoriesAsync(0)).ToList(); Assert.AreEqual(2, returnedCategories.Count); Assert.AreEqual(1, returnedCategories[0].Id); Assert.AreEqual(2, returnedCategories[1].Id); }
public async Task GetCategories_Calls_Service_When_Cache_Miss() { var cacheService = new MockCacheService(); cacheService.DataExistsAndIsValidAsyncDelegate = s => Task.FromResult(false); cacheService.SaveExternalDataAsyncDelegate = s => Task.FromResult(new Uri("http://test.org")); cacheService.SaveDataAsyncDelegate = (s, c) => Task.FromResult(new Uri("http://test.org")); var productCatalogService = new MockProductCatalogService(); var categories = new List<Category> { new Category{ Id = 1}, new Category{ Id = 2} }; productCatalogService.GetCategoriesAsyncDelegate = (depth) => Task.FromResult(new ReadOnlyCollection<Category>(categories)); productCatalogService.GetSubcategoriesAsyncDelegate = (i) => Task.FromResult(new ReadOnlyCollection<Category>(null)); var target = new ProductCatalogRepository(productCatalogService, cacheService); var returnedCategories = await target.GetCategoriesAsync(0); Assert.AreEqual(2, returnedCategories.Count); Assert.AreEqual(1, returnedCategories[0].Id); Assert.AreEqual(2, returnedCategories[1].Id); }
public async Task GetCategories_Saves_Data_To_Cache() { var cacheService = new MockCacheService { GetDataDelegate = s => { throw new FileNotFoundException(); }, SaveDataAsyncDelegate = (s, o) => { var collection = (Collection<Category>)o; Assert.AreEqual("Categories-0-0", s); Assert.AreEqual(2, collection.Count); Assert.AreEqual(1, collection[0].Id); Assert.AreEqual(2, collection[1].Id); return Task.FromResult(new Uri("http://test.org")); } }; var productCatalogService = new MockProductCatalogService(); var categories = new List<Category> { new Category{ Id = 1}, new Category{ Id = 2} }; productCatalogService.GetSubcategoriesAsyncDelegate = (parentId, maxProducts) => Task.FromResult<ICollection<Category>>(new Collection<Category>(categories)); var target = new ProductCatalogRepository(productCatalogService, cacheService); await target.GetRootCategoriesAsync(0); }
public async Task GetSubcategories_Uses_Cache_When_Data_Available() { var cacheService = new MockCacheService(); var categories = new List<Category> { new Category{ Id = 10}, new Category{ Id = 11} }; cacheService.GetDataDelegate = s => { if (s == "Categories-1-10") return new ReadOnlyCollection<Category>(categories); return new ReadOnlyCollection<Category>(null); }; var productCatalogService = new MockProductCatalogService(); productCatalogService.GetSubcategoriesAsyncDelegate = (parentId, maxProducts) => Task.FromResult<ICollection<Category>>(new Collection<Category>(null)); var target = new ProductCatalogRepository(productCatalogService, cacheService); var returnedCategories = (await target.GetSubcategoriesAsync(1, 10)).ToList(); Assert.AreEqual(2, returnedCategories.Count); Assert.AreEqual(10, returnedCategories[0].Id); Assert.AreEqual(11, returnedCategories[1].Id); }