示例#1
0
        public async Task UpdatingSourceOnlyUpdatesDrawableTwice()
        {
            var image = new ImageStub
            {
                Background = new SolidPaintStub(Colors.Black),
                Source     = new FileImageSourceStub("red.png"),
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Red);

                handler.ImageEvents.Clear();

                image.Source = new FileImageSourceStub("blue.png");
                handler.UpdateValue(nameof(IImage.Source));

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Blue);

                Assert.Equal(2, handler.ImageEvents.Count);
                Assert.Equal("Image", handler.ImageEvents[0].Member);
                Assert.Null(handler.ImageEvents[0].Value);
                Assert.Equal("Image", handler.ImageEvents[1].Member);
                Assert.IsType <UIImage>(handler.ImageEvents[1].Value);
            });
        }
        public async Task UpdatingSourceOnlyUpdatesDrawableTwice()
        {
            var image = new ImageStub
            {
                BackgroundColor = Colors.Black,
                Source          = new FileImageSourceStub("red.png"),
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Red);

                handler.ImageEvents.Clear();

                image.Source = new FileImageSourceStub("blue.png");
                handler.UpdateValue(nameof(IImage.Source));

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Blue);

                Assert.Equal(2, handler.ImageEvents.Count);
                Assert.Equal("SetImageResource", handler.ImageEvents[0].Member);
                Assert.Equal(Android.Resource.Color.Transparent, handler.ImageEvents[0].Value);
                Assert.Equal("SetImageDrawable", handler.ImageEvents[1].Member);
                Assert.IsType <BitmapDrawable>(handler.ImageEvents[1].Value);
            });
        }
示例#3
0
        public async Task InitializingNullSourceOnlyUpdatesNull(string colorHex)
        {
            var expectedColor = Color.FromHex(colorHex);

            var image = new ImageStub
            {
                Background = new SolidPaintStub(expectedColor),
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                Assert.Single(handler.ImageEvents);
                Assert.Equal("Image", handler.ImageEvents[0].Member);
                Assert.Null(handler.ImageEvents[0].Value);

                await handler.NativeView.AssertContainsColor(expectedColor);
            });
        }
        public async Task InitializingNullSourceOnlyUpdatesTransparent(string colorHex)
        {
            var expectedColor = Color.FromHex(colorHex);

            var image = new ImageStub
            {
                BackgroundColor = expectedColor,
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                Assert.Single(handler.ImageEvents);
                Assert.Equal("SetImageResource", handler.ImageEvents[0].Member);
                Assert.Equal(Android.Resource.Color.Transparent, handler.ImageEvents[0].Value);

                await handler.NativeView.AssertContainsColor(expectedColor);
            });
        }
示例#5
0
        public async Task InitializingSourceOnlyUpdatesImageOnce()
        {
            var image = new ImageStub
            {
                BackgroundColor = Colors.Black,
                Source          = new FileImageSourceStub("red.png"),
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Red);

                Assert.Equal(2, handler.ImageEvents.Count);
                Assert.Equal("Image", handler.ImageEvents[0].Member);
                Assert.Null(handler.ImageEvents[0].Value);
                Assert.Equal("Image", handler.ImageEvents[1].Member);
                Assert.IsType <UIImage>(handler.ImageEvents[1].Value);
            });
        }