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; }
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); }
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); }
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; }