예제 #1
0
        public void TestFindTranslateWithEffort()
        {
            int roomDictonary = 0;
            string searchWord = "кот";
            string[] translate = new string[] { "cat" };
            string[] exrectedTranslate = { "cat" };

            using (var connection = DbConnectionFactory.CreateTransient())
            {
                context = new DictonaryContext(connection);

                IDictonaryRepository repository = new DictonaryRepository(context);

                EngDictonary engWord = new EngDictonary() { Id = 1, Word = "cat", Words = null };
                RusDictonary word = new RusDictonary() { Id = 1, Word = searchWord, Words = new Collection<EngDictonary>() { engWord } };
                context.RusDictonaries.Add(word);
                context.SaveChanges();

                try
                {
                    var actualTranslate = repository.FindTranslateIntoDb(roomDictonary, searchWord);
                    Assert.IsNotNull(actualTranslate);
                    CollectionAssert.AreEquivalent(exrectedTranslate, actualTranslate);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
예제 #2
0
 public string[] FindTranslateIntoDb(int roomDictonary, string searchWord)
 {
     EngDictonary engWord = new EngDictonary() { Id = 1, Word = "cat", Words = null };
     RusDictonary word = new RusDictonary() { Id = 1, Word = searchWord, Words = new Collection<EngDictonary>() { engWord } };
     rusDictonary.Add(word);
     var result = rusDictonary.Where(rd => rd.Word == searchWord)
             .SelectMany(rd => rd.Words)
             .Select(ew => ew.Word)
             .ToArray();
     return result;
 }
예제 #3
0
        public bool AddWordToDb(int roomDictonary, string newWord)
        {
            RusDictonary word = new RusDictonary() { Id = 1, Word = newWord, Words = null };
            rusDictonary.Add(word);

            if (rusDictonary.Contains(word))
            {
                return true;
            }

            return false;
        }
예제 #4
0
        public bool DeleteWordFromDb(int roomDictonary, string deleteWord)
        {
            RusDictonary word = new RusDictonary() { Id = 1, Word = deleteWord, Words = null };
            rusDictonary.Add(word);
            rusDictonary.Remove(word);

            if (rusDictonary.Contains(word))
            {
                return false;
            }

            return true;
        }