public Task <IImageSourceServiceResult <UIImage> > GetImageAsync(ICustomImageSourceStub imageSource, float scale = 1, CancellationToken cancellationToken = default) { var color = imageSource.Color; var drawable = _cache.Get(color); var result = new ImageSourceServiceResult(drawable, () => _cache.Return(color)); return(Task.FromResult <IImageSourceServiceResult <UIImage> >(result)); }
public override Task <IImageSourceServiceResult <Drawable> > GetDrawableAsync(IImageSource imageSource, Context context, CancellationToken cancellationToken = default) { if (imageSource is not ICustomImageSourceStub imageSourceStub) { return(Task.FromResult <IImageSourceServiceResult <Drawable> >(null)); } var color = imageSourceStub.Color; var drawable = _cache.Get(color); var result = new ImageSourceServiceResult(drawable, () => _cache.Return(color)); return(Task.FromResult <IImageSourceServiceResult <Drawable> >(result)); }
public void ResultsDisposeCorrectlyAndOnce() { var dispose = 0; var cache = new CustomImageCacheStub(); var image = cache.Get(Colors.Red); var result = new ImageSourceServiceResult(image, () => dispose++); Assert.False(result.IsDisposed); Assert.Equal(0, dispose); result.Dispose(); Assert.True(result.IsDisposed); Assert.Equal(1, dispose); result.Dispose(); Assert.True(result.IsDisposed); Assert.Equal(1, dispose); cache.Return(Colors.Red); }
public async Task ResultsDisposeCorrectlyAndOnce() { var dispose = 0; var cache = new CustomImageCacheStub(); var image = await InvokeOnMainThreadAsync(() => cache.Get(Colors.Red)); var result = new ImageSourceServiceResult(image, () => dispose++); Assert.False(result.IsDisposed); Assert.Equal(0, dispose); result.Dispose(); Assert.True(result.IsDisposed); Assert.Equal(1, dispose); result.Dispose(); Assert.True(result.IsDisposed); Assert.Equal(1, dispose); cache.Return(Colors.Red); }