Exemplo n.º 1
0
        /// <summary>
        /// Turns a merge consignment and options into code
        /// </summary>
        /// <param name="mergeConsignment">The merger details</param>
        /// <param name="mergeOptions">Options for the code merger</param>
        /// <returns>Merged code</returns>
        public static string Merge(MergeConsignment mergeConsignment, MergeOptions mergeOptions)
        {
            var stringBuilder = new StringBuilder();

            foreach (var mergeItems in mergeConsignment.MergeItems)
                stringBuilder.Append(MergeItem(mergeConsignment.CodeInput, mergeItems, mergeOptions));

            return stringBuilder.ToString();
        }
Exemplo n.º 2
0
        public static string MergeItem(string inputCode, MergeItem mergeItem, MergeOptions mergeOptions)
        {
            var output = string.Empty;
            var substitutionOutput = string.Empty;

            foreach (var mergeParing in mergeItem.MergeParings)
            {
                var swapValue = mergeParing.SwapValue;
                var inputValue = mergeParing.InputValue;

                if (inputValue != null && inputValue.Trim().Length > 0)
                {
                    substitutionOutput = inputCode.Replace(swapValue, inputValue);

                    //Perform the camel replacement if needed on the output code
                    if (mergeOptions.CameliseSubstitutionAlso)
                    {
                        //Camilise our text values
                        var swapValueCamelised = swapValue.CameliseString();
                        var inputValueCamelised = mergeParing.InputValue.CameliseString();

                        if (inputValueCamelised != null && inputValue.Trim().Length > 0)
                            substitutionOutput = substitutionOutput.Replace(swapValueCamelised, inputValueCamelised);
                    }

                    //Perform the space replacement if needed on the output code
                    if (mergeOptions.SpaciliseSubstitutionAlso)
                    {
                        //Camilise our text values
                        var swapValueSpacilised = swapValue.SpaciliseCapitals();
                        var inputValueSpacilised = mergeParing.InputValue.SpaciliseCapitals();

                        if (inputValueSpacilised != null && inputValueSpacilised.Trim().Length > 0)
                            substitutionOutput = substitutionOutput.Replace(swapValueSpacilised, inputValueSpacilised);
                    }
                }

                output += substitutionOutput;
            }

            return output;
        }
Exemplo n.º 3
0
        public void CodeMergeConsignmentWithSimpleConsignmentAndDefaultOptionsShallSucceed()
        {
            //Setup
            var inputCode = @"public TYPE PROP;
            ";
            var expectedOutputCode = @"public string Name;
            public int Id;
            ";

            var mergeConsignment = new MergeConsignment
                {
                    CodeInput = inputCode,
                    MergeItems = new List<MergeItem>
                        {
                            new MergeItem
                                {
                                    MergeParings = new List<MergePairing>
                                    {
                                        new MergePairing { SwapValue = "PROP", InputValue = "Name" } ,
                                        new MergePairing { SwapValue = "TYPE", InputValue = "string" }
                                    }
                                },
                            new MergeItem
                                {
                                    MergeParings = new List<MergePairing>
                                    {
                                        new MergePairing { SwapValue = "PROP", InputValue = "Id" } ,
                                        new MergePairing { SwapValue = "TYPE", InputValue = "int" }
                                    }
                                }
                        }
                };

            var mergeOptions = new MergeOptions();//Default

            //Exercise
            var actualCodeOutput = MergeHelper.Merge(mergeConsignment, mergeOptions);

            //Verify
            Assert.AreEqual(expectedOutputCode, actualCodeOutput, "The actual code output is not what was expected: " + actualCodeOutput);
        }
Exemplo n.º 4
0
        public void CodeMergeItemWithCameliseShallPerformAnAdditionalSubstitutionOnCamelisedInputAndMergeItems()
        {
            //Setup
            var inputCode = @"public string somethingElse SomethingElse { get; set; }";
            var expectedOutputCode = @"public string nameMe NameMe { get; set; }";

            var swapValue = "SomethingElse";
            var mergeItem = new MergeItem
            {
                MergeParings = new List<MergePairing>
                {
                    new MergePairing { SwapValue = swapValue, InputValue = "NameMe" }
                }
            };

            var mergeOptions = new MergeOptions { CameliseSubstitutionAlso = true };

            //Exercise
            var actualCodeOutput = MergeHelper.MergeItem(inputCode, mergeItem, mergeOptions);

            //Verify
            Assert.AreEqual(expectedOutputCode, actualCodeOutput, "The actual code output is not what was expected: " + actualCodeOutput);
        }
Exemplo n.º 5
0
        public void CodeMergeItemWithDefaultOptionsShallSucceed()
        {
            //Setup
            var inputCode = @"public string Something { get; set; }

            ";
            var expectedOutputCode = @"public string Name { get; set; }

            public string Code { get; set; }

            public string Description { get; set; }

            ";
            var swapValue = "Something";
            var mergeItem = new MergeItem
            {
                MergeParings = new List<MergePairing>
                {
                    new MergePairing { SwapValue = swapValue, InputValue = "Name" } ,
                    new MergePairing { SwapValue = swapValue, InputValue = "Code" } ,
                    new MergePairing { SwapValue = swapValue, InputValue = "Description" }
                }
            };

            var mergeOptions = new MergeOptions();//Default

            //Exercise
            var actualCodeOutput = MergeHelper.MergeItem(inputCode, mergeItem, mergeOptions);

            //Verify
            Assert.AreEqual(expectedOutputCode, actualCodeOutput, "The actual code output is not what was expected: " + actualCodeOutput);
        }
Exemplo n.º 6
0
        private void Merge()
        {
            //Setup
            string inputCode = this.txtInputCode.Text;

            var mergeItem = new MergeItem
                {
                    MergeParings =
                        this.GetInputValues()
                            .Select(i => new MergePairing {SwapValue = this.SwapValue, InputValue = i})
                            .ToList()
                };

            var mergeOptions = new MergeOptions { CameliseSubstitutionAlso = this.cbCamel.Checked, SpaciliseSubstitutionAlso = this.cbAddSpaces.Checked };

            //Exercise
            var actualCodeOutput = MergeHelper.MergeItem(inputCode, mergeItem, mergeOptions);

            this.txtOutputCode.Text = actualCodeOutput;
        }