public void SaveForExams(string word, string transcription, string[] translations, string[] allMeanings, Phrase[] phrases = null) { var alreadyExists = _repository.GetOrNull(word); if (alreadyExists == null) { _repository.CreateNew(word, string.Join(", ", translations), allMeanings, transcription, phrases); } else { var updatedTranslations = alreadyExists .Translation .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Union(translations) .ToArray(); alreadyExists.Translation = string.Join(", ", updatedTranslations); alreadyExists.OnExamFailed(); _repository.UpdateScoresAndTranslation(alreadyExists); } }
public void GetOrNullPair_ReturnsPhrase() { var repo = new WordsRepository("test"); repo.ApplyMigrations(); repo.CreateNew("word", "translation", "trans", new[] { new Phrase() { Created = DateTime.Now, Origin = "what is word", OriginWord = "word", Translation = "trans is trans", TranslationWord = "trans" } }); var word = repo.GetOrNullWithPhrases("word"); Assert.IsNotNull(word.Phrases); Assert.AreEqual(1, word.Phrases.Count); Assert.AreEqual("what is word", word.Phrases[0].Origin); }
public void GetWorst10_ReturnsPhrase() { var repo = new WordsRepository("test"); repo.ApplyMigrations(); repo.CreateNew("word", "translation", "trans", new[] { new Phrase() { Created = DateTime.Now, Origin = "what is word", OriginWord = "word", Translation = "trans is trans", TranslationWord = "trans" }, new Phrase() { Created = DateTime.Now, Origin = "what is word 2", OriginWord = "word", Translation = "trans is trans 2", TranslationWord = "trans" }, }); repo.CreateNew("word2", "translation2", "trans", new[] { new Phrase() { Created = DateTime.Now, Origin = "what is word", OriginWord = "word2", Translation = "trans is trans", TranslationWord = "trans2" }, new Phrase() { Created = DateTime.Now, Origin = "what is word 2", OriginWord = "word2", Translation = "trans is trans 2", TranslationWord = "trans2" }, }); repo.CreateNew("word3", "translation3", "trans", new[] { new Phrase() { Created = DateTime.Now, Origin = "what is word", OriginWord = "word3", Translation = "trans is trans", TranslationWord = "trans3" }, new Phrase() { Created = DateTime.Now, Origin = "what is word 3", OriginWord = "word3", Translation = "trans is trans 3", TranslationWord = "trans3" }, }); var words = repo.GetWorst(2); Assert.IsNotNull(words); Assert.AreEqual(2, words.Length); }