public void ValidDeletion()
 {
     groupOne.Add(textOne);
     groupOne.Remove(textOne);
     groupOne.Add(groupTwo);
     groupOne.Remove(groupTwo);
 }
Esempio n. 2
0
        public void RemoveItemFromGroup(string groupName, string itemName)
        {
            IGroupModel parent = _groupStore.GetOne(x => x.Name == groupName);

            if (parent == null)
            {
                throw new ArgumentException($"Can't remove item from 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 remove item named {itemName} from group since it doesn't exist.");
                }
                if (!_groupStore.Contains(parent, childGroup))
                {
                    throw new ArgumentException("Cannot remove item from group since it is not a member of that group.");
                }
                parent.Remove(childGroup);
                _groupStore.RemoveItem(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 remove item from group since it is not a member of that group.");
                }
                parent.Remove(childText);
                _groupStore.RemoveItem(parent, childText);
            }
        }