コード例 #1
0
        void TestBackingStore(string inputString, string outputString)
        {
            CreateBackingStore refactoring = new CreateBackingStore();
            RefactoringOptions options     = ExtractMethodTests.CreateRefactoringOptions(inputString);
            List <Change>      changes     = refactoring.PerformChanges(options, null);
            string             output      = ExtractMethodTests.GetOutput(options, changes);

            Assert.IsTrue(ExtractMethodTests.CompareSource(output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output);
        }
コード例 #2
0
        void TestIntegrateTemporaryVariable(string inputString, string outputString)
        {
            IntegrateTemporaryVariableRefactoring refactoring = new IntegrateTemporaryVariableRefactoring();
            RefactoringOptions options = ExtractMethodTests.CreateRefactoringOptions(inputString);
            List <Change>      changes = refactoring.PerformChanges(options, null);
            string             output  = ExtractMethodTests.GetOutput(options, changes);

            Assert.IsTrue(ExtractMethodTests.CompareSource(output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output);
        }
コード例 #3
0
        void TestIntroduceConstantRefactoring(string inputString, string outputString)
        {
            IntroduceConstantRefactoring refactoring = new IntroduceConstantRefactoring();
            RefactoringOptions           options     = ExtractMethodTests.CreateRefactoringOptions(inputString);

            IntroduceConstantRefactoring.Parameters param = new IntroduceConstantRefactoring.Parameters()
            {
                Name = "magic"
            };
            List <Change> changes = refactoring.PerformChanges(options, param);
            string        output  = ExtractMethodTests.GetOutput(options, changes);

            Assert.IsTrue(ExtractMethodTests.CompareSource(output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output);
        }
コード例 #4
0
        void TestCreateMethod(string input, string outputString, bool returnWholeFile)
        {
            var generator = new CSharpCodeGeneratorNode();

            MonoDevelop.Projects.CodeGeneration.CodeGenerator.AddGenerator(generator);
            var refactoring            = new CreateMethodCodeGenerator();
            RefactoringOptions options = ExtractMethodTests.CreateRefactoringOptions(input);

            Assert.IsTrue(refactoring.IsValid(options));

            if (returnWholeFile)
            {
                refactoring.SetInsertionPoint(CodeGenerationService.GetInsertionPoints(options.Document, refactoring.DeclaringType).First());
            }
            else
            {
                DocumentLocation loc = new DocumentLocation(1, 1);
                refactoring.SetInsertionPoint(new InsertionPoint(loc, NewLineInsertion.Eol, NewLineInsertion.Eol));
            }

            List <Change> changes = refactoring.PerformChanges(options, null);
//			changes.ForEach (c => Console.WriteLine (c));
            // get just the generated method.
            string output = ExtractMethodTests.GetOutput(options, changes);

            if (returnWholeFile)
            {
                Assert.IsTrue(ExtractMethodTests.CompareSource(output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output);
                return;
            }
            output = output.Substring(0, output.IndexOf('}') + 1).Trim();

            // crop 1 level of indent
            Document doc = new Document(output);

            foreach (LineSegment line in doc.Lines)
            {
                if (doc.GetCharAt(line.Offset) == '\t')
                {
                    ((IBuffer)doc).Remove(line.Offset, 1);
                }
            }
            output = doc.Text;

            Assert.IsTrue(ExtractMethodTests.CompareSource(output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output);
            MonoDevelop.Projects.CodeGeneration.CodeGenerator.RemoveGenerator(generator);
        }