public async Task ReleasingImageSourceReturnsDifferentBitmap() { var bitmapFile = CreateBitmapFile(100, 100, Colors.Red); var imageSource = new FileImageSourceStub(bitmapFile); var service = new FileImageSourceService(); // get an image var result1 = await service.GetDrawableAsync(imageSource, Platform.DefaultContext); var bitmapDrawable1 = Assert.IsType <BitmapDrawable>(result1.Value); var bitmap1 = bitmapDrawable1.Bitmap; // release result1.Dispose(); // try collect it var collected = await TryCollectFile(bitmapFile); Assert.True(collected); // get the image again var result2 = await service.GetDrawableAsync(imageSource, Platform.DefaultContext); var bitmapDrawable2 = Assert.IsType <BitmapDrawable>(result2.Value); var bitmap2 = bitmapDrawable2.Bitmap; // make sure it WAS collected and we got a new image Assert.NotEqual(bitmap1, bitmap2); result2.Dispose(); }
public async Task TheSameImageSourceReturnsTheSameBitmap() { var bitmapFile = CreateBitmapFile(100, 100, Colors.Red); var imageSource = new FileImageSourceStub(bitmapFile); var service = new FileImageSourceService(); // get an image var result1 = await service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext); var drawable1 = result1.Value; var bitmapDrawable1 = Assert.IsType <BitmapDrawable>(drawable1); var bitmap1 = bitmapDrawable1.Bitmap; // try collect it var collected = await TryCollectFile(bitmapFile); Assert.False(collected); // get the image again var result2 = await service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext); var drawable2 = result2.Value; var bitmapDrawable2 = Assert.IsType <BitmapDrawable>(drawable2); var bitmap2 = bitmapDrawable2.Bitmap; // make sure it was NOT collected and we got the same image Assert.Equal(bitmap1, bitmap2); result1.Dispose(); result2.Dispose(); }
public async Task ThrowsForIncorrectTypes(Type type) { var service = new FileImageSourceService(); var imageSource = (ImageSourceStub)Activator.CreateInstance(type); await Assert.ThrowsAsync <InvalidCastException>(() => service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext)); }
public async Task GetDrawableAsyncWithResource(string filename, string colorHex) { var service = new FileImageSourceService(); var imageSource = new FileImageSourceStub(filename); using var result = await service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext); var expectedColor = Color.FromArgb(colorHex); result.Value.AssertColorAtCenter(expectedColor.ToPlatform()); }
public async Task GetDrawableAsyncWithResource(string filename, string colorHex) { var service = new FileImageSourceService(); var imageSource = new FileImageSourceStub(filename); using var drawable = await service.GetDrawableAsync(imageSource, Platform.DefaultContext); var bitmapDrawable = Assert.IsType <BitmapDrawable>(drawable.Value); var bitmap = bitmapDrawable.Bitmap; var expectedColor = Color.FromArgb(colorHex); bitmap.AssertColorAtCenter(expectedColor.ToPlatform()); }
public async Task GetDrawableAsyncWithFile(string colorHex) { var expectedColor = Color.FromArgb(colorHex); var service = new FileImageSourceService(); var filename = CreateBitmapFile(100, 100, expectedColor); var imageSource = new FileImageSourceStub(filename); using var result = await service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext); var bitmapDrawable = Assert.IsType <BitmapDrawable>(result.Value); var bitmap = bitmapDrawable.Bitmap; bitmap.AssertColorAtCenter(expectedColor.ToPlatform()); }