public async Task WillStopBackgroundLoading() { var fakeCacheFile = new FakeCacheFile(); var fakeKeyInfo = new KeyInfo(FakeEnumerable(), null, 1_000_000); var backgroundLoadComplete = false; using (var collection = new FileSystemBackedKeyCollection(fakeKeyInfo, fakeCacheFile)) { collection.BackgroundLoadComplete += (object sender, System.EventArgs e) => backgroundLoadComplete = true; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed collection.PopulateFileSystemAsync(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Assert.False(backgroundLoadComplete); collection.CancelBackgroundLoading(); await Task.Delay(1_000); Assert.True(backgroundLoadComplete); } }
public async Task WillReturnIfAtleast500ItemsHaveLoaded() { var fakeCacheFile = new FakeCacheFile(); var fakeKeyInfo = new KeyInfo(FakeEnumerable(), null, 1); using (var collection = new FileSystemBackedKeyCollection(fakeKeyInfo, fakeCacheFile)) { await collection.PopulateFileSystemAsync(); Assert.True(collection.Count >= 500); } }
public async Task WillReturnIfBackgroundLoadIsComplete() { var fakeCacheFile = new FakeCacheFile(); var fakeKeyInfo = new KeyInfo(FakeEnumerable(), null, 1); using (var collection = new FileSystemBackedKeyCollection(fakeKeyInfo, fakeCacheFile)) { await collection.PopulateFileSystemAsync(); Assert.Equal(500, collection.Count); } }
public async Task WillFireOnceEnumerationIsComplete() { var fakeCacheFile = new FakeCacheFile(); var fakeKeyInfo = new KeyInfo(FakeEnumerable(), null, 0); var eventFired = false; var collection = new FileSystemBackedKeyCollection(fakeKeyInfo, fakeCacheFile); collection.BackgroundLoadComplete += (object sender, System.EventArgs e) => eventFired = true; await collection.PopulateFileSystemAsync(); Assert.True(eventFired); }
public async Task WillFireOnPopulateFileSystem() { var fakeCacheFile = new FakeCacheFile(); var fakeKeyInfo = new KeyInfo(FakeEnumerable(), null, 1_000_000); var eventFired = false; using (var collection = new FileSystemBackedKeyCollection(fakeKeyInfo, fakeCacheFile)) { collection.BackgroundLoadStarted += (object sender, System.EventArgs e) => eventFired = true; await collection.PopulateFileSystemAsync(); Assert.True(eventFired); } }