Exemplo n.º 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();
        }
Exemplo n.º 2
0
        public void OnNavigateToDocNotInProjectTest()
        {
            try
            {
                var mockDocumentEnumerator = new SequenceMock <IEnumerator>();
                var mockDte            = new Mock <DTE>();
                var mockDocuments      = new Mock <Documents>();
                var mockDocument       = new SequenceMock <Document>();
                var mockActiveDocument = new Mock <Document>();
                var mockTextSelection  = new SequenceMock <TextSelection>();
                var mockVirtualPoint   = new SequenceMock <VirtualPoint>();

                this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
                var mockSecondDocument = new SequenceMock <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 analysisHelper = this.SetCoreNoUI();
                bool           eventFired     = false;

                PrivateObject actual = new PrivateObject(this.package, new PrivateType(typeof(StyleCopVSPackage)));
                actual.SetFieldOrProperty("core", this.package.Core);

                // Register output generated event to test event fired
                this.package.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);

                // Use private type to set static private field
                PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));
                privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);

                // Execute
                PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
                taskUnderTestPrivateObject.Invoke("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");
            }
            catch (Exception ex)
            {
                // Use try catch to test a workaround on CI build (AppVeyor)
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 3
0
        public void OnNavigateToDocInProjectTest()
        {
            try
            {
                var mockDocumentEnumerator = new SequenceMock <IEnumerator>();
                var mockDte            = new Mock <DTE>();
                var mockDocuments      = new Mock <Documents>();
                var mockDocument       = new SequenceMock <Document>();
                var mockActiveDocument = new Mock <Document>();
                var mockTextSelection  = new SequenceMock <TextSelection>();
                var mockVirtualPoint   = new SequenceMock <VirtualPoint>();

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

                mockDocument.AddExpectationExpr(doc => doc.Activate());
                mockDocument.AddExpectationExpr(doc => doc.DTE, (Func <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);

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

                // Use private type to set static private field
                PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));
                privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);

                // Execute
                PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
                taskUnderTestPrivateObject.Invoke("OnNavigate", EventArgs.Empty);

                // Verify the required methods are called to show the violation
                mockTextSelection.Verify();
                mockVirtualPoint.Verify();
                mockDocument.Verify();
            }
            catch (Exception ex)
            {
                // Use try catch to test a workaround on CI build (AppVeyor)
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 4
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");
        }
        public void OnNavigateToDocNotInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
            var mockDte = new Mock<DTE>();
            var mockDocuments = new Mock<Documents>();
            var mockDocument = new SequenceMock<Document>();
            var mockActiveDocument = new Mock<Document>();
            var mockTextSelection = new SequenceMock<TextSelection>();
            var mockVirtualPoint = new SequenceMock<VirtualPoint>();

            this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
            var mockSecondDocument = new SequenceMock<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 analysisHelper = this.SetCoreNoUI();
            bool eventFired = false;
            var styleCopCore = (StyleCopCore)typeof(AnalysisHelper)
                .GetField("core", BindingFlags.Instance | BindingFlags.NonPublic)
                .GetValue(analysisHelper);
            styleCopCore.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);
            typeof(ProjectUtilities).GetField("serviceProvider", BindingFlags.Static | BindingFlags.NonPublic)
                .SetValue(null, this.mockServiceProvider.Instance);

            // Execute
            typeof(ViolationTask).GetMethod("OnNavigate", BindingFlags.Instance | BindingFlags.NonPublic)
                .Invoke(this.taskUnderTest, new object[] { 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");
        }
        public void OnNavigateToDocInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
            var mockDte = new Mock<DTE>();
            var mockDocuments = new Mock<Documents>();
            var mockDocument = new SequenceMock<Document>();
            var mockActiveDocument = new Mock<Document>();
            var mockTextSelection = new SequenceMock<TextSelection>();
            var mockVirtualPoint = new SequenceMock<VirtualPoint>();

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

            mockDocument.AddExpectationExpr(doc => doc.Activate());
            mockDocument.AddExpectationExpr(doc => doc.DTE, (Func<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);
            typeof(ProjectUtilities).GetField("serviceProvider", BindingFlags.Static | BindingFlags.NonPublic)
                .SetValue(null, this.mockServiceProvider.Instance);

            // Execute
            typeof(ViolationTask).GetMethod("OnNavigate", BindingFlags.Instance | BindingFlags.NonPublic)
                .Invoke(this.taskUnderTest, new object[] { EventArgs.Empty });

            // Verify the required methods are called to show the violation
            mockTextSelection.Verify();
            mockVirtualPoint.Verify();
            mockDocument.Verify();
        }
Exemplo n.º 7
0
        public void OnNavigateToDocNotInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
            var mockDte = new Mock<DTE>();
            var mockDocuments = new Mock<Documents>();
            var mockDocument = new SequenceMock<Document>();
            var mockActiveDocument = new Mock<Document>();
            var mockTextSelection = new SequenceMock<TextSelection>();
            var mockVirtualPoint = new SequenceMock<VirtualPoint>();

            this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
            var mockSecondDocument = new SequenceMock<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 = this.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.serviceProvider = 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");
        }
Exemplo n.º 8
0
        public void OnNavigateToDocInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
            var mockDte = new Mock<DTE>();
            var mockDocuments = new Mock<Documents>();
            var mockDocument = new SequenceMock<Document>();
            var mockActiveDocument = new Mock<Document>();
            var mockTextSelection = new SequenceMock<TextSelection>();
            var mockVirtualPoint = new SequenceMock<VirtualPoint>();

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

            mockDocument.AddExpectationExpr(doc => doc.Activate());
            mockDocument.AddExpectationExpr(doc => doc.DTE, (Func<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.serviceProvider = 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();
        }
Exemplo n.º 9
0
        public void OnNavigateToDocNotInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
            var mockDte = new Mock<DTE>();
            var mockDocuments = new Mock<Documents>();
            var mockDocument = new SequenceMock<Document>();
            var mockActiveDocument = new Mock<Document>();
            var mockTextSelection = new SequenceMock<TextSelection>();
            var mockVirtualPoint = new SequenceMock<VirtualPoint>();

            this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
            var mockSecondDocument = new SequenceMock<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 analysisHelper = this.SetCoreNoUI();
            bool eventFired = false;

            PrivateObject actual = new PrivateObject(this.package, new PrivateType(typeof(StyleCopVSPackage)));
            actual.SetFieldOrProperty("core", this.package.Core);

            // Register output generated event to test event fired
            this.package.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);

            // Use private type to set static private field
            PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));
            privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);

            // Execute
            PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
            taskUnderTestPrivateObject.Invoke("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");
        }
Exemplo n.º 10
0
        public void OnNavigateToDocInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
            var mockDte = new Mock<DTE>();
            var mockDocuments = new Mock<Documents>();
            var mockDocument = new SequenceMock<Document>();
            var mockActiveDocument = new Mock<Document>();
            var mockTextSelection = new SequenceMock<TextSelection>();
            var mockVirtualPoint = new SequenceMock<VirtualPoint>();

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

            mockDocument.AddExpectationExpr(doc => doc.Activate());
            mockDocument.AddExpectationExpr(doc => doc.DTE, (Func<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);

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

            // Use private type to set static private field
            PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));
            privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);

            // Execute
            PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
            taskUnderTestPrivateObject.Invoke("OnNavigate", EventArgs.Empty);

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