Ejemplo n.º 1
0
        public bool AddWordToDb(int roomDictonary, string newWord)
        {
            try
            {
                if (roomDictonary == 0)
                {
                    bool exists = db.RusDictonaries.Select(rd => rd.Word).Any(w => w == newWord);

                    if (!exists)
                    {
                        db.RusDictonaries.Add(new RusDictonary {
                            Word = newWord
                        });
                        db.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    bool exists = db.EngDictonaries.Select(rd => rd.Word).Any(w => w == newWord);

                    if (!exists)
                    {
                        db.EngDictonaries.Add(new EngDictonary {
                            Word = newWord
                        });
                        db.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                throw new FaultException("Возникла ошибка ,слово не было добавлено в БД ! ");
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }