コード例 #1
0
            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);
                }
            }
コード例 #2
0
            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);
                }
            }
コード例 #3
0
            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);
                }
            }
コード例 #4
0
            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);
            }
コード例 #5
0
            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);
                }
            }