public void CreateText(string name, TextReader input, int length, string author = null)
        {
            if (_textStore.Exists(x => x.Name == name) || _groupStore.Exists(x => x.Name == name))
            {
                throw new ArgumentException($"Cannot create text because another item in the database already has the name {name}.");
            }
            ITextModel model = _modelFactory.GetTextModel(name, input, length);

            if (!string.IsNullOrWhiteSpace(author))
            {
                model.SetAuthor(author);
            }
            _textStore.Add(model);
        }
Esempio n. 2
0
        public ITextModel GetOne(Expression <Func <Text, bool> > criteria)
        {
            Text text = _db.Texts.FirstOrDefault(criteria);

            if (text == null)
            {
                return(null);
            }
            IFlexibleWordCountModel counts = GetCountsFromText(text);
            ITextModel model = _modelFactory.GetTextModel(text.Name, counts);

            model.SetAuthor(text.Author);
            model.SetIncludeQuotes(Convert.ToBoolean(text.IncludeQuotes));
            return(model);
        }
        public void TestModifyAuthor()
        {
            //string name = _uniqueNames.Pop();
            string name;

            _uniqueNames.TryPop(out name);
            StreamReader sr    = new StreamReader("../../SampleTextFiles/WordSpanningMultipleLines.txt");
            ITextModel   model = _modelFactory.GetTextModel(name, sr, UniversalConstants.CountSize);

            model.SetAuthor("tom");
            _textStore.Add(model);
            model = _textStore.GetOne(x => x.Name == name);
            Assert.AreEqual("tom", model.GetAuthor());
            _textStore.ModifyAuthor(model, "jones");
            model = _textStore.GetOne(x => x.Name == name);
            Assert.AreEqual("jones", model.GetAuthor());
            _textStore.Delete(model);
        }
        public void UpdateText(string oldName, string newName = null, string author = null, bool?includeQuotes = null)
        {
            ITextModel model = _textStore.GetOne(x => x.Name == oldName);

            if (model == null)
            {
                throw new ArgumentException("Cannot update text because it does not exist.");
            }
            if (author != null)
            {
                if (string.IsNullOrWhiteSpace(author))
                {
                    throw new ArgumentException("Cannot update text's author to null or whitespace.");
                }
                _textStore.ModifyAuthor(model, author);
                model.SetAuthor(author);
            }
            if (includeQuotes != null)
            {
                _textStore.ModifyIncludeQuotes(model, (bool)includeQuotes);
                model.SetIncludeQuotes((bool)includeQuotes);
            }
            if (newName != null)
            {
                if (string.IsNullOrWhiteSpace(newName))
                {
                    throw new ArgumentException("Cannot update text's name to null or whitespace.");
                }
                if (_textStore.Exists(x => x.Name == newName) || _groupStore.Exists(x => x.Name == newName))
                {
                    throw new ArgumentException($"Cannot update text name because another item in the database already has the name {newName}.");
                }
                _textStore.ModifyName(model, newName);
                model.SetName(newName);
            }
        }