< Summary

Class:MUNity.Extensions.ResolutionExtensions.AmendmentExtensions
Assembly:MUNity.Schema
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNitySchema\Extensions\ResolutionExtensions\AmendmentExtensions.cs
Covered lines:0
Uncovered lines:109
Coverable lines:109
Total lines:227
Line coverage:0% (0 of 109)
Covered branches:0
Total branches:24
Branch coverage:0% (0 of 24)
Covered methods:0
Total methods:10
Method coverage:0% (0 of 10)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
AmendmentsForOperativeParagraph(...)100%10%
PushAmendment(...)0%100%
RemoveAmendment(...)0%80%
CreateDeleteAmendment(...)0%20%
CreateChangeAmendment(...)0%20%
CreateMoveAmendment(...)0%20%
CreateAddAmendment(...)100%10%
CreateDeleteAmendment(...)100%10%
CreateMoveAmendment(...)100%10%
CreateChangeAmendment(...)100%10%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNitySchema\Extensions\ResolutionExtensions\AmendmentExtensions.cs

#LineLine coverage
 1using MUNity.Models.Resolution;
 2using System;
 3using System.Collections.Generic;
 4using System.Text;
 5using System.Linq;
 6using MUNity.Extensions.ObservableCollectionExtensions;
 7
 8namespace MUNity.Extensions.ResolutionExtensions
 9{
 10
 11    /// <summary>
 12    /// Get some more funcinality for working with amendments on the Resolution. documents
 13    /// </summary>
 14    public static class AmendmentExtensions
 15    {
 16        /// <summary>
 17        /// Returns all the Amendments for the operative paragraph with the given Id.
 18        /// </summary>
 19        /// <param name="section"></param>
 20        /// <param name="id"></param>
 21        /// <returns></returns>
 22        public static List<AbstractAmendment> AmendmentsForOperativeParagraph(this OperativeSection section, string id)
 023        {
 024            var result = new List<AbstractAmendment>();
 25
 026            result.AddRange(section.AddAmendments.Where(n => n.TargetSectionId == id));
 027            result.AddRange(section.ChangeAmendments.Where(n => n.TargetSectionId == id));
 028            result.AddRange(section.DeleteAmendments.Where(n => n.TargetSectionId == id));
 029            result.AddRange(section.MoveAmendments.Where(n => n.TargetSectionId == id));
 030            return result;
 031        }
 32
 33        /// <summary>
 34        /// Adds a new Amendment into the Amendment list.
 35        /// </summary>
 36        /// <param name="section"></param>
 37        /// <param name="amendment"></param>
 38        private static void PushAmendment(this OperativeSection section, AbstractAmendment amendment)
 039        {
 40            // For now every Amendment has a TargetSectionId this could maybe be different one day
 41            // Remember to move this function if this day ever comes.
 042            if (section.FirstOrDefault(n => n.OperativeParagraphId == amendment.TargetSectionId) == null)
 043                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
 44
 045            if (amendment is AddAmendment addAmendment)
 046            {
 047                section.AddAmendments.Add(addAmendment);
 048            }
 049            else if (amendment is ChangeAmendment changeAmendment)
 050            {
 051                section.ChangeAmendments.Add(changeAmendment);
 052            }
 053            else if (amendment is DeleteAmendment deleteAmendment)
 054            {
 055                section.DeleteAmendments.Add(deleteAmendment);
 056            }
 057            else if (amendment is MoveAmendment moveAmendment)
 058            {
 059                section.MoveAmendments.Add(moveAmendment);
 060            }
 61            else
 062            {
 063                throw new MUNity.Exceptions.Resolution.UnsupportedAmendmentTypeException();
 64            }
 065        }
 66
 67        /// <summary>
 68        /// Removes an amentment from its list. Note that this is not the same
 69        /// as Deny. This will just remove the given instance of the amendment.
 70        /// </summary>
 71        /// <param name="section"></param>
 72        /// <param name="amendment"></param>
 73        public static void RemoveAmendment(this OperativeSection section, AbstractAmendment amendment)
 074        {
 075            if (amendment is AddAmendment addAmendment)
 076            {
 077                section.AddAmendments.RemoveAll(n => n.TargetSectionId == amendment.TargetSectionId);
 078                section.Paragraphs.RemoveAll(n => n.OperativeParagraphId == amendment.TargetSectionId);
 079            }
 080            else if (amendment is ChangeAmendment changeAmendment)
 081            {
 082                section.ChangeAmendments.Remove(changeAmendment);
 083            }
 084            else if (amendment is DeleteAmendment deleteAmendment)
 085            {
 086                section.DeleteAmendments.Remove(deleteAmendment);
 087            }
 088            else if (amendment is MoveAmendment moveAmendment)
 089            {
 090                section.MoveAmendments.Remove(moveAmendment);
 091                section.Paragraphs.RemoveAll(n => moveAmendment.NewTargetSectionId == n.OperativeParagraphId);
 092            }
 93            else
 094            {
 095                throw new MUNity.Exceptions.Resolution.UnsupportedAmendmentTypeException();
 96            }
 097        }
 98
 99        /// <summary>
 100        /// Creates a new Amendment to delete an operative paragraph.
 101        /// </summary>
 102        /// <param name="section"></param>
 103        /// <param name="paragraphId"></param>
 104        /// <returns></returns>
 105        public static DeleteAmendment CreateDeleteAmendment(this OperativeSection section, string paragraphId)
 0106        {
 0107            if (section.FindOperativeParagraph(paragraphId) == null)
 0108                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
 109
 0110            DeleteAmendment newAmendment = new DeleteAmendment
 0111            {
 0112                TargetSectionId = paragraphId
 0113            };
 0114            section.PushAmendment(newAmendment);
 0115            return newAmendment;
 0116        }
 117
 118        /// <summary>
 119        /// Creates a new Amendment for a TextChange of a paragraph with a given Id.
 120        /// </summary>
 121        /// <param name="section">The operative Section of the resolution that this Admendment should be created in and 
 122        /// <param name="paragraphId">The OperativeParagraphId of the target paragraph that the text should be changed i
 123        /// <param name="newText">The new Text that the paragraph should be set to if the created Amendment is Accepted/
 124        /// <returns></returns>
 125        public static ChangeAmendment CreateChangeAmendment(this OperativeSection section, string paragraphId, string ne
 0126        {
 0127            if (section.FindOperativeParagraph(paragraphId) == null)
 0128                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
 129
 0130            var newAmendment = new ChangeAmendment
 0131            {
 0132                TargetSectionId = paragraphId,
 0133                NewText = newText
 0134            };
 0135            section.PushAmendment(newAmendment);
 0136            return newAmendment;
 0137        }
 138
 139
 140        /// <summary>
 141        /// Creates a Move Amendment. This will also create a new Operative paragraph at the palce where the amendment s
 142        /// will copy the text once when the amendment is created and once when the amendment is accepted. If the text o
 143        /// text of the virtual operative paragraph may differ.
 144        /// </summary>
 145        /// <param name="section"></param>
 146        /// <param name="paragraphId"></param>
 147        /// <param name="targetIndex"></param>
 148        /// <param name="parentParagraph"></param>
 149        /// <returns></returns>
 150        public static MoveAmendment CreateMoveAmendment(this OperativeSection section, string paragraphId, int targetInd
 0151        {
 0152            var sourceParagraph = section.FindOperativeParagraph(paragraphId);
 0153            if (sourceParagraph == null)
 0154                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
 155
 0156            var newAmendment = new MoveAmendment
 0157            {
 0158                TargetSectionId = paragraphId
 0159            };
 0160            var virtualParagraph = new OperativeParagraph
 0161            {
 0162                IsLocked = true,
 0163                IsVirtual = true,
 0164                Text = sourceParagraph.Text
 0165            };
 0166            newAmendment.NewTargetSectionId = virtualParagraph.OperativeParagraphId;
 0167            section.InsertIntoRealPosition(virtualParagraph, targetIndex, parentParagraph);
 0168            section.PushAmendment(newAmendment);
 0169            return newAmendment;
 0170        }
 171
 172        /// <summary>
 173        /// Creates a new Add Amendment to add a new operative paragraph at a certain position. This will also create a 
 174        /// the new paragraph may be when it is accepted.
 175        /// </summary>
 176        /// <param name="section">The operative Section of the Resolution where this paragraph should be added.</param>
 177        /// <param name="targetIndex">The index where the paragraph should be added.</param>
 178        /// <param name="text">The Text of the new paragraph</param>
 179        /// <param name="parentParagraph">Use this parent paragraph if the new paragraph should be a sub point</param>
 180        /// <returns></returns>
 181        public static AddAmendment CreateAddAmendment(this OperativeSection section, int targetIndex, string text = "", 
 0182        {
 0183            var virtualParagraph = new OperativeParagraph(text)
 0184            {
 0185                IsVirtual = true,
 0186                Visible = false
 0187            };
 0188            section.InsertIntoRealPosition(virtualParagraph, targetIndex, parentParagraph);
 0189            var amendment = new AddAmendment
 0190            {
 0191                TargetSectionId = virtualParagraph.OperativeParagraphId
 0192            };
 0193            section.PushAmendment(amendment);
 0194            return amendment;
 0195        }
 196
 197        /// <summary>
 198        /// Creates a new amendment to delete a certain operative paragraph.
 199        /// </summary>
 200        /// <param name="section"></param>
 201        /// <param name="paragraph"></param>
 202        /// <returns></returns>
 0203        public static DeleteAmendment CreateDeleteAmendment(this OperativeSection section, OperativeParagraph paragraph)
 204
 205        /// <summary>
 206        /// Creates a new Move Amendment. The given targetIndex is the position the new Virtual Paragraph will be locate
 207        /// Type in 0 to move it to the beginning of the list. Note that 1 will also move it to the start!
 208        /// When you have two Paragraphs (A and B) and want A to move behind B (B, A) you need to set the targetIndex to
 209        /// </summary>
 210        /// <param name="section">The Operative Section that you want to crate the Move Amendment at.</param>
 211        /// <param name="paragraph"></param>
 212        /// <param name="targetIndex"></param>
 213        /// <param name="parentParagraph"></param>
 214        /// <returns></returns>
 215        public static MoveAmendment CreateMoveAmendment(this OperativeSection section, OperativeParagraph paragraph, int
 0216            section.CreateMoveAmendment(paragraph.OperativeParagraphId, targetIndex, parentParagraph);
 217
 218        /// <summary>
 219        /// Creates a new Text change amendment.
 220        /// </summary>
 221        /// <param name="section"></param>
 222        /// <param name="paragraph"></param>
 223        /// <param name="newText"></param>
 224        /// <returns></returns>
 0225        public static ChangeAmendment CreateChangeAmendment(this OperativeSection section, OperativeParagraph paragraph,
 226    }
 227}