Пример #1
0
        private static void CreateQualifiedSelectionForTestCase(RenameTestsDataObject tdo)
        {
            var component = RetrieveComponent(tdo, tdo.SelectionModuleName);

            if (tdo.RawSelection.HasValue)
            {
                tdo.QualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), tdo.RawSelection.Value);
                return;
            }
            Assert.Inconclusive($"Unable to find target '{RenameTests.FAUX_CURSOR}' in { tdo.SelectionModuleName} content.");
        }
Пример #2
0
 private static void CheckRenameRefactorTestResults(RenameTestsDataObject tdo)
 {
     foreach (var inputOutput in tdo.ModuleTestSetupDefs)
     {
         if (inputOutput.CheckExpectedEqualsActual)
         {
             var codeModule = RetrieveComponent(tdo, inputOutput.ModuleName).CodeModule;
             var expected   = inputOutput.Expected;
             var actual     = codeModule.Content();
             Assert.AreEqual(expected, actual);
         }
     }
 }
Пример #3
0
 private static void RunRenameRefactorScenario(RenameTestsDataObject tdo)
 {
     if (tdo.RefactorParamType == RefactorParams.Declaration)
     {
         tdo.RenameRefactoringUnderTest.Refactor(tdo.RenameModel.Target);
     }
     else if (tdo.RefactorParamType == RefactorParams.QualifiedSelection)
     {
         tdo.RenameRefactoringUnderTest.Refactor(tdo.QualifiedSelection);
     }
     else
     {
         tdo.RenameRefactoringUnderTest.Refactor();
     }
 }
Пример #4
0
 public static void PerformExpectedVersusActualRenameTests(RenameTestsDataObject tdo
                                                           , RenameTestModuleDefinition?inputOutput1
                                                           , RenameTestModuleDefinition?inputOutput2 = null
                                                           , RenameTestModuleDefinition?inputOutput3 = null
                                                           , RenameTestModuleDefinition?inputOutput4 = null)
 {
     try
     {
         InitializeTestDataObject(tdo, inputOutput1, inputOutput2, inputOutput3, inputOutput4);
         RunRenameRefactorScenario(tdo);
         CheckRenameRefactorTestResults(tdo);
     }
     finally
     {
         tdo.ParserState?.Dispose();
     }
 }
Пример #5
0
        private static void AddTestModuleDefinition(RenameTestsDataObject tdo, RenameTestModuleDefinition inputOutput)
        {
            if (inputOutput.Input_WithFauxCursor.Length > 0)
            {
                tdo.SelectionModuleName = inputOutput.ModuleName;
                if (inputOutput.Input_WithFauxCursor.Contains(RenameTests.FAUX_CURSOR))
                {
                    var numCursors = inputOutput.Input_WithFauxCursor.ToArray().Where(c => c.Equals(RenameTests.FAUX_CURSOR)).Count();
                    if (numCursors != 1)
                    {
                        Assert.Inconclusive($"{numCursors} found in FauxCursor input - only a single cursor is allowed.");
                    }
                    tdo.RawSelection = inputOutput.RenameSelection;
                    if (!tdo.RawSelection.HasValue)
                    {
                        Assert.Inconclusive($"Unable to set RawSelection field for test module {inputOutput.ModuleName}");
                    }

                    //FIXME is this still necessary? I think not...
                    //inputOutput.RenameSelection = tdo.RawSelection;
                }
            }
            tdo.ModuleTestSetupDefs.Add(inputOutput);
        }
Пример #6
0
        private static void InitializeTestDataObject(RenameTestsDataObject tdo
                                                     , RenameTestModuleDefinition?inputOutput1
                                                     , RenameTestModuleDefinition?inputOutput2 = null
                                                     , RenameTestModuleDefinition?inputOutput3 = null
                                                     , RenameTestModuleDefinition?inputOutput4 = null)
        {
            var  renameTMDs  = new List <RenameTestModuleDefinition>();
            bool cursorFound = false;

            foreach (var io in new[] { inputOutput1, inputOutput2, inputOutput3, inputOutput4 })
            {
                if (io.HasValue)
                {
                    var renameTMD = io.Value;
                    if (!renameTMD.Input_WithFauxCursor.Equals(string.Empty))
                    {
                        if (cursorFound)
                        {
                            Assert.Inconclusive($"Found multiple selection cursors ('{RenameTests.FAUX_CURSOR}') in the test input");
                        }
                        cursorFound = true;
                    }
                    renameTMDs.Add(renameTMD);
                }
            }

            if (!cursorFound)
            {
                Assert.Inconclusive($"Unable to determine selected target using '{RenameTests.FAUX_CURSOR}' in test input");
            }

            renameTMDs.ForEach(rtmd => AddTestModuleDefinition(tdo, rtmd));

            if (tdo.NewName.Length == 0)
            {
                Assert.Inconclusive("NewName is blank");
            }
            if (!tdo.RawSelection.HasValue)
            {
                Assert.Inconclusive("A User 'Selection' has not been defined for the test");
            }

            tdo.MsgBox = new Mock <IMessageBox>();
            tdo.MsgBox.Setup(m => m.ConfirmYesNo(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>())).Returns(tdo.MsgBoxReturn == ConfirmationOutcome.Yes);

            var activeIndex = renameTMDs.FindIndex(tmd => tmd.Input_WithFauxCursor != string.Empty);

            tdo.VBE = tdo.VBE ?? BuildProject(tdo.ProjectName, tdo.ModuleTestSetupDefs, activeIndex, tdo.UseLibraries);
            tdo.AdditionalSetup?.Invoke(tdo);
            (tdo.ParserState, tdo.RewritingManager) = MockParser.CreateAndParseWithRewritingManager(tdo.VBE);

            CreateQualifiedSelectionForTestCase(tdo);
            tdo.RenameModel = new RenameModel(tdo.ParserState.DeclarationFinder, tdo.QualifiedSelection)
            {
                NewName = tdo.NewName
            };
            Assert.IsTrue(tdo.RenameModel.Target.IdentifierName.Contains(tdo.OriginalName)
                          , $"Target aquired ({tdo.RenameModel.Target.IdentifierName} does not equal name specified ({tdo.OriginalName}) in the test");

            var presenter = new Mock <IRenamePresenter>();
            var factory   = GetFactoryMock(m => {
                presenter.Setup(p => p.Model).Returns(m);
                presenter.Setup(p => p.Show(It.IsAny <Declaration>()))
                .Callback(() => m.NewName = tdo.NewName)
                .Returns(m);
                presenter.Setup(p => p.Show())
                .Callback(() => m.NewName = tdo.NewName)
                .Returns(m);
                return(presenter);
            }, out var creator);
            var selectionService = MockedSelectionService(tdo.VBE);

            tdo.RenameRefactoringUnderTest = new RenameRefactoring(factory.Object, tdo.MsgBox.Object, tdo.ParserState, tdo.ParserState.ProjectsProvider, tdo.RewritingManager, selectionService);
        }
Пример #7
0
        internal static IVBComponent RetrieveComponent(RenameTestsDataObject tdo, string componentName)
        {
            var vbProject = tdo.VBE.VBProjects.Single(item => item.Name == tdo.ProjectName);

            return(vbProject.VBComponents.SingleOrDefault(item => item.Name == componentName));
        }