public void AllowMultiple_HasMultipleSelectedViews()
        {
            var view = new SelectorView
            {
                AllowMultiple = true,
                ItemsSource   = GetItems(),
                ItemTemplate  = new SelectableDataTemplateSelector()
            };

            Assert.Null(view.SelectedItem);

            Assert.Single(view.SelectedItems);

            var firstView = view.Children[0];

            Assert.IsType <IsNotSelectedViewMock>(firstView);
            var tappedGesture = firstView.GestureRecognizers.First(g => g is TapGestureRecognizer) as TapGestureRecognizer;

            Assert.NotNull(tappedGesture);

            tappedGesture.SendTapped(firstView);
            Assert.Null(view.SelectedItem);
            Assert.Equal(2, view.SelectedItems.Count);
            Assert.Equal(2, view.Children.Where(v => v is IsSelectedViewMock).Count());

            tappedGesture.SendTapped(firstView);
            Assert.Single(view.SelectedItems);
            Assert.Single(view.Children.Where(v => v is IsSelectedViewMock));
        }
Exemple #2
0
 internal ReplaceDefaultQualifierOperation(AIUI ui, QualifierView oldValue, QualifierView newValue, SelectorView target)
     : base(ui)
 {
     _target   = target;
     _oldValue = oldValue;
     _newValue = newValue;
 }
        public void AllowOne_OnlyHasSingleSelectedView()
        {
            var view = new SelectorView
            {
                ItemsSource   = GetItems(),
                ItemTemplate  = new SelectableDataTemplateSelector(),
                AllowMultiple = false
            };

            var selectedItem = view.SelectedItem;

            Assert.NotNull(selectedItem);

            var firstView = view.Children[0];

            Assert.IsType <IsNotSelectedViewMock>(firstView);

            var tappedGesture = firstView.GestureRecognizers.First(g => g is TapGestureRecognizer) as TapGestureRecognizer;

            Assert.NotNull(tappedGesture);
            tappedGesture.SendTapped(firstView);

            Assert.NotEqual(selectedItem, view.SelectedItem);

            Assert.Single(view.Children.Where(v => v is IsSelectedViewMock));
        }
 internal ReplaceSelectorOperation(AIUI ui, Selector oldValue, Selector newValue, SelectorView target)
     : base(ui)
 {
     _target   = target;
     _oldValue = oldValue;
     _newValue = newValue;
 }
        public void EachChildHasTappedGesture()
        {
            var view = new SelectorView
            {
                ItemsSource = GetItems()
            };

            foreach (var child in view.Children)
            {
                TestOutputHelper.WriteLine($"Selectable Item: {((SelectableMock)child.BindingContext).Name}");

                Assert.NotEmpty(child.GestureRecognizers);
                var tappedGesture = (TapGestureRecognizer)child.GestureRecognizers.FirstOrDefault(g => g is TapGestureRecognizer);
                Assert.NotNull(tappedGesture);
                Assert.Equal(child.BindingContext, tappedGesture.CommandParameter);
            }
        }
 protected override void OnViewAttached(object view, object context)
 {
     selView = view as SelectorView;
     var rs = Application.Current.RootVisual.RenderSize;
     selView.MaxHeight = System.Math.Max(rs.Height, rs.Width);
     selView.MaxWidth = selView.MaxHeight;
     base.OnViewAttached(view, context);
 }
 internal AddSelectorOperation(AIUI ui, SelectorView target)
     : base(ui)
 {
     _target = target;
 }