public async Task <WordTranslationFullStringsModel> GetWordFullInformationStringsAsync(string word, int originalLangId, int translationLangId)
        {
            WordTranslationFullStringsModel infoWord = new WordTranslationFullStringsModel
            {
                OriginalWord = word
            };

            using (var uow = unitOfWorkFactory.GetUnitOfWork())
            {
                WordTranslation wordTr = await uow.WordTranslationRepository.GetAll()
                                         .Where(x => x.OriginalWord.Value == word && x.OriginalWord.LanguageId == originalLangId &&
                                                x.TranslationWord.LanguageId == translationLangId)
                                         .FirstOrDefaultAsync();

                infoWord.Description   = wordTr.OriginalWord.Description;
                infoWord.Transcription = wordTr.OriginalWord.Transcription;
                infoWord.PartOfSpeech  = wordTr.OriginalWord.PartOfSpeech.Name;
                infoWord.Comment       = wordTr.OriginalWord.Comment;

                List <string> translations = uow.WordTranslationRepository.GetAll()
                                             .Where(x => x.OriginalWord.Value == word && x.OriginalWord.LanguageId == originalLangId &&
                                                    x.TranslationWord.LanguageId == translationLangId)
                                             .Select(x => x.TranslationWord.Value)
                                             .ToList();
                infoWord.Translations = translations.Count > 0 ? translations : null;

                List <string> synonyms = uow.WordTranslationRepository.GetAll()
                                         .Where(x => x.OriginalWord.Value == word && x.OriginalWord.LanguageId == originalLangId &&
                                                x.TranslationWord.LanguageId == originalLangId)
                                         .Select(x => x.TranslationWord.Value)
                                         .ToList();
                infoWord.Synonims = synonyms.Count > 0 ? synonyms : null;

                List <string> tags = wordTr.OriginalWord.Tags.Select(x => x.Name).ToList();
                infoWord.Tags = tags.Count > 0 ? tags : null;
            }
            return(infoWord);
        }
Example #2
0
        public async void GetWordFullInformationStringsAsync_ReturnsWord()
        {
            //Arrange
            string word         = "word";
            string description  = "word";
            string transl       = "слово";
            string synon        = "phrase";
            int    originLangId = 1;
            int    translLangId = 4;

            Word translation = new Word()
            {
                Id         = 2,
                Value      = transl,
                LanguageId = translLangId
            };
            Word synonim = new Word()
            {
                Id         = 3,
                Value      = synon,
                LanguageId = originLangId
            };

            IQueryable <WordTranslation> wordTranslations = new List <WordTranslation>
            {
                new WordTranslation
                {
                    OriginalWordId = 1,
                    OriginalWord   = new Word
                    {
                        Value       = word,
                        Description = description,
                        LanguageId  = originLangId
                    },
                    TranslationWord = translation
                },
                new WordTranslation
                {
                    OriginalWordId = 1,
                    OriginalWord   = new Word
                    {
                        Value       = word,
                        Description = description,
                        LanguageId  = originLangId
                    },
                    TranslationWord = synonim
                }
            }.AsQueryable <WordTranslation>();

            WordTranslationFullStringsModel expected = new WordTranslationFullStringsModel
            {
                OriginalWord = word,
                Description  = description,
                Translations = new List <string>
                {
                    transl
                },
                Synonims = new List <string>
                {
                    synon
                }
            };

            var mockSet = GenerateMockDbSet <WordTranslation>(wordTranslations);

            _repo.Setup(x => x.GetAll()).Returns(mockSet.Object);


            //Act
            var actual = await _service.GetWordFullInformationStringsAsync(word, originLangId, translLangId);

            //Assert
            Assert.AreEqual(expected.OriginalWord, actual.OriginalWord);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.Transcription, actual.Transcription);
            CollectionAssert.AreEqual(expected.Translations, actual.Translations);
            CollectionAssert.AreEqual(expected.Synonims, actual.Synonims);

            _factory.Verify(x => x.GetUnitOfWork(), Times.Once);
            _uow.Verify(x => x.WordTranslationRepository, Times.Exactly(3));
            _repo.Verify(x => x.GetAll(), Times.Exactly(3));
        }