public void DoesNotSaveOrSetReplacementSelectionOnRecoverSelections_SelectionNotSavedPreviously_ModuleNotOpen()
        {
            var selectionServiceMock = TestSelectionServiceMock();
            var parseManager         = new Mock <IParseManager>().Object;
            var selectionRecoverer   = new SelectionRecoverer(selectionServiceMock.Object, parseManager);

            selectionServiceMock.Setup(m => m.OpenModules())
            .Returns(() => _testModuleSelections.Take(2).Select(qs => qs.QualifiedName).ToList());

            var selectionReplacement = new Selection(22, 2, 44, 5);

            selectionRecoverer.SaveSelections(_testModuleSelections.Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2));
            selectionRecoverer.ReplaceSavedSelection(_testModuleSelections[2].QualifiedName, selectionReplacement);
            selectionRecoverer.RecoverSavedSelections();

            selectionServiceMock.Verify(m => m.Selection(_testModuleSelections[0].QualifiedName), Times.Once);
            selectionServiceMock.Verify(m => m.Selection(_testModuleSelections[1].QualifiedName), Times.Once);
            selectionServiceMock.Verify(m => m.Selection(_testModuleSelections[2].QualifiedName), Times.Never);
            selectionServiceMock.Verify(m => m.Selection(_testModuleSelections[3].QualifiedName), Times.Never);

            selectionServiceMock.Verify(m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, _testModuleSelections[0].Selection), Times.Once);
            selectionServiceMock.Verify(m => m.TrySetSelection(_testModuleSelections[1].QualifiedName, _testModuleSelections[1].Selection), Times.Once);
            selectionServiceMock.Verify(m => m.TrySetSelection(_testModuleSelections[2].QualifiedName, It.IsAny <Selection>()), Times.Never);
            selectionServiceMock.Verify(m => m.TrySetSelection(_testModuleSelections[3].QualifiedName, It.IsAny <Selection>()), Times.Never);
        }
        public void ReplacementSelectionOverwritesAdjustmentOnRecoverSelections()
        {
            var selectionServiceMock = TestSelectionServiceMock();
            var parseManager         = new Mock <IParseManager>().Object;
            var selectionRecoverer   = new SelectionRecoverer(selectionServiceMock.Object, parseManager);

            var selectionOffset      = new Selection(0, 2, 4, 5);
            var selectionReplacement = new Selection(22, 2, 44, 5);

            selectionRecoverer.SaveSelections(_testModuleSelections
                                              .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(1));
            selectionRecoverer.AdjustSavedSelection(_testModuleSelections[0].QualifiedName, selectionOffset);
            selectionRecoverer.ReplaceSavedSelection(_testModuleSelections[0].QualifiedName, selectionReplacement);
            selectionRecoverer.RecoverSavedSelections();

            selectionServiceMock.Verify(
                m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, selectionReplacement), Times.Once);
        }
        public void SetsExactlySavedSelectionsOnRecoverSelections()
        {
            var selectionServiceMock = TestSelectionServiceMock();
            var parseManager         = new Mock <IParseManager>().Object;
            var selectionRecoverer   = new SelectionRecoverer(selectionServiceMock.Object, parseManager);

            selectionRecoverer.SaveSelections(_testModuleSelections
                                              .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2));
            selectionRecoverer.RecoverSavedSelections();

            foreach (var qualifiedSelection in _testModuleSelections.Take(2))
            {
                selectionServiceMock.Verify(
                    m => m.TrySetSelection(qualifiedSelection.QualifiedName, qualifiedSelection.Selection), Times.Once);
            }

            selectionServiceMock.Verify(
                m => m.TrySetSelection(_testModuleSelections[2].QualifiedName, It.IsAny <Selection>()), Times.Never);
        }
        public void SetsReplacementSelectionOnRecoverSelections_SelectionSavedPreviously()
        {
            var selectionServiceMock = TestSelectionServiceMock();
            var parseManager         = new Mock <IParseManager>().Object;
            var selectionRecoverer   = new SelectionRecoverer(selectionServiceMock.Object, parseManager);

            var selectionReplacement = new Selection(22, 2, 44, 5);

            selectionRecoverer.SaveSelections(_testModuleSelections
                                              .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2));
            selectionRecoverer.ReplaceSavedSelection(_testModuleSelections[0].QualifiedName, selectionReplacement);
            selectionRecoverer.RecoverSavedSelections();

            selectionServiceMock.Verify(
                m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, selectionReplacement), Times.Once);
            selectionServiceMock.Verify(
                m => m.TrySetSelection(_testModuleSelections[1].QualifiedName, _testModuleSelections[1].Selection),
                Times.Once);
            selectionServiceMock.Verify(
                m => m.TrySetSelection(_testModuleSelections[2].QualifiedName, It.IsAny <Selection>()), Times.Never);
        }
        public void SetsModifiedSelectionAfterOffsetIsAppliedOnRecoverSelections()
        {
            var selectionServiceMock = TestSelectionServiceMock();
            var parseManager         = new Mock <IParseManager>().Object;
            var selectionRecoverer   = new SelectionRecoverer(selectionServiceMock.Object, parseManager);

            var selectionOffset = new Selection(0, 2, 4, 5);

            selectionRecoverer.SaveSelections(_testModuleSelections
                                              .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2));
            selectionRecoverer.AdjustSavedSelection(_testModuleSelections[0].QualifiedName, selectionOffset);
            selectionRecoverer.RecoverSavedSelections();

            var expectedAdjustedSelection = _testModuleSelections[0].Selection.Offset(selectionOffset);

            selectionServiceMock.Verify(
                m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, expectedAdjustedSelection), Times.Once);
            selectionServiceMock.Verify(
                m => m.TrySetSelection(_testModuleSelections[1].QualifiedName, _testModuleSelections[1].Selection),
                Times.Once);
            selectionServiceMock.Verify(
                m => m.TrySetSelection(_testModuleSelections[2].QualifiedName, It.IsAny <Selection>()), Times.Never);
        }