Beispiel #1
0
        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.GetImageAsync(imageSource);

            var uiimage1 = Assert.IsType <UIImage>(result1.Value);

            // release
            result1.Dispose();

            // try collect it
            var collected = await TryCollectFile(bitmapFile);

            Assert.True(collected);

            // get the image again
            var result2 = await service.GetImageAsync(imageSource);

            var uiimage2 = Assert.IsType <UIImage>(result2.Value);

            // make sure it WAS collected and we got a new image
            Assert.NotEqual(uiimage1, uiimage2);

            result2.Dispose();
        }
Beispiel #2
0
        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.GetImageAsync(imageSource);

            var uiimage1 = Assert.IsType <UIImage>(result1.Value);

            // try collect it
            var collected = await TryCollectFile(bitmapFile);

            Assert.False(collected);

            // get the image again
            var result2 = await service.GetImageAsync(imageSource);

            var uiimage2 = Assert.IsType <UIImage>(result2.Value);

            // make sure it was NOT collected and we got the same image
            Assert.Equal(uiimage1, uiimage2);

            result1.Dispose();
            result2.Dispose();
        }
Beispiel #3
0
        public async Task ThrowsForIncorrectTypes(Type type)
        {
            var service = new FileImageSourceService();

            var imageSource = (ImageSourceStub)Activator.CreateInstance(type);

            await Assert.ThrowsAsync <InvalidCastException>(() => service.GetImageAsync(imageSource));
        }
Beispiel #4
0
        public async Task GetImageAsyncWithResource(string filename, string colorHex)
        {
            var service = new FileImageSourceService();

            var imageSource = new FileImageSourceStub(filename);

            using var result = await service.GetImageAsync(imageSource);

            var uiimage = Assert.IsType <UIImage>(result.Value);

            var expectedColor = Color.FromHex(colorHex);

            uiimage.AssertColorAtCenter(expectedColor.ToNative());
        }
Beispiel #5
0
        public async Task GetImageAsyncWithFile(string colorHex)
        {
            var expectedColor = Color.FromHex(colorHex);

            var service = new FileImageSourceService();

            var filename    = CreateBitmapFile(100, 100, expectedColor);
            var imageSource = new FileImageSourceStub(filename);

            using var drawable = await service.GetImageAsync(imageSource);

            var uiimage = Assert.IsType <UIImage>(drawable.Value);

            uiimage.AssertColorAtCenter(expectedColor.ToNative());
        }