Exemplo n.º 1
0
            public async Task ReturnsResultsWithNameMatchingToken()
            {
                var obs = Observable.Return(new BitmapImage());

                var suggestions = new List <AutoCompleteSuggestion>
                {
                    new AutoCompleteSuggestion("rainbow", obs, ":", ":"),
                    new AutoCompleteSuggestion("poop", obs, ":", ":"),
                    new AutoCompleteSuggestion("poop_scoop", obs, ":", ":")
                }.ToObservable();

                var mentionsSource = Substitute.For <IAutoCompleteSource>();

                mentionsSource.GetSuggestions().Returns(Observable.Empty <AutoCompleteSuggestion>());
                mentionsSource.Prefix.Returns("@");

                var emojiSource = Substitute.For <IAutoCompleteSource>();

                emojiSource.GetSuggestions().Returns(suggestions);
                emojiSource.Prefix.Returns(":");

                var advisor = new AutoCompleteAdvisor(new[] { mentionsSource, emojiSource });

                var result = await advisor.GetAutoCompletionSuggestions("this is :poo", 12);

                Assert.AreEqual(8, result.Offset);
                Assert.AreEqual(2, result.Suggestions.Count);
                Assert.AreEqual("poop", result.Suggestions[0].Name);
                Assert.AreEqual("poop_scoop", result.Suggestions[1].Name);
            }
Exemplo n.º 2
0
            public async Task ReturnsEmptyAutoCompleteResult(string text, int caretIndex)
            {
                var autoCompleteSource = Substitute.For <IAutoCompleteSource>();

                autoCompleteSource.GetSuggestions().Returns(Observable.Empty <AutoCompleteSuggestion>());
                autoCompleteSource.Prefix.Returns(":");

                var advisor = new AutoCompleteAdvisor(new[] { autoCompleteSource });

                var result = await advisor.GetAutoCompletionSuggestions(text, 0);

                Assert.AreSame(AutoCompleteResult.Empty, result);
            }
Exemplo n.º 3
0
            public async Task ReturnsEmptyAutoCompleteResultWhenSourceThrowsException()
            {
                var autoCompleteSource = Substitute.For <IAutoCompleteSource>();

                autoCompleteSource.GetSuggestions().Returns(Observable.Throw <AutoCompleteSuggestion>(new Exception("FAIL!")));
                autoCompleteSource.Prefix.Returns("@");

                var advisor = new AutoCompleteAdvisor(new[] { autoCompleteSource });

                var result = await advisor.GetAutoCompletionSuggestions("@", 1);

                Assert.AreSame(AutoCompleteResult.Empty, result);
            }
Exemplo n.º 4
0
            public async Task ReturnsMentionsInCorrectOrder()
            {
                var obs = Observable.Return(new BitmapImage());

                var suggestions = new List <AutoCompleteSuggestion>
                {
                    // We need to have more than 10 matches to ensure we grab the most appropriate top ten
                    new AutoCompleteSuggestion("zztop1", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop2", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop3", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop4", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop5", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop6", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop7", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop8", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop9", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("zztop10", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("rainbowbright", "Jimmy Alice Cooper", obs, "@", ""),
                    new AutoCompleteSuggestion("apricot", "Bob Rainbow", obs, "@", ""),
                    new AutoCompleteSuggestion("rainbow", "John Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("poop_scoop", obs, "@", ""),
                    new AutoCompleteSuggestion("zeke", "RainbowBright Doe", obs, "@", ""),
                    new AutoCompleteSuggestion("bill", "RainbowBright Doe", obs, "@", "")
                }.ToObservable();

                var mentionsSource = Substitute.For <IAutoCompleteSource>();

                mentionsSource.GetSuggestions().Returns(suggestions);
                mentionsSource.Prefix.Returns("@");

                var emojiSource = Substitute.For <IAutoCompleteSource>();

                emojiSource.GetSuggestions().Returns(Observable.Empty <AutoCompleteSuggestion>());
                emojiSource.Prefix.Returns(":");

                var advisor = new AutoCompleteAdvisor(new[] { mentionsSource, emojiSource });

                var result = await advisor.GetAutoCompletionSuggestions("this is @rainbow sucka", 16);

                Assert.AreEqual("rainbow", result.Suggestions[0].Name);
                Assert.AreEqual("rainbowbright", result.Suggestions[1].Name);
                Assert.AreEqual("apricot", result.Suggestions[2].Name);
                Assert.AreEqual("bill", result.Suggestions[3].Name); // Bill and Zeke have the same name
                Assert.AreEqual("zeke", result.Suggestions[4].Name); // but the secondary sort is by login
            }