コード例 #1
0
        public void TestModifyName()
        {
            //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);

            _textStore.Add(model);
            model = _textStore.GetOne(x => x.Name == name);
            Assert.IsNotNull(model);
            //string newName = _uniqueNames.Pop();
            string newName;

            _uniqueNames.TryPop(out newName);
            _textStore.ModifyName(model, newName);
            ITextModel nullModel = _textStore.GetOne(x => x.Name == name);

            model = _textStore.GetOne(x => x.Name == newName);
            Assert.IsNull(nullModel);
            Assert.IsNotNull(model);
            _textStore.Delete(model);
        }
コード例 #2
0
        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);
            }
        }