Ejemplo n.º 1
0
        public void AddItemToGroup(string groupName, string itemName)
        {
            if (groupName == itemName)
            {
                throw new ArgumentException("Cannot add a group to itself.");
            }
            IGroupModel parent = _groupStore.GetOne(x => x.Name == groupName);

            if (parent == null)
            {
                throw new ArgumentException($"Can't add item to group named {groupName} since it doesn't exist.");
            }
            ITextModel  childText  = _textStore.GetOne(x => x.Name == itemName);
            IGroupModel childGroup = _groupStore.GetOne(x => x.Name == itemName);

            if (childText == null)
            {
                if (childGroup == null)
                {
                    throw new ArgumentException($"Can't add item named {itemName} to group since it doesn't exist.");
                }
                if (_groupStore.Contains(childGroup, parent))
                {
                    throw new ArgumentException("Can't add a group as a child to its own parent or a parent of its parent or ...");
                }
                if (_groupStore.Contains(parent, childGroup))
                {
                    throw new ArgumentException("Cannot add item to group since it is already a member of that group.");
                }
                parent.Add(childGroup);
                _groupStore.AddItem(parent, childGroup);
            }
            else
            {
                if (childGroup != null)
                {
                    throw new ArgumentException("The database has a text and group with the same name. That shouldn't happen.");
                }
                if (_groupStore.Contains(parent, childText))
                {
                    throw new ArgumentException("Cannot add item to group since it is already a member of that group.");
                }
                parent.Add(childText);
                _groupStore.AddItem(parent, childText);
            }
        }
Ejemplo n.º 2
0
        public void TestAddText()
        {
            string groupName;

            _uniqueNames.TryPop(out groupName);
            //string groupName = _uniqueNames.Pop();
            IGroupModel groupModel = _modelFactory.GetGroupModel(groupName, UniversalConstants.CountSize);

            _groupStore.Add(groupModel);
            //string textName = _uniqueNames.Pop();
            string textName;

            _uniqueNames.TryPop(out textName);
            StreamReader text      = new StreamReader("../../SampleTextFiles/WordSpanningMultipleLines.txt");
            ITextModel   textModel = _modelFactory.GetTextModel(textName, text, UniversalConstants.CountSize);

            _textStore.Add(textModel);
            _groupStore.AddItem(groupModel, textModel);
            groupModel = _groupStore.GetOne(x => x.Name == groupName);
            List <ITextOrGroupViewModel> groupMembers = groupModel.GetMembers();

            Assert.AreEqual(1, groupMembers.Count);
            Assert.AreEqual(textName, groupMembers[0].GetName());
            Assert.IsInstanceOfType(groupMembers[0], typeof(ITextModel));
            CompareTextModels(textModel, (ITextModel)groupMembers[0]);
            _groupStore.RemoveItem(groupModel, textModel);
            _textStore.Delete(textModel);
            _groupStore.Delete(groupModel);
        }