Esempio n. 1
0
        public void FindWords(string text, string prefix, string trueListWords)
        {
            DBDictionaryWord dbContext = new DBDictionaryWord();
            IGenericRepository <DictionaryWord> repo = new GenericRepository <DictionaryWord>(dbContext);
            BaseManagerDictionary manager            = new ManagerDictionary(repo);

            if (repo.Get().Any())
            {
                manager.DeleteDictionary();
            }

            manager.CreateDictionary(text);

            List <DictionaryWord> words = manager.FindWords(prefix).ToList();


            StringBuilder result = new StringBuilder();

            foreach (var word in words)
            {
                result.Append(word.Word).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueListWords);
        }
Esempio n. 2
0
        public void FindWords(string text, string prefix, string trueListWords)
        {
            IGenericRepository <DictionaryWord> repo = new FakeRepository();
            ManagerDictionary manager = new ManagerDictionary(repo);


            manager.CreateDictionary(text);

            List <DictionaryWord> words = manager.FindWords(prefix).ToList();


            StringBuilder result = new StringBuilder();

            foreach (var word in words)
            {
                result.Append(word.Word).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueListWords);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            /* IUnityContainer container = new UnityContainer();
             * container.RegisterType<DetectEncodingType>(new ContainerControlledLifetimeManager());
             * container.RegisterType<DetectEncodingTypeUTF8>(new ContainerControlledLifetimeManager());
             * container.RegisterType<DBDictionaryWord> (new ContainerControlledLifetimeManager());
             * container.RegisterType<IGenericRepository<DictionaryWord>, GenericRepository<DictionaryWord>>();
             * container.RegisterType<BaseManagerDictionary, ManagerDictionary>(new ContainerControlledLifetimeManager());*/



            if (args.Length != 0)
            {
                //Если есть команды
                try
                {
                    var commandLineApplication = InitCommandLine(args);
                    commandLineApplication.Execute(args);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Environment.Exit(0);
                    return;
                }
            }

            //без параметров командной строки, при этом оно должно автоматически переходить в режим ввода, стандартный поток ввода – с клавиатуры
            StringBuilder  prefix = new StringBuilder();
            ConsoleKeyInfo info;

            while (true)
            {
                info = Console.ReadKey(true);
                Console.Write(info.KeyChar);

                if (info.Key == ConsoleKey.Enter && prefix.Length == 0 || info.Key == ConsoleKey.Escape)//выход при нажатии Esc или ввода пустой строки
                {
                    Environment.Exit(0);
                    break;
                }
                else
                if (info.Key == ConsoleKey.Enter && prefix.Length > 0)//ввели не пустую строку
                {
                    List <DictionaryWord> arrayWords;
                    try
                    {
                        DBDictionaryWord dbContext = new DBDictionaryWord();
                        IGenericRepository <DictionaryWord> repo = new GenericRepository <DictionaryWord>(dbContext);
                        BaseManagerDictionary manager            = new ManagerDictionary(repo);

                        //  var manager=container.Resolve<ManagerDictionary>();
                        arrayWords = manager.FindWords(prefix.ToString()).ToList();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Environment.Exit(0);
                        return;
                    }

                    Console.WriteLine();

                    foreach (var word in arrayWords)
                    {
                        Console.WriteLine("- " + word.Word);
                    }
                    prefix.Clear();
                }
                else
                {
                    prefix.Append(info.KeyChar);//собираем символы ввода не esc и не enter
                }
            }
        }