public async Task RetrievesGitHubAvatar() { var expectedImage = AvatarProvider.CreateBitmapImage("pack://*****:*****@test.com&s=140"); var blobCache = new InMemoryBlobCache(); var sharedCache = Substitute.For <ISharedCache>(); sharedCache.LocalMachine.Returns(blobCache); var imageCache = new TestImageCache(); await imageCache.SeedImage(avatarUrl, expectedImage, DateTimeOffset.MaxValue); var avatarProvider = new AvatarProvider(sharedCache, imageCache); var avatarContainer = Substitute.For <IAvatarContainer>(); avatarContainer.AvatarUrl.Returns("https://avatars.githubusercontent.com/u/[email protected]&s=140"); var retrieved = await avatarProvider.GetAvatar(avatarContainer); AssertSameImage(expectedImage, retrieved); }
public async Task CanBeAccessedFromMultipleThreads() { var blobCache = new InMemoryBlobCache(); var sharedCache = Substitute.For <ISharedCache>(); sharedCache.LocalMachine.Returns(blobCache); var imageCache = new TestImageCache(); var avatarProvider = new AvatarProvider(sharedCache, imageCache); var expected = avatarProvider.DefaultUserBitmapImage.ToString(); int mainThreadId = Thread.CurrentThread.ManagedThreadId; int otherThreadId = mainThreadId; var actual = await Task.Run(() => { otherThreadId = Thread.CurrentThread.ManagedThreadId; return(avatarProvider.DefaultUserBitmapImage.ToString()); }); Assert.Equal(expected, actual); Assert.NotEqual(mainThreadId, otherThreadId); }