public async Task AddOne_GetAllReturnsIt() { var example = CreateExample("table", "стол"); await _repo.Add(example); var all = await _repo.GetAll(new[] { example.Id }); Assert.AreEqual(1, all.Count); var read = all.First(); Assert.AreEqual(example.OriginPhrase, read.OriginPhrase); Assert.AreEqual(example.OriginWord, read.OriginWord); Assert.AreEqual(example.TranslatedPhrase, read.TranslatedPhrase); Assert.AreEqual(example.TranslatedWord, read.TranslatedWord); }
private async Task IncludeExamples(IReadOnlyCollection <UserWord> words) { var ids = new List <ObjectId>(); foreach (var word in words) { foreach (var translation in word.Translations) { ids.AddRange(translation.Examples.Select(e => e.ExampleId)); } } var examples = (await _examplesRepo.GetAll(ids)).ToDictionary(e => e.Id); foreach (var word in words) { foreach (var translation in word.Translations) { foreach (var example in translation.Examples) { example.ExampleOrNull = examples[example.ExampleId]; } } } }
public async Task <IReadOnlyList <DictionaryTranslation> > GetTranslationsWithExamples(string enword) { var word = await _dicRepository.GetOrDefault(enword); if (word == null) { return(new DictionaryTranslation[0]); } var result = new List <DictionaryTranslation>(); foreach (var translation in word.Translations) { var examples = translation.Examples.Length > 0 ? await _exampleRepository.GetAll(translation.Examples.Select(e => e.ExampleId)) : new List <Example>(); result.Add(new DictionaryTranslation( word.Word, translation.Word, word.Transcription, word.Source, examples)); } return(result); }