public void Disk_cache_does_not_exist_when_initialised_but_not_yet_used() { var storagePath = Guid.NewGuid().ToString(); var locationCacheDisk = new LocationCacheDisk(null, storagePath); Assert.False(System.IO.File.Exists(storagePath)); }
public DiskLoggingTests() { logger = Setup.ConfigureDi.Services.GetRequiredService <FakeLogger <LocationCacheDisk> >(); var diskStoragePath = System.Guid.NewGuid().ToString() + ".json"; locationCacheDisk = new LocationCacheDisk(logger, diskStoragePath); locationCreator = Setup.ConfigureDi.Services.GetRequiredService <LocationCreator>(); }
public async Task Location_cache_can_be_used_when_cache_file_has_not_been_written_yet() { var locationCacheDisk = new LocationCacheDisk(null, Guid.NewGuid().ToString()); var result = await locationCacheDisk.FindByKeyAsync("Does not exist in cache"); Assert.Null(result); }
public async Task Location_cache_is_written_to_disk() { var storagePath = Guid.NewGuid().ToString(); var locationCacheDisk = new LocationCacheDisk(null, storagePath); var locationCreator = Setup.ConfigureDi.Services.GetRequiredService <LocationCreator>(); var location = locationCreator.Create("AddedToCacheHere"); await locationCacheDisk.InsertAsync(location); Assert.True(System.IO.File.Exists(storagePath)); }
/// <summary> /// Creates an instance of the LocationCache that has a fake logger attached for /// checking that code is called. /// Suitable for unit and integration testing. /// </summary> /// <returns></returns> public CacheManager Create() { DiskStoragePath = Guid.NewGuid().ToString() + ".json"; L1Logger = serviceProvider.GetRequiredService <FakeLogger <LocationCacheMemory> >(); L2Logger = serviceProvider.GetRequiredService <FakeLogger <LocationCacheDisk> >(); Level1Cache = new LocationCacheMemory(L1Logger); Level2Cache = new LocationCacheDisk(L2Logger, DiskStoragePath); LocationCreator = serviceProvider.GetRequiredService <LocationCreator>(); Logger = serviceProvider.GetRequiredService <FakeLogger <CacheManager> >(); return(new CacheManager(Level1Cache, Level2Cache, LocationCreator, Logger)); }
public async Task Location_cache_is_read_from_disk() { var storagePath = Guid.NewGuid().ToString(); var locationCacheDisk = new LocationCacheDisk(null, storagePath); var locationCreator = Setup.ConfigureDi.Services.GetRequiredService <LocationCreator>(); var location = locationCreator.Create("PersistedToDisk"); await locationCacheDisk.InsertAsync(location); locationCacheDisk = new LocationCacheDisk(null, storagePath); var result = await locationCacheDisk.FindByKeyAsync(location.SourceKey); Assert.Equal("PersistedToDisk", result.Source); }