Example #1
0
        public LocalFileProxyTests()
        {
            _folderPath = Path.Combine(_localFileProxyFolder, _folder);
            _file1Path  = Path.Combine(_folderPath, _file1);
            _file2Path  = Path.Combine(_folderPath, _file2);

            _localFileProxy = new LocalFileProxy(new MockLogger <LocalFileProxy>(),
                                                 new MockOptions <CommonSettings>(
                                                     new CommonSettings
            {
                FileProxyType        = FileProxyTypes.Local,
                LocalFileProxyFolder = _localFileProxyFolder
            }));
            if (!Directory.Exists(_localFileProxyFolder))
            {
                Directory.CreateDirectory(_localFileProxyFolder);
            }
            if (!Directory.Exists(_folderPath))
            {
                Directory.CreateDirectory(_folderPath);
            }
            if (!File.Exists(_file1Path))
            {
                File.WriteAllText(_file1Path, "TestData1");
            }
            if (!File.Exists(_file2Path))
            {
                File.WriteAllText(_file2Path, "TestData2");
            }
        }
Example #2
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);
        }