Example #1
0
        public async Task GetTestAsync()
        {
            var ingredients = new List <Ingredient>
            {
                new Ingredient("a", DateTime.Now.AddDays(-2), new[] { "A" }, "A", "X", false),
                new Ingredient("b", DateTime.Now.AddMinutes(-2), new[] { "B" }, "B1", "Y", true)
            };
            await File.WriteAllTextAsync(Path.Combine(_localFileProxyFolder, "ingredients.json"), JsonConvert.SerializeObject(ingredients));

            var fileProxy = new LocalFileProxy(new MockLogger <LocalFileProxy>(), new MockOptions <CommonSettings>(
                                                   new CommonSettings
            {
                FileProxyType        = FileProxyTypes.Local,
                LocalFileProxyFolder = _localFileProxyFolder
            }));

            var ingredientsCache = new IngredientsCache(fileProxy, new MockLogger <IngredientsCache>(), new MockOptions <CommonSettings>(new CommonSettings
            {
                IngredientsCacheExpiration = TimeSpan.FromMilliseconds(500)
            }));

            var ingredient = await ingredientsCache.GetAsync("b");

            Assert.Equal("B1", ingredient.Description);

            ingredients.Remove(ingredient);
            ingredients.Add(ingredient.With(description: "B2"));
            await File.WriteAllTextAsync(Path.Combine(_localFileProxyFolder, "ingredients.json"), JsonConvert.SerializeObject(ingredients));

            ingredient = await ingredientsCache.GetAsync("b");

            Assert.Equal("B1", ingredient.Description);

            await Task.Delay(750);

            ingredient = await ingredientsCache.GetAsync("b");

            Assert.Equal("B2", ingredient.Description);
        }
Example #2
0
 public RecipeCache(ICacheProxy cacheProxy, IngredientsCache ingredientsCache, ILogger <RecipeCache> logger) : base(cacheProxy, logger)
 {
     _ingredientsCache = ingredientsCache;
 }