Пример #1
0
        public async Task <bool> Handle(WordFamiliarityUpsertBatch request, CancellationToken cancellationToken)
        {
            new WordFamiliarityUpsertBatchValidator().ValidateAndThrow(request);

            await WordSelector.EnsureWordsCreated(DB, Mapper, request.Words, cancellationToken);

            await DB.Unsafe.SaveChangesAsync(cancellationToken);

            if (request.Level == 0)
            {
                // Not sure why but this doesn't run.
                //    System.ArgumentException : Field '_queryCompiler' defined on type 'Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider' is not a field on the target object which is of type 'LinqKit.ExpandableQueryProvider`1[ReadABit.Infrastructure.Models.WordFamiliarity]'.
                // await DB.WordFamiliaritiesOfUser(request.UserId)
                //     .OfWords(request.Words)
                //     .DeleteAsync(cancellationToken);

                var wordFamiliarityIds = await DB.WordFamiliaritiesOfUser(request.UserId)
                                         .OfWords(request.Words)
                                         .Select(wf => wf.Id)
                                         .ToListAsync(cancellationToken);

                await DB.WordFamiliaritiesOfUser(request.UserId)
                .Where(wf => wordFamiliarityIds.Contains(wf.Id))
                .DeleteAsync(cancellationToken);

                return(true);
            }

            await UpsertWordFamiliarity(request, cancellationToken);

            return(true);
        }
Пример #2
0
 public static IQueryable <Word> OfWord(this IQueryable <Word> query, WordSelector selector)
 {
     return(query
            .Where(w =>
                   w.LanguageCode == selector.LanguageCode &&
                   w.Expression == selector.Expression.Normalize()
                   ));
 }
Пример #3
0
 public static IQueryable <T> OfWord <T>(this IQueryable <T> query, WordSelector selector) where T : IOfWord
 {
     return(query
            .Where(wd =>
                   wd.Word.LanguageCode == selector.LanguageCode &&
                   wd.Word.Expression == selector.Expression.Normalize()
                   ));
 }
Пример #4
0
            public void ShouldReturnOnlyAlphabeticValues_WhenIsFilteringAlphabeticIsTrueAndOthersAreSetToFalse()
            {
                // Given
                var textRange = CreateTextRange("hello 10! how are you? I am 55 years old.");
                var underTest = new WordSelector();

                underTest.ApplyAttributes(new[] { new SelectorAttribute("alphabetic", true) });

                // When
                var result = underTest.SelectElement(textRange).Select(range => range.GetText());

                // Then
                Assert.That(result, Is.EquivalentTo(new[] { "hello", "how", "are", "you", "I", "am", "years", "old" }));
            }
Пример #5
0
            public void ShouldReturnSeparatedWordsOfSpecifiedText_WhenEveryAttributeHasDefaultValue()
            {
                // Given
                var textRange = CreateTextRange("hello world, how\nare\r\nyou?!Fine (thanks).");
                var underTest = new WordSelector();

                // When
                var result = underTest.SelectElement(textRange).Select(range => range.GetText());

                // Then
                Assert.That(result, Is.EquivalentTo(new[]
                {
                    "hello", "world", "how", "are", "you", "Fine", "thanks"
                }));
            }
Пример #6
0
 public static Task <Guid> IdOfWord(this IQueryable <Word> query, WordSelector selector, CancellationToken cancellationToken)
 {
     return(query.OfWord(selector)
            .Select(w => w.Id)
            .SingleOrDefaultAsync(cancellationToken: cancellationToken));
 }
Пример #7
0
 public void OnPointerExit(PointerEventData eventData)
 {
     backgroundImage.color = UI_Manager.WordObjectNormalColor;
     WordSelector.TogglePopupCurentLink(string.Empty);
 }
Пример #8
0
 public void WordList_OnlyAcceptsFiveLetters()
 {
     WordSelector wordSelector = new WordSelector();
     var selectedWord = wordSelector.SelectWord(new List<string> { "bread", "take", "maples" });
     Assert.Equal("BREAD", selectedWord);
 }
Пример #9
0
 public void OnPointerEnter(PointerEventData eventData)
 {
     backgroundImage.color = UI_Manager.WordObjectHighlightColor;
     WordSelector.TogglePopupCurentLink(word);
 }
Пример #10
0
 public void WordList_EmptyList_ReturnsEmpty()
 {
     WordSelector wordSelector = new WordSelector();
     var selectedWord = wordSelector.SelectWord(new List<string>());
     Assert.Equal("", selectedWord);
 }
Пример #11
0
 public void WordList_IgnoresCase()
 {
     WordSelector wordSelector = new WordSelector();
     var selectedWord = wordSelector.SelectWord(new List<string> { "bread" });
     Assert.Equal("BREAD", selectedWord);
 }
Пример #12
0
 public void SelectedWord_SelectsWordFromList()
 {
     WordSelector wordSelector = new WordSelector();
     var selectedWord = wordSelector.SelectWord(new List<string> { "bread", "apple" });
     Assert.NotNull(selectedWord);
 }
Пример #13
0
 public void SelectedWord_DoesNotContainMultipleLetters()
 {
     WordSelector wordSelector = new WordSelector();
     var selectedWord = wordSelector.SelectWord(new List<string> { "apple", "bread" });
     Assert.Equal("BREAD", selectedWord);
 }
Пример #14
0
 public Setting(WordSelector.WordSelector selector)
 {
     this.selector = selector;
     InitializeComponent();
 }
Пример #15
0
 public CommandChangeDistribution(WordSelector.WordSelector selector)
     : base(".distribution","change distribution (left  , right , median)")
 {
     this.selector = selector;
 }
Пример #16
0
 public CommandResetRandomSequence(WordSelector.WordSelector selector)
     : base(".reset","reset random sequence")
 {
     this.selector=selector;
 }