public void TestSetup() { _folder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(_folder); var cacheFolder = Path.Combine(_folder, "Cache"); Directory.CreateDirectory(cacheFolder); // override configuration var config = UQConfiguration.Instance as UQConfiguration; config.HorizontalCacheConfigurationSection.SetParameter("folder", cacheFolder); config.HorizontalCacheConfigurationSection.ProviderType = typeof(TestTextFileCacheProvider <>); config.HorizontalCacheConfigurationSection.IsEnabled = true; // create 1000 files for testing var dao = new DummyEntityDAO2(); dao.SetProperties(new Dictionary <string, object> { ["folder"] = _folder }); dao.GenerateFiles(1000); // forces the cache initialization var context = new DummyContext(_folder); context.DummyEntitiesWithCache.Select(x => x.Key).ToList(); }
public static void Setup(TestContext testContext) { Directory.CreateDirectory(@"C:\Tests"); Directory.CreateDirectory(@"C:\Tests\DataSource"); var dao = new DummyEntityDAO2(); dao.SetProperties(new Dictionary <string, object> { ["folder"] = @"C:\Tests\DataSource" }); dao.GenerateFiles(100000); }
[Ignore] // takes time public void TestFullRebuild() { var folder = @"C:\Tests\"; var dao = new DummyEntityDAO2(); dao.SetProperties(new Dictionary <string, object> { ["folder"] = Path.Combine(folder, "DataSource") }); var cacheProvider = new TextFileCacheProvider <DummyEntity>("DB1", new Dictionary <string, string> { ["folder"] = folder }, dao, GeneralHelper.GetPropertiesHavingAttribute(typeof(DummyEntity), typeof(CachedAttribute))); var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); cacheProvider.FullRebuild(); stopwatch.Stop(); Assert.IsTrue(stopwatch.ElapsedMilliseconds < 100000); Assert.IsTrue(File.Exists(Path.Combine(folder, "TN.DB1.UQFramework.Test.DummyEntity.UQFramework.Test.DummyEntityDAO2.txt"))); var cache = cacheProvider.GetAllCachedItems(); Assert.AreEqual(100000, cache.Count); var itemId = "32017"; // just random id to check that cached is properly var cachedData = cache[itemId].SomeData; var realItem = dao.GetEntity(itemId); Assert.AreEqual(realItem.SomeData, cachedData); }