Exemplo n.º 1
0
        public void CreateDictionary(string text, string trueResult)
        {
            /* var mockDbSet = new Mock<DbSet<DictionaryWord>>();
             *
             * var dbSetContent = new List<DictionaryWord>();
             *
             * mockDbSet.As<IQueryable<DictionaryWord>>().Setup(m => m.Provider).Returns(dbSetContent.AsQueryable().Provider);
             * mockDbSet.As<IQueryable<DictionaryWord>>().Setup(m => m.Expression).Returns(dbSetContent.AsQueryable().Expression);
             * mockDbSet.As<IQueryable<DictionaryWord>>().Setup(m => m.ElementType).Returns(dbSetContent.AsQueryable().ElementType);
             * mockDbSet.As<IQueryable<DictionaryWord>>().Setup(m => m.GetEnumerator()).Returns(() => dbSetContent.GetEnumerator());
             * mockDbSet.Setup(m => m.Add(It.IsAny<DictionaryWord>())).Callback<DictionaryWord>((s) => dbSetContent.Add(s));
             * mockDbSet.Setup(m => m.Remove(It.IsAny<DictionaryWord>())).Callback<DictionaryWord>((s) => dbSetContent.Remove(s));
             *
             * var mockDbContext = new Mock<DBDictionaryWord>();
             *
             * mockDbContext.Setup(c => c.Set<DictionaryWord>()).Returns(mockDbSet.Object);
             *
             * GenericRepository<DictionaryWord> repoDictionaryWord = new GenericRepository<DictionaryWord>(mockDbContext.Object);*/
            IGenericRepository <DictionaryWord> repoDictionaryWord = new FakeRepository();
            ManagerDictionary manager = new ManagerDictionary(repoDictionaryWord);

            manager.CreateDictionary(text);

            StringBuilder result = new StringBuilder();

            foreach (var word in repoDictionaryWord.Get())
            {
                result.Append(word.Word).Append(" ").Append(word.Frequency).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueResult);
        }
Exemplo n.º 2
0
        [TestCase("жил жил  ", "жил жил ", "")]                       //0 + 0
        public void UpdateDictionary(string text1, string text2, string trueResult)
        {
            /*  IUnityContainer container = new UnityContainer();
             *
             * container.RegisterType<DBDictionaryWord>(new ContainerControlledLifetimeManager());
             * container.RegisterType<IGenericRepository<DictionaryWord>, GenericRepository<DictionaryWord>>();
             * container.RegisterType<BaseManagerDictionary, ManagerDictionary>(new ContainerControlledLifetimeManager());
             * var repo = container.Resolve<GenericRepository<DictionaryWord>>();
             * var manager = container.Resolve<ManagerDictionary>();*/
            DBDictionaryWord dbContext = new DBDictionaryWord();
            IGenericRepository <DictionaryWord> repo = new GenericRepository <DictionaryWord>(dbContext);
            BaseManagerDictionary manager            = new ManagerDictionary(repo);

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

            manager.UpdateDictionary(text2);

            StringBuilder result = new StringBuilder();

            foreach (var word in repo.Get())
            {
                result.Append(word.Word).Append(" ").Append(word.Frequency).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueResult);
        }
Exemplo n.º 3
0
        public void CreateDictionary(string text, string trueResult)
        {
            GlobalSetting.MaxLengthWord            = 15;
            GlobalSetting.MaxNumberOfWordsReturned = 5;
            GlobalSetting.MinFrequencyWord         = 3;
            GlobalSetting.MinLengthWord            = 3;
            GlobalSetting.SeparationCharacters     = new char[] { ' ' };

            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);

            StringBuilder result = new StringBuilder();

            foreach (var word in repo.Get())
            {
                result.Append(word.Word).Append(" ").Append(word.Frequency).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueResult);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        [TestCase("жил жил  ", "жил жил ", "")]                       //0 + 0
        public void UpdateDictionary(string text1, string text2, string trueResult)
        {
            IGenericRepository <DictionaryWord> repo = new FakeRepository();
            ManagerDictionary manager = new ManagerDictionary(repo);


            manager.CreateDictionary(text1);

            manager.UpdateDictionary(text2);


            StringBuilder result = new StringBuilder();

            foreach (var word in repo.Get())
            {
                result.Append(word.Word).Append(" ").Append(word.Frequency).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueResult);
        }
Exemplo n.º 7
0
        public void DeleteDictionary(string text, string trueResult)
        {
            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);

            manager.DeleteDictionary();

            StringBuilder result = new StringBuilder();

            foreach (var word in repo.Get())
            {
                result.Append(word.Word).Append(" ").Append(word.Frequency).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueResult);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Настройка команд для идентификации ввода в консоли cmd.exe.
        /// </summary>
        /// <param name="args"> аргументы сонсоли cmd.exe</param>
        /// <returns>Настроенный экземпляр реализации команд консоли cmd.exe</returns>
        public static CommandLineApplication InitCommandLine(string[] args)
        {
            CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false);

            CommandOption createDictionary = commandLineApplication.Option(
                "--create | -c",
                "The command to create a dictionary, you must specify the name of the file with the text. A dictionary will be created from the text.",
                CommandOptionType.SingleValue);

            var updateDictionary = commandLineApplication.Option(
                "--update | -u",
                "The command to update the dictionary, you must specify the name of the file with the text." +
                " New words will be added from the text, and existing words in the dictionary will be updated.",
                CommandOptionType.SingleValue);

            var deleteDictionary = commandLineApplication.Option(
                "--delete | -d",
                "The command to delete the dictionary.",
                CommandOptionType.NoValue);

            commandLineApplication.HelpOption("-? | -h | --help");


            commandLineApplication.OnExecute(() =>
            {
                //одновременно должна выполняться только одна команда
                int numberInsertCommand = 0; //счетчик команд

                foreach (var command in commandLineApplication.GetOptions())
                {
                    if (command.HasValue())
                    {
                        numberInsertCommand++;
                    }
                }

                if (numberInsertCommand > 1) //команд больше чем одна
                {
                    Console.WriteLine("You can specify only one command-line parameter at a time (commands)");
                    Environment.Exit(0);
                    return(0);
                }


                DBDictionaryWord dbContext;
                IGenericRepository <DictionaryWord> repo;
                ManagerDictionary manager;

                dbContext = new DBDictionaryWord();
                repo      = new GenericRepository <DictionaryWord>(dbContext);
                manager   = new ManagerDictionary(repo);

                //обработка команд
                //команда создания словаря
                if (createDictionary.HasValue())
                {
                    if (IsUTF8(createDictionary.Value()))
                    {
                        string text = "";
                        text        = File.ReadAllText(createDictionary.Value(), Encoding.Default);
                        manager.CreateDictionary(text);
                    }
                    else
                    {
                        Console.WriteLine("Error: The file format is not UTF8.");
                    }
                }

                //команда обновления словаря
                if (updateDictionary.HasValue())
                {
                    if (IsUTF8(updateDictionary.Value()))
                    {
                        string text = "";
                        text        = File.ReadAllText(updateDictionary.Value(), Encoding.Default);
                        manager.UpdateDictionary(text);
                    }
                    else
                    {
                        Console.WriteLine("Error: The file format is not UTF8.");
                    }
                }

                //команда удаления словаря
                if (deleteDictionary.HasValue())
                {
                    manager.DeleteDictionary();
                }
                Environment.Exit(0);
                return(0);
            });
            return(commandLineApplication);
        }