Inheritance: IAvatarProvider
Example #1
0
        IObservable <BitmapSource> ResolveImage(SuggestionItem uri)
        {
            if (uri.ImageUrl != null)
            {
                return(avatarProvider.GetAvatar(uri.ImageUrl));
            }

            return(Observable.Return(AvatarProvider.CreateBitmapImage(DefaultAvatar)));
        }
        public async Task GetsAvatarFromCache()
        {
            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);
        }
        public void DoesNotThrowOnNullUserOrAvatarUrl()
        {
            var blobStore = Substitute.For<IBlobCache>();
            blobStore.Invalidate(null).Returns(_ => { throw new ArgumentNullException(); });
            var sharedCache = Substitute.For<ISharedCache>();
            sharedCache.LocalMachine.Returns(blobStore);

            var avatarProvider = new AvatarProvider(sharedCache, new TestImageCache());

            avatarProvider.InvalidateAvatar(null);
            avatarProvider.InvalidateAvatar(Substitute.For<IAvatarContainer>());
        }