public static void Verify_ThatEachMonth_HasAValidGenerator()
        {
            var suggestionGenerators = new List <ISuggestionsGenerator>
            {
                new JanuarySuggestionsGenerator(),
                new FebruarySuggestionsGenerator(),
                new MarchSuggestionsGenerator(),
                new AprilSuggestionsGenerator(),
                new MaySuggestionsGenerator(),
                new JuneSuggestionsGenerator(),
                new JulySuggestionsGenerator(),
                new AugustSuggestionsGenerator(),
                new SeptemberSuggestionsGenerator(),
                new OctoberSuggestionsGenerator(),
                new NovemberSuggestionsGenerator(),
                new DecemberSuggestionsGenerator()
            };

            ISuggestionsProvider suggestionsProvider = new SuggestionsProvider(suggestionGenerators);

            int validMonths = 0;

            for (var month = 1; month <= 12; month += 1)
            {
                try
                {
                    suggestionsProvider.Provide(new DateTime(2018, month, 1));

                    validMonths++;
                }
                catch (Exception)
                {
                    Assert.Fail($"No generator found for month: {month}");
                }
            }

            Assert.AreEqual(12, validMonths);
            Assert.AreEqual(12, suggestionGenerators.Count);
        }
示例#2
0
        private async void TimerOnTick(object sender, EventArgs eventArgs)
        {
            _timer.Stop();

            if (SuggestionsProvider == null)
            {
                return;
            }

            // If active request, cancel it.
            _cts?.Cancel();

            // Start a request.
            _cts = new CancellationTokenSource();

            _items = await SuggestionsProvider.GetSuggestions(Text, _cts.Token);

            HasItems = _items != null && _items.Length > 0;

            if (_cts == null || _cts.IsCancellationRequested)
            {
                _cts = null;
                return;
            }
            _cts = null;

            // No reason to search if we don't have any values.
            if (_items == null)
            {
                return;
            }
            _selector.ItemsSource = _items;

            // Do search and changes here.
            string match    = null;
            int    matchPos = -1;

            foreach (var obj in _items)
            {
                var str = GetDisplayText(obj);
                matchPos = str.IndexOf(Text, StringComparison.OrdinalIgnoreCase);
                if (matchPos != -1)
                {
                    match = str;
                    break;
                }
            }

            // No match.  Leave them alone.
            if (string.IsNullOrEmpty(match))
            {
                return;
            }

            //TextChanged -= OnTextChanged;

            if (IsKeyboardFocusWithin)
            {
                // If Text == SelectedValue, don't open because the value was just selected.
                if (Text == GetDisplayText(_selector.SelectedValue))
                {
                    _popup.IsOpen = false;
                }
                else
                {
                    OpenPopup();
                    if (_selector.SelectedIndex == -1)
                    {
                        _selector.SelectedIndex = 0;
                    }
                }
            }
            else
            {
                _popup.IsOpen = false;
            }

            //Text = match;
            //CaretIndex = textLength;
            //SelectionStart = matchPos;
            //SelectionLength = textLength;
            //TextChanged += OnTextChanged;
        }