コード例 #1
0
        public async Task ThrowsForIncorrectTypes(Type type)
        {
            var service = new StreamImageSourceService();

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

            await Assert.ThrowsAsync <InvalidCastException>(() => service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext));
        }
コード例 #2
0
        public async Task GetDrawableAsync(string colorHex)
        {
            var expectedColor = Color.FromArgb(colorHex).ToNative();

            var service = new StreamImageSourceService();

            var imageSource = new StreamImageSourceStub(CreateBitmapStream(100, 100, expectedColor));

            using var drawable = await service.GetDrawableAsync(imageSource, Platform.DefaultContext);

            var bitmapDrawable = Assert.IsType <BitmapDrawable>(drawable.Value);

            var bitmap = bitmapDrawable.Bitmap;

            bitmap.AssertColorAtCenter(expectedColor);
        }