示例#1
0
        public void TestProjectItemWithoutLicenseHeaderFile()
        {
            Solution solution = MockRepository.GenerateMock <Solution>();

            solution.Expect(x => x.FullName).Return(@"d:\projects\Stuff.sln");

            DTE dte = MockRepository.GenerateMock <DTE>();

            dte.Expect(x => x.Solution).Return(solution);

            ProjectItems projectItems = MockRepository.GenerateMock <ProjectItems>();

            ProjectItem linkedFile = MockRepository.GenerateMock <ProjectItem>();

            linkedFile.Expect(x => x.DTE).Return(dte);
            projectItems.Expect(x => x.Parent).Return(new object());
            linkedFile.Expect(x => x.Collection).Return(projectItems);

            solution.Expect(x => x.FindProjectItem("linkedFile.cs")).Return(linkedFile);


            linkedFile.Expect(x => x.Name).Return("linkedFile.cs");
            linkedFile.Expect(x => x.Properties).Return(null);


            LinkedFileFilter linkedFileFilter = new LinkedFileFilter(solution);

            linkedFileFilter.Filter(new List <ProjectItem> {
                linkedFile
            });

            Assert.IsEmpty(linkedFileFilter.ToBeProgressed);
            Assert.IsNotEmpty(linkedFileFilter.NoLicenseHeaderFile);
            Assert.IsEmpty(linkedFileFilter.NotInSolution);
        }
        public void TestNoLicenseHeaderFile()
        {
            ILicenseHeaderExtension extension   = MockRepository.GenerateStub <ILicenseHeaderExtension> ();
            ProjectItem             projectItem = MockRepository.GenerateMock <ProjectItem>();

            projectItem.Expect(x => x.Name).Return("projectItem.cs");

            ILinkedFileFilter     linkedFileFilter      = MockRepository.GenerateMock <ILinkedFileFilter> ();
            LicenseHeaderReplacer licenseHeaderReplacer = MockRepository.GenerateStrictMock <LicenseHeaderReplacer> (extension);

            linkedFileFilter.Expect(x => x.NoLicenseHeaderFile).Return(new List <ProjectItem> {
                projectItem
            });
            linkedFileFilter.Expect(x => x.ToBeProgressed).Return(new List <ProjectItem> ());
            linkedFileFilter.Expect(x => x.NotInSolution).Return(new List <ProjectItem> ());


            LinkedFileHandler linkedFileHandler = new LinkedFileHandler();

            linkedFileHandler.Handle(licenseHeaderReplacer, linkedFileFilter);

            string expectedMessage = string.Format(Resources.LinkedFileUpdateInformation, "projectItem.cs")
                                     .Replace(@"\n", "\n");

            Assert.AreEqual(expectedMessage, linkedFileHandler.Message);
        }
示例#3
0
        public void TestProjectItemWithLicenseHeaderFile()
        {
            string licenseHeaderFileName = "test.licenseheader";

            Solution    solution   = MockRepository.GenerateMock <Solution>();
            ProjectItem linkedFile = MockRepository.GenerateMock <ProjectItem>();

            ProjectItem licenseHeaderFile = MockRepository.GenerateStub <ProjectItem>();

            licenseHeaderFile.Expect(x => x.FileCount).Return(1);
            licenseHeaderFile.Expect(x => x.FileNames[0]).Return(licenseHeaderFileName);

            using (var writer = new StreamWriter(licenseHeaderFileName))
            {
                writer.WriteLine("extension: .cs");
                writer.WriteLine("//test");
            }

            ProjectItems projectItems = MockRepository.GenerateStub <ProjectItems>();

            projectItems.Stub(x => x.GetEnumerator())
            .Return(null)
            .WhenCalled(
                x => x.ReturnValue =
                    new List <ProjectItem> {
                licenseHeaderFile
            }.GetEnumerator()
                );

            linkedFile.Expect(x => x.ProjectItems).Return(projectItems);
            linkedFile.Expect(x => x.Name).Return("linkedFile.cs");
            solution.Expect(x => x.FindProjectItem("linkedFile.cs")).Return(linkedFile);


            LinkedFileFilter linkedFileFilter = new LinkedFileFilter(solution);

            linkedFileFilter.Filter(new List <ProjectItem> {
                linkedFile
            });

            Assert.IsNotEmpty(linkedFileFilter.ToBeProgressed);
            Assert.IsEmpty(linkedFileFilter.NoLicenseHeaderFile);
            Assert.IsEmpty(linkedFileFilter.NotInSolution);

            //Cleanup
            File.Delete(licenseHeaderFileName);
        }
示例#4
0
        public void TestProjectItemWithoutLicenseHeaderFile()
        {
            Solution    solution   = MockRepository.GenerateMock <Solution> ();
            ProjectItem linkedFile = MockRepository.GenerateMock <ProjectItem> ();

            solution.Expect(x => x.FindProjectItem("linkedFile.cs")).Return(linkedFile);
            linkedFile.Expect(x => x.Name).Return("linkedFile.cs");
            linkedFile.Expect(x => x.Collection.Parent).Return(new object());

            LinkedFileFilter linkedFileFilter = new LinkedFileFilter(solution);

            linkedFileFilter.Filter(new List <ProjectItem> {
                linkedFile
            });

            Assert.IsEmpty(linkedFileFilter.ToBeProgressed);
            Assert.IsNotEmpty(linkedFileFilter.NoLicenseHeaderFile);
            Assert.IsEmpty(linkedFileFilter.NotInSolution);
        }
        public void TestIsLicenseHeader()
        {
            ProjectItem licenseHeader = MockRepository.GenerateMock <ProjectItem>();

            licenseHeader.Expect(x => x.Name).Return("test.licenseheader");

            ProjectItem notLicenseHeader = MockRepository.GenerateMock <ProjectItem>();

            notLicenseHeader.Expect(x => x.Name).Return("test.cs");

            Assert.IsTrue(ProjectItemInspection.IsLicenseHeader(licenseHeader));
            Assert.IsFalse(ProjectItemInspection.IsLicenseHeader(notLicenseHeader));
        }
            private void AddDocumentToProjectItem(string name, ProjectItem projectItem)
            {
                var parent = MockRepository.GenerateMock <EnvDTE.Document>();

                parent.Expect(x => x.FullName).Return("");

                var editPoint = MockRepository.GenerateMock <EditPoint>();

                editPoint.Expect(x => x.GetText(null)).IgnoreArguments().Return("");

                var textDocument = MockRepository.GenerateMock <TextDocument>();

                textDocument.Expect(x => x.CreateEditPoint()).IgnoreArguments().Return(editPoint);
                textDocument.Expect(x => x.Parent).Return(parent);

                var documentMock = MockRepository.GenerateMock <EnvDTE.Document>();

                documentMock.Expect(x => x.Object("TextDocument")).Return(textDocument);
                projectItem.Expect(x => x.Kind).Return(Constants.vsProjectItemKindPhysicalFile);
                projectItem.Expect(x => x.Document).Return(documentMock);
                projectItem.Expect(x => x.Name).Return(name);
            }
        public void TestIsPhysicalFile()
        {
            ProjectItem physicalFile = MockRepository.GenerateMock <ProjectItem>();

            physicalFile.Expect(x => x.Kind).Return(EnvDTE.Constants.vsProjectItemKindPhysicalFile);

            ProjectItem virtualFolder = MockRepository.GenerateMock <ProjectItem> ();

            virtualFolder.Expect(x => x.Kind).Return(EnvDTE.Constants.vsProjectItemKindVirtualFolder);


            Assert.IsTrue(ProjectItemInspection.IsPhysicalFile(physicalFile));
            Assert.IsFalse(ProjectItemInspection.IsPhysicalFile(virtualFolder));
        }
            public void NoPhysicalFile_Kind()
            {
                _projectItem.Expect(x => x.Kind).Return(Constants.vsProjectItemKindSubProject);

                var result = _replacer.TryCreateDocument(_projectItem, out _document, out _wasOpen);

                Assert.That(result, Is.EqualTo(CreateDocumentResult.NoPhysicalFile));
            }
            private void AddDocumentToProjectItem(string name, ProjectItem projectItem)
            {
                var parent = MockRepository.GenerateMock<EnvDTE.Document> ();
                parent.Expect (x => x.FullName).Return ("");

                var editPoint = MockRepository.GenerateMock<EditPoint> ();
                editPoint.Expect (x => x.GetText (null)).IgnoreArguments ().Return ("");

                var textDocument = MockRepository.GenerateMock<TextDocument> ();
                textDocument.Expect (x => x.CreateEditPoint ()).IgnoreArguments ().Return (editPoint);
                textDocument.Expect (x => x.Parent).Return (parent);

                var documentMock = MockRepository.GenerateMock<EnvDTE.Document> ();
                documentMock.Expect (x => x.Object ("TextDocument")).Return (textDocument);
                projectItem.Expect (x => x.Kind).Return (Constants.vsProjectItemKindPhysicalFile);
                projectItem.Expect (x => x.Document).Return (documentMock);
                projectItem.Expect (x => x.Name).Return (name);
            }