Exemple #1
0
        public async Task FontFamilyInitializesCorrectly(string family)
        {
            var button = new ButtonStub
            {
                Text = "Test",
                Font = Font.OfSize(family, 10)
            };

            var handler = await CreateHandlerAsync(button);

            var nativeButton = GetNativeButton(handler);

            var fontManager = App.Services.GetRequiredService <IFontManager>();

            var nativeFont = fontManager.GetTypeface(Font.OfSize(family, 0.0));

            Assert.Equal(nativeFont, nativeButton.Typeface);

            if (string.IsNullOrEmpty(family))
            {
                Assert.Equal(fontManager.DefaultTypeface, nativeButton.Typeface);
            }
            else
            {
                Assert.NotEqual(fontManager.DefaultTypeface, nativeButton.Typeface);
            }
        }
Exemple #2
0
        public async Task InsertAddsChildToNativeLayout()
        {
            var layout = new LayoutStub();
            var slider = new SliderStub();
            var button = new ButtonStub();

            layout.Add(slider);

            var handler = await CreateHandlerAsync(layout);

            var children = await InvokeOnMainThreadAsync(() =>
            {
                return(GetNativeChildren(handler));
            });

            Assert.Equal(1, children.Count);
            Assert.Same(slider.Handler.NativeView, children[0]);

            children = await InvokeOnMainThreadAsync(() =>
            {
                handler.Insert(0, button);
                return(GetNativeChildren(handler));
            });

            Assert.Equal(2, children.Count);
            Assert.Same(button.Handler.NativeView, children[0]);
            Assert.Same(slider.Handler.NativeView, children[1]);
        }
Exemple #3
0
        public async Task PaddingInitializesCorrectly()
        {
            var button = new ButtonStub()
            {
                Text    = "Test",
                Padding = new Thickness(5, 10, 15, 20)
            };

            var handler = await CreateHandlerAsync(button);

            var appCompatButton = (AppCompatButton)handler.View;

            var(left, top, right, bottom) = (appCompatButton.PaddingLeft, appCompatButton.PaddingTop, appCompatButton.PaddingRight, appCompatButton.PaddingBottom);

            var context = handler.View.Context;

            var expectedLeft   = context.ToPixels(5);
            var expectedTop    = context.ToPixels(10);
            var expectedRight  = context.ToPixels(15);
            var expectedBottom = context.ToPixels(20);

            Assert.Equal(expectedLeft, left);
            Assert.Equal(expectedTop, top);
            Assert.Equal(expectedRight, right);
            Assert.Equal(expectedBottom, bottom);
        }
Exemple #4
0
        public async Task ClearRemovesChildrenFromNativeLayout()
        {
            var layout = new LayoutStub();
            var slider = new SliderStub();
            var button = new ButtonStub();

            layout.Add(slider);
            layout.Add(button);

            var handler = await CreateHandlerAsync(layout);

            var children = await InvokeOnMainThreadAsync(() =>
            {
                return(GetNativeChildren(handler));
            });

            Assert.Equal(2, children.Count);
            Assert.Same(slider.Handler.PlatformView, children[0]);
            Assert.Same(button.Handler.PlatformView, children[1]);

            var count = await InvokeOnMainThreadAsync(() =>
            {
                handler.Clear();
                return(GetNativeChildCount(handler));
            });

            Assert.Equal(0, count);
        }
Exemple #5
0
        public async Task UpdateNativeLayout()
        {
            var layout = new LayoutStub();
            var slider = new SliderStub();
            var button = new ButtonStub();

            layout.Add(slider);

            var handler = await CreateHandlerAsync(layout);

            var children = await InvokeOnMainThreadAsync(() =>
            {
                return(GetNativeChildren(handler));
            });

            Assert.Equal(1, children.Count);
            Assert.Same(slider.Handler.PlatformView, children[0]);

            children = await InvokeOnMainThreadAsync(() =>
            {
                layout[0] = button;
                handler.Update(0, button);
                return(GetNativeChildren(handler));
            });

            Assert.Equal(1, children.Count);
            Assert.Same(button.Handler.PlatformView, children[0]);
        }
Exemple #6
0
        public async Task TextInitializesCorrectly()
        {
            var button = new ButtonStub()
            {
                Text = "Test"
            };

            await ValidatePropertyInitValue(button, () => button.Text, GetNativeText, button.Text);
        }
Exemple #7
0
        public async Task TextColorInitializesCorrectly()
        {
            var button = new ButtonStub()
            {
                Text      = "Test",
                TextColor = Color.Orange
            };

            await ValidatePropertyInitValue(button, () => button.TextColor, GetNativeTextColor, button.TextColor);
        }
Exemple #8
0
        public void NextTick_AtStart_GetsFromButton()
        {
            var ticker = new Ticker(1, 0);
            var button = new ButtonStub <ButtonId> {
                IdVal = ButtonId.Bottom, NextTickVal = 1
            };
            var buttons = new List <IButton <ButtonId> > {
                button
            };

            var aggr = new ButtonAggregator(() => ticker, buttons);

            Assert.AreEqual(1, aggr.NextTick(0));
        }
Exemple #9
0
        public void ButtonAggregator_OnPinValueChange_TransmitToButton()
        {
            var ticker = new Ticker(1, 0);
            var button = new ButtonStub <ButtonId> {
                IdVal = ButtonId.Bottom
            };
            var buttons = new List <IButton <ButtonId> > {
                button
            };

            var aggr = new ButtonAggregator(
                () => ticker, buttons).OnPinValueChange(ButtonId.Bottom);

            Assert.IsTrue(button.OnPinValueChanged);
        }
Exemple #10
0
        public async Task ClickEventFires()
        {
            var clicked = false;

            var button = new ButtonStub();

            button.Clicked += delegate
            {
                clicked = true;
            };

            await PerformClick(button);

            Assert.True(clicked);
        }
Exemple #11
0
        public void Tick_UpdatedButton_StartsTicker()
        {
            var ticker = new Ticker(2, 0);
            var button = new ButtonStub <ButtonId> {
                IdVal = ButtonId.Bottom, NextTickVal = 1,
                Next  = new ButtonStub <ButtonId> {
                    IdVal = ButtonId.Bottom
                }
            };
            var buttons = new List <IButton <ButtonId> > {
                button
            };

            var aggr = new ButtonAggregator(() => ticker, buttons).Tick(0);

            Assert.AreEqual(2, aggr.NextTick(0));
        }
        public async Task PaddingInitializesCorrectly()
        {
            var expected = new Thickness(5, 10, 15, 20);

            var button = new ButtonStub()
            {
                Text    = "Test",
                Padding = expected
            };

            var actual = await GetValueAsync(button, GetNativePadding);

            Assert.Equal(expected.Left, actual.Left);
            Assert.Equal(expected.Top, actual.Top);
            Assert.Equal(expected.Right, actual.Right);
            Assert.Equal(expected.Bottom, actual.Bottom);
        }
Exemple #13
0
        public async Task ValidateDefaultAccessibilityTraits()
        {
            var view  = new ButtonStub();
            var trait = await GetValueAsync((IView)view,
                                            handler =>
            {
                // Accessibility Traits don't initialize until after
                // a UIView is added to the visual hierarchy so we are just
                // initializing here and then validating that the value doesn't get cleared

                handler.NativeView.AccessibilityTraits = UIAccessibilityTrait.Button;
                view.Semantics.Hint = "Test Hint";
                view.Handler.UpdateValue("Semantics");
                return(handler.NativeView.AccessibilityTraits);
            });

            Assert.Equal(UIAccessibilityTrait.Button, trait);
        }
Exemple #14
0
        public async Task PushMultiplePagesAtStart()
        {
            var page1 = new ButtonStub();
            var page2 = new ButtonStub();
            NavigationViewStub navigationViewStub = new NavigationViewStub()
            {
                NavigationStack = new List <IView>()
                {
                    page1, page2
                }
            };

            await CreateNavigationViewHandlerAsync(navigationViewStub, (handler) =>
            {
                Assert.Equal(2, GetNativeNavigationStackCount(handler));
                return(Task.CompletedTask);
            });
        }
Exemple #15
0
        public async Task PaddingInitializesCorrectly()
        {
            var button = new ButtonStub()
            {
                Text    = "Test",
                Padding = new Thickness(5, 10, 15, 20)
            };

            var handler = await CreateHandlerAsync(button);

            var uiButton = (UIButton)handler.NativeView;

            var insets = await InvokeOnMainThreadAsync(() => { return(uiButton.ContentEdgeInsets); });

            Assert.Equal(5, insets.Left);
            Assert.Equal(10, insets.Top);
            Assert.Equal(15, insets.Right);
            Assert.Equal(20, insets.Bottom);
        }
Exemple #16
0
        public void Tick_TickerEnd_UpdatesKey()
        {
            var ticker = new Ticker(2, 0);
            var button = new ButtonStub <ButtonId>
            {
                IdVal       = ButtonId.Bottom,
                NextTickVal = 1,
                Next        = new ButtonStub <ButtonId> {
                    IdVal = ButtonId.Bottom, PressedVal = true
                }
            };
            var buttons = new List <IButton <ButtonId> > {
                button
            };

            var aggr = new ButtonAggregator(() => ticker, buttons).Tick(0).Tick(2);

            Assert.AreEqual(KeyId.A, aggr.KeyState);
            Assert.AreEqual(null, aggr.NextTick(2));
        }
        public async Task IsVisibleUpdatesCorrectly()
        {
            var expected = Colors.Red;

            var layout = new LayoutStub();

            var hiddenButton = new ButtonStub
            {
                Text       = "Text",
                TextColor  = expected,
                Visibility = Visibility.Collapsed,
            };

            var button = new ButtonStub
            {
                Text = "Change IsVisible"
            };

            layout.Add(hiddenButton);
            layout.Add(button);

            var clicked = false;

            button.Clicked += delegate
            {
                hiddenButton.Visibility = Visibility.Visible;
                clicked = true;
            };

            await PerformClick(button);

            Assert.True(clicked);

            var result = await GetValueAsync(hiddenButton, GetVisibility);

            Assert.Equal(hiddenButton.Visibility, result);

            await ValidateHasColor(hiddenButton, expected);
        }
Exemple #18
0
        public async Task CharacterSpacingInitializesCorrectly()
        {
            string originalText          = "Test";
            var    xplatCharacterSpacing = 4;

            var button = new ButtonStub()
            {
                CharacterSpacing = xplatCharacterSpacing,
                Text             = originalText
            };

            var values = await GetValueAsync(button, (handler) =>
            {
                return(new
                {
                    ViewValue = button.CharacterSpacing,
                    NativeViewValue = GetNativeCharacterSpacing(handler)
                });
            });

            Assert.Equal(xplatCharacterSpacing, values.ViewValue);
            Assert.Equal(xplatCharacterSpacing, values.NativeViewValue);
        }
Exemple #19
0
        public async Task FontFamilyInitializesCorrectly(string family)
        {
            var button = new ButtonStub
            {
                Text = "Test",
                Font = Font.OfSize(family, 10)
            };

            var(services, nativeFont) = await GetValueAsync(button, handler => (handler.Services, GetNativeButton(handler).Font));

            var fontManager = services.GetRequiredService <IFontManager>();

            var expectedNativeFont = fontManager.GetFont(Font.OfSize(family, 0.0));

            Assert.Equal(expectedNativeFont.FamilyName, nativeFont.FamilyName);
            if (string.IsNullOrEmpty(family))
            {
                Assert.Equal(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName);
            }
            else
            {
                Assert.NotEqual(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName);
            }
        }
        public async Task CharacterSpacingInitializesCorrectly()
        {
            var xplatCharacterSpacing = 4;

            var button = new ButtonStub()
            {
                CharacterSpacing = xplatCharacterSpacing,
                Text             = "Test"
            };

            float expectedValue = button.CharacterSpacing.ToEm();

            var values = await GetValueAsync(button, (handler) =>
            {
                return(new
                {
                    ViewValue = button.CharacterSpacing,
                    PlatformViewValue = GetNativeCharacterSpacing(handler)
                });
            });

            Assert.Equal(xplatCharacterSpacing, values.ViewValue);
            Assert.Equal(expectedValue, values.PlatformViewValue, EmCoefficientPrecision);
        }