public void Test()
        {
            string codeText = File.ReadAllText("Resources\\BasicClass.txt");

            var parser = new CSharpParser();
            parser.ParseCode(codeText);

            var codeRoot = (CodeRoot)parser.CreatedCodeRoot;
            //Actions actions = Test2(codeRoot);//Test1(codeRoot);

            Actions actions = new Actions();

            Entity entity = new EntityImpl("BasicClass");
            entity.AddProperty(new PropertyImpl { Name = "Property5", Type = "Entity" });

            Entity entity1 = new EntityImpl("Class1");
            entity1.AddProperty(new PropertyImpl { Name = "Property5", Type = "Entity" });

            entity.MappedClass = codeRoot.Namespaces[0].Classes[0];
            entity1.MappedClass = codeRoot.Namespaces[0].Classes[1];

            CheckEntity(entity, actions);

            codeText = actions.RunActions(codeText, codeRoot, true);
            actions = new Actions();

            actions.AddAction(new AddAttributeToPropertyAction(entity.MappedClass.Properties[0], new Attribute(codeRoot.Controller){Name = "Attr"}));
            CheckEntity(entity1, actions);

            var output = actions.RunActions(codeText, codeRoot, false);
        }
        public void ApplyTo(Actions actions)
        {
            foreach (var attr in attributes)
            {
                var attribute = attr.Build(_class.Controller);

                if (attribute == null)
                    continue;

                if (_class.HasAttributeNamed(attribute.Name) || attributesToDelete.Contains(attribute.Name)) continue;

                actions.AddAction(new AddAttributeToClassAction(_class, attribute));
            }
            foreach (var attr in attributesToDelete)
            {
                if (_class.HasAttributeNamed(attr))
                {
                    ArchAngel.Providers.CodeProvider.DotNet.Attribute att = _class.Attributes.Find(a => a.Name == attr);
                    actions.AddAction(new RemoveAttributeFromClassAction(att));
                }
            }
        }
        public void They_Are_Added_Correctly()
        {
            var parser = new CSharpParser();
            parser.ParseCode(Code.Class1Text);

            var codeRoot = (CodeRoot)parser.CreatedCodeRoot;
            var basicClass = codeRoot.Namespaces[0].Classes[0];

            var property2 = new Property(codeRoot.Controller, "Property1", new DataType(codeRoot.Controller, "string"), "public");
            var property3 = new Property(codeRoot.Controller, "Property2", new DataType(codeRoot.Controller, "Class1"), "private");

            var action1 = new AddPropertyToClassAction(property2, AdditionPoint.EndOfParent, basicClass);
            var action2 = new AddPropertyToClassAction(property3, AdditionPoint.EndOfParent, basicClass);

            Actions actions = new Actions();
            actions.AddAction(action1);
            actions.AddAction(action2);

            string output = actions.RunActions(parser);
            output = Slyce.Common.Utility.StandardizeLineBreaks(output, Environment.NewLine);
            Assert.That(output, Is.EqualTo(Code.Class1Plus2PropertiesText));
        }
        public void ApplyTo(Actions actions)
        {
            var usingStatement = Construct(_class);

            // Try find the UsingStatement in the existing class using the old name
            var existingUsingStatement = _class.Controller.Root.UsingStatements.FirstOrDefault(u => u.ToString() == _value);

            if (existingUsingStatement != null)
            {
                if (_mustRemove)
                    ApplyUsingStatementDeletion(actions, existingUsingStatement);
            }
            else if (!_mustRemove)
            {
                // Add the UsingStatement to the class.
                actions.AddAction(new AddUsingStatementToClassAction(_class, usingStatement));
            }
        }
        public void ApplyTo(Actions actions)
        {
            var interface1 = Construct(_class);

            // Try find the Interface in the existing class using the old name
            var existingInterface = _class.BaseNames.FirstOrDefault(i => i == _value);

            if (existingInterface != null)
            {
                if (_mustRemove)
                    ApplyImplementsDeletion(actions, _class, existingInterface);
            }
            else if (!_mustRemove)
            {
                // Add the Implements to the class.
                DataType newImplements = new DataType(_class.Controller, interface1.Name);
                actions.AddAction(new AddImplementsToClassAction(_class, newImplements, false));
            }
        }
 private static void ApplyImplementsDeletion(Actions actions, Class _class, string existingInterface)
 {
     DataType newImplements = new DataType(_class.Controller, existingInterface);
     actions.AddAction(new RemoveImplementsFromClassAction(_class, existingInterface));
 }
 private static void ApplyTypeChanges(Property existingProperty, Property exampleProperty, Actions actions)
 {
     if (exampleProperty.DataType != null && existingProperty.DataType.Equals(exampleProperty.DataType) == false)
     {
         // Change datatype
         actions.AddAction(new ChangeTypeOfPropertyAction(existingProperty, exampleProperty.DataType));
     }
 }
 private static void ApplyPropertyDeletion(Actions actions, Property existingProperty)
 {
     actions.AddAction(new RemovePropertyFromClassAction(existingProperty));
 }
 private static void ApplyTypeChanges(Field existingField, Field exampleField, Actions actions)
 {
     if (exampleField.DataType != null && existingField.DataType.Equals(exampleField.DataType) == false)
     {
         // Change datatype
         actions.AddAction(new ChangeTypeOfFieldAction(existingField, exampleField.DataType));
     }
 }
        private static void ApplyModifierChanges(Field existingField, Field exampleField, Actions actions)
        {
            if (existingField.Modifiers.UnorderedEqual(exampleField.Modifiers) == false)
            {
                string modifierString = "";

                foreach (var mod in existingField.Modifiers)
                    modifierString += mod + " ";

                modifierString = modifierString.Trim();
                actions.AddAction(new RemoveModifierFromFieldAction(existingField, modifierString));

                foreach (var modifier in exampleField.Modifiers)
                    actions.AddAction(new AddModifierToFieldAction(existingField, modifier, false));
            }
        }
        public void ApplyTo(Actions actions)
        {
            var function = Construct(_class);

            // Try find the function in the existing class using the old name
            Function existingFunction = null;// _class.Functions.FirstOrDefault(p => p.Name == _name);

            foreach (var func in _class.Functions.Where(p => p.Name == _name && (_ParameterTypes != null && p.Parameters.Count == _ParameterTypes.Count)))
            {
                bool found = true;

                for (int i = 0; i < func.Parameters.Count; i++)
                {
                    if (func.Parameters[i].DataType != _ParameterTypes[i].DataType)
                    {
                        found = false;
                        break;
                    }
                }
                if (found)
                {
                    existingFunction = func;
                    break;
                }
            }
            if (existingFunction == null)
            {
                for (int i = _oldNames.Count - 1; i >= 0; i--)
                {
                    // No property found with the new name, so try the old name
                    //existingFunction = _class.Functions.FirstOrDefault(p => p.Name == _oldNames[i]);

                    //if (existingFunction != null)
                    //    break;
                    foreach (var func in _class.Functions.Where(p => p.Name == _oldNames[i] && p.Parameters.Count == _ParameterTypes.Count))
                    {
                        bool found = true;

                        for (int pCounter = 0; pCounter < func.Parameters.Count; pCounter++)
                        {
                            if (func.Parameters[pCounter].DataType != _ParameterTypes[pCounter].DataType)
                            {
                                found = false;
                                break;
                            }
                        }
                        if (found)
                        {
                            existingFunction = func;
                            break;
                        }
                    }
                    if (existingFunction != null)
                        break;
                }
            }
            //if (existingFunction == null)
            //{
            //    // As a last ditch effort to find the property, ignore case when searching
            //    existingFunction = _class.Functions.FirstOrDefault(p => p.Name.ToLowerInvariant() == _name.ToLowerInvariant());
            //}
            if (existingFunction != null)
            {
                if (_mustRemove)
                    ApplyFunctionDeletion(actions, existingFunction);
                else
                {
                    // Make sure the property matches the given property
                    ApplyFunctionChanges(actions, existingFunction, function);
                }
            }
            else if (_mustRemove)
            {
                // No existing property found, so we don't need to do anything, it's already removed.
                // Don't add any actions
                return;
            }
            else
            {
                // Add the property to the class.
                actions.AddAction(new AddFunctionToClassAction(function, AdditionPoint.EndOfParent, _class));
            }
            if (!_mustRemove)
            {
                var functionToAddTo = existingFunction ?? function;

                //foreach (var attrBuilder in attributes)
                //{
                //    var attribute = attrBuilder.Build(functionToAddTo.Controller);

                //    if (functionToAddTo.Attributes.Any(a => a.Name == attribute.Name) ||
                //        functionToAddTo.AttributeSections.SelectMany(section => section.Attributes).Any(a => a.Name == attribute.Name))
                //    {
                //        // if there are any attributes on the property currently with this name, then we should skip it.
                //        continue;
                //    }
                //    actions.AddAction(new AddAttributeToMethodAction(functionToAddTo, attribute));
                //}
            }
        }
 /// <summary>
 /// Changes the entire header, including modifiers, return-type, name and parameters.
 /// </summary>
 /// <param name="existingFunction"></param>
 /// <param name="exampleFunction"></param>
 /// <param name="actions"></param>
 private static void ApplyHeaderChanges(Function existingFunction, Function exampleFunction, Actions actions)
 {
     if (existingFunction.Name != exampleFunction.Name)
     {
         // Change datatype
         actions.AddAction(new ChangeMethodHeaderAction(existingFunction, exampleFunction));
     }
 }
 private static void ApplyFunctionDeletion(Actions actions, Function existingFunction)
 {
     actions.AddAction(new RemoveMethodFromClassAction(existingFunction));
 }
 private static void ApplyBodyChanges(Function existingFunction, Function exampleFunction, Actions actions)
 {
     actions.AddAction(new ChangeMethodBodyAction(existingFunction, exampleFunction));
 }
 private static void ApplyUsingStatementDeletion(Actions actions, UsingStatement existingUsingStatement)
 {
     actions.AddAction(new RemoveUsingStatementFromClassAction(existingUsingStatement));
 }
 private static void ApplyFieldDeletion(Actions actions, Field existingField)
 {
     actions.AddAction(new RemoveFieldFromClassAction(existingField));
 }
 private static void ApplyInitialValueChanges(Field existingField, Field exampleField, Actions actions)
 {
     if (exampleField.InitialValue != null && existingField.InitialValue.Equals(exampleField.InitialValue) == false)
     {
         // Change initial value
         actions.AddAction(new ChangeInitialValueOfFieldAction(existingField, exampleField.InitialValue));
     }
 }
        private static void ApplyAccessorChanges(Property existingProperty, Property exampleProperty, Actions actions)
        {
            if (existingProperty.GetAccessor == null)
            {
                actions.AddAction(new AddAccessorToPropertyAction(existingProperty, exampleProperty.GetAccessor));
            }
            else if (exampleProperty.GetAccessor != null && existingProperty.GetAccessor.Modifier != exampleProperty.GetAccessor.Modifier)
            {
                actions.AddAction(new ChangePropertyAccessorModifierAction(existingProperty.GetAccessor, exampleProperty.GetAccessor.Modifier));
            }

            if (existingProperty.SetAccessor == null)
            {
                actions.AddAction(new AddAccessorToPropertyAction(existingProperty, exampleProperty.SetAccessor));
            }
            else if (exampleProperty.SetAccessor != null && existingProperty.SetAccessor.Modifier != exampleProperty.SetAccessor.Modifier)
            {
                actions.AddAction(new ChangePropertyAccessorModifierAction(existingProperty.SetAccessor, exampleProperty.SetAccessor.Modifier));
            }
        }
 private static void ApplyNameChanges(Field existingField, Field exampleField, Actions actions)
 {
     if (existingField.Name != exampleField.Name)
     {
         // Change name
         actions.AddAction(new ChangeNameOfFieldAction(existingField, exampleField.Name));
     }
 }
        private static void ApplyModifierChanges(Property existingProperty, Property exampleProperty, Actions actions)
        {
            if (existingProperty.Modifiers.UnorderedEqual(exampleProperty.Modifiers) == false)
            {
                actions.AddAction(new RemoveModifiersFromPropertyAction(existingProperty));

                foreach (var modifier in exampleProperty.Modifiers)
                {
                    actions.AddAction(new AddModifierToPropertyAction(existingProperty, modifier, false));
                }
            }
        }
        public void ApplyTo(Actions actions)
        {
            var field = Construct(_class);

            // Try find the field in the existing class using the old name
            var existingField = _class.Fields.FirstOrDefault(p => p.Name == _name);

            if (existingField == null)
            {
                for (int i = _oldNames.Count - 1; i >= 0; i--)
                {
                    // No field found with the new name, so try the old name
                    existingField = _class.Fields.FirstOrDefault(p => p.Name == _oldNames[i]);

                    if (existingField != null)
                        break;
                }
            }
            if (existingField == null)
            {
                // As a last ditch effort to find the field, ignore case when searching
                existingField = _class.Fields.FirstOrDefault(p => p.Name.ToLowerInvariant() == _name.ToLowerInvariant());
            }
            if (existingField != null)
            {
                if (_mustRemove)
                    ApplyFieldDeletion(actions, existingField);
                else
                {
                    // Make sure the field matches the given property
                    ApplyFieldChanges(actions, existingField, field);
                }
            }
            else if (_mustRemove)
            {
                // No existing field found, so we don't need to do anything, it's already removed.
                // Don't add any actions
                return;
            }
            else
            {
                // Add the property to the class.
                actions.AddAction(new AddFieldToClassAction(field, AdditionPoint.EndOfParent, _class));
            }
            if (!_mustRemove)
            {
                var fieldToAddTo = existingField ?? field;

                foreach (var attrBuilder in attributes)
                {
                    var attribute = attrBuilder.Build(fieldToAddTo.Controller);

                    if (fieldToAddTo.Attributes.Any(a => a.Name == attribute.Name) ||
                        fieldToAddTo.AttributeSections.SelectMany(section => section.Attributes).Any(a => a.Name == attribute.Name))
                    {
                        // if there are any attributes on the property currently with this name, then we should skip it.
                        continue;
                    }

                    actions.AddAction(new AddAttributeToFieldAction(fieldToAddTo, attribute));
                }
            }
        }
 private static void ApplyNameChanges(Property existingProperty, Property exampleProperty, Actions actions)
 {
     if (existingProperty.Name != exampleProperty.Name)
     {
         // Change datatype
         actions.AddAction(new ChangeNameOfPropertyAction(existingProperty, exampleProperty.Name));
     }
 }