Example #1
0
        public void VsOnNavigateToDocInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock <IEnumerator>();
            var mockDte            = new Mock <EnvDTE.DTE>();
            var mockDocuments      = new Mock <EnvDTE.Documents>();
            var mockDocument       = new SequenceMock <EnvDTE.Document>();
            var mockActiveDocument = new Mock <EnvDTE.Document>();
            var mockTextSelection  = new SequenceMock <EnvDTE.TextSelection>();
            var mockVirtualPoint   = new SequenceMock <EnvDTE.VirtualPoint>();

            this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, this.violation.File);

            mockDocument.AddExpectationExpr(doc => doc.Activate());
            mockDocument.AddExpectationExpr(doc => doc.DTE, (Func <EnvDTE.DTE>) delegate { return((EnvDTE.DTE)mockDte.Instance); });

            mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);

            mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
            mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);

            mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));

            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
            ProjectUtilities_Accessor.SetServiceProvider(this.mockServiceProvider.Instance);

            // Execute
            this.taskUnderTest.OnNavigate(EventArgs.Empty);

            // Verify the required methods are called to show the violation
            mockTextSelection.Verify();
            mockVirtualPoint.Verify();
            mockDocument.Verify();
        }
Example #2
0
        public void VsOnNavigateToDocNotInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock <IEnumerator>();
            var mockDte            = new Mock <EnvDTE.DTE>();
            var mockDocuments      = new Mock <EnvDTE.Documents>();
            var mockDocument       = new SequenceMock <EnvDTE.Document>();
            var mockActiveDocument = new Mock <EnvDTE.Document>();
            var mockTextSelection  = new SequenceMock <EnvDTE.TextSelection>();
            var mockVirtualPoint   = new SequenceMock <EnvDTE.VirtualPoint>();

            this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
            var mockSecondDocument = new SequenceMock <EnvDTE.Document>();

            mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), true);
            mockDocumentEnumerator.AddExpectationExpr(docs => docs.Current, mockSecondDocument.Instance);
            mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), false);

            mockSecondDocument.AddExpectationExpr(doc => doc.FullName, "DummyFile.txt");

            AnalysisHelper_Accessor analysisHelper = SetCoreNoUI();
            bool eventFired = false;

            analysisHelper.core.OutputGenerated += (sender, args) => { eventFired = true; };

            mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);

            mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
            mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);

            mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));

            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
            ProjectUtilities_Accessor.SetServiceProvider(this.mockServiceProvider.Instance);

            // Execute
            this.taskUnderTest.OnNavigate(EventArgs.Empty);

            // Verify the required methods are called to show the violation
            mockTextSelection.Verify();
            mockVirtualPoint.Verify();
            mockDocument.Verify();

            Assert.IsTrue(eventFired, "Core did not fire output event");
        }
Example #3
0
        public void VsOnNavigateEmptyDocumentTest()
        {
            bool eventFired = false;
            var  mockDte    = new Mock <EnvDTE.DTE>();

            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(SVsSolutionBuildManager)), new MockSolutionBuildManager());
            AnalysisHelper_Accessor analysisHelper = SetCoreNoUI();

            analysisHelper.core.OutputGenerated += (sender, args) => { eventFired = true; };

            ProjectUtilities_Accessor.SetServiceProvider(this.mockServiceProvider.Instance);

            // Does nothing - included for code coverage and to catch it if it starts doing something unexpectedtly
            this.taskUnderTestShell.Document = string.Empty;
            this.taskUnderTest.OnNavigate(EventArgs.Empty);

            Assert.IsTrue(eventFired, "Core did not fire output event");
        }