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); }
private async Task FinishedAddingItemAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); //Now we can finally insert the header into the new item. while (_addedItems.Count > 0) { var item = _addedItems.Pop(); var content = item.GetContent(out var wasAlreadyOpen, this); if (content == null) { continue; } var headers = LicenseHeaderFinder.GetHeaderDefinitionForItem(item); if (headers == null) { continue; } var result = await LicenseHeaderReplacer.RemoveOrReplaceHeader( new LicenseHeaderContentInput (content, item.FileNames[1], headers, item.GetAdditionalProperties())); await CoreHelpers.HandleResultAsync(result, this, wasAlreadyOpen, false); } _currentCommandEvents.AfterExecute -= FinishedAddingItem; }
public void GetLanguageFromExtension_LanguagesAreEmpty_ReturnsNull() { var replacer = new LicenseHeaderReplacer(Enumerable.Empty <Language>(), Enumerable.Empty <string>()); var language = replacer.GetLanguageFromExtension(".cs"); Assert.That(language, Is.Null); }
public async Task RemoveOrReplaceHeader_PathIsNull_ReturnsReplacerResultFileNotFound() { var replacer = new LicenseHeaderReplacer(Enumerable.Empty <Language>(), Enumerable.Empty <string>()); var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderPathInput (null, null)); Assert.That(actual.Error.Type, Is.EqualTo(ReplacerErrorType.FileNotFound)); }
public async Task RemoveOrReplaceHeader_ContentInputWithoutHeader_ReturnsReplacerResultNoHeaderFound() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var path = CreateTestFile(".cs"); var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderContentInput ("test content", path, new Dictionary <string, string[]>())); Assert.That(actual.Error.Type, Is.EqualTo(ReplacerErrorType.NoHeaderFound)); }
public void GetLanguageFromExtension_LanguagesAreNull_DoesNotThrowExceptionAndReturnsNull() { var replacer = new LicenseHeaderReplacer(null, Enumerable.Empty <string>()); Language language = null; Assert.That(() => language = replacer.GetLanguageFromExtension(".cs"), Throws.Nothing); Assert.That(language, Is.Null); }
public async Task RemoveOrReplaceHeader_LanguageNotPresent_ReturnsReplacerResultLanguageNotFound() { var replacer = new LicenseHeaderReplacer(Enumerable.Empty <Language>(), Enumerable.Empty <string>()); var path = CreateTestFile(".cs"); var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderPathInput (path, null)); Assert.That(actual.Error.Type, Is.EqualTo(ReplacerErrorType.LanguageNotFound)); }
public async Task RemoveOrReplaceHeader_DocumentIsLicenseHeaderFile_ReturnsReplacerResultLicenseHeaderDocument() { var replacer = new LicenseHeaderReplacer(Enumerable.Empty <Language>(), Enumerable.Empty <string>()); var path = CreateTestFile(); var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderPathInput (path, null)); Assert.That(actual.Error.Type, Is.EqualTo(ReplacerErrorType.LicenseHeaderDocument)); }
public async Task RemoveOrReplaceHeader_ContentInputInvalidHeader_ReturnsReplacerResultParsingError() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var path = CreateTestFile(".cs", true); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// first line", "// copyright" } } }; var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderContentInput ("#endregion", path, headers) { IgnoreNonCommentText = true }); Assert.That(actual.Error.Type, Is.EqualTo(ReplacerErrorType.ParsingError)); }
public async Task RemoveOrReplaceHeader_PathInputHeadersWithNonCommentText_ReturnsReplacerResultNonCommentText() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var path = CreateTestFile(".cs"); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// first line 1", "// second line", "copyright" } } }; var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderPathInput (path, headers)); Assert.That(actual.Error.Type, Is.EqualTo(ReplacerErrorType.NonCommentText)); }
public async Task RemoveOrReplaceHeader_PathInputEmptyHeader_ReturnsReplacerResultEmptyHeader() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var path = CreateTestFile(".cs"); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "" } } }; var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderPathInput (path, headers)); Assert.That(actual.Error.Type, Is.EqualTo(ReplacerErrorType.EmptyHeader)); }
public async Task RemoveOrReplaceHeader_LicenseHeaderContentInputsInvalid_ReturnsNoReplacerResult() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var licenseHeaderInputs = new List <LicenseHeaderContentInput> { new LicenseHeaderContentInput("test content3", CreateTestFile(".js"), new Dictionary <string, string[]>()) }; var actualResults = (await replacer.RemoveOrReplaceHeader(licenseHeaderInputs, new Progress <ReplacerProgressContentReport>(), new CancellationToken())).ToList(); Assert.That(actualResults.Count, Is.EqualTo(0)); }
public async Task RemoveOrReplaceHeader_ValidContentInput_DoesNotThrowExceptionAndReturnsSuccess() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var path = CreateTestFile(".cs"); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// first line", "// copyright" } } }; var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderContentInput ("test content", path, headers)); Assert.That(actual.IsSuccess, Is.True); }
public void RemoveOrReplaceHeader_ValidInput_DoesNotThrowExceptionAndReturnsSuccess() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var path = CreateTestFile(".cs"); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// first line 1", "// second line", "// copyright" } } }; ReplacerResult actual = null; Assert.That(async() => actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderPathInput(path, headers)), Throws.Nothing); Assert.That(actual.IsSuccess, Is.True); }
public bool ShouldBeVisible(ProjectItem item) { ThreadHelper.ThrowIfNotOnUIThread(); var visible = false; if (ProjectItemInspection.IsPhysicalFile(item)) { visible = LicenseHeaderReplacer.IsValidPathInput(item.FileNames[1]) && item.CanBeOpened(); } return(visible); }
public void SetUp() { _extensionMock = MockRepository.GenerateMock <ILicenseHeaderExtension>(); _optionsPage = MockRepository.GenerateMock <IOptionsPage>(); _replacer = new LicenseHeaderReplacer(_extensionMock); _projectItem = MockRepository.GenerateMock <ProjectItem>(); _languagesPage = MockRepository.GenerateMock <ILanguagesPage>(); _extensionMock.Expect(x => x.LanguagesPage).Return(_languagesPage); _extensionMock.Expect(x => x.OptionsPage).Return(_optionsPage); _optionsPage.Expect(x => x.UseRequiredKeywords).Return(true); _optionsPage.Expect(x => x.RequiredKeywords).Return(""); _projectItem.Stub(x => x.Open(Constants.vsViewKindTextView)).Return(MockRepository.GenerateMock <Window>()); }
public void TestNoProjectItems() { Solution solution = MockRepository.GenerateStub <Solution>(); ILicenseHeaderExtension extension = MockRepository.GenerateStub <ILicenseHeaderExtension>(); LinkedFileFilter linkedFileFilter = MockRepository.GenerateStrictMock <LinkedFileFilter>(solution); LicenseHeaderReplacer licenseHeaderReplacer = MockRepository.GenerateStrictMock <LicenseHeaderReplacer>(extension); LinkedFileHandler linkedFileHandler = new LinkedFileHandler(); linkedFileHandler.Handle(licenseHeaderReplacer, linkedFileFilter); Assert.AreEqual(string.Empty, linkedFileHandler.Message); }
public async Task RemoveOrReplaceHeader_ContentInputHeadersWithNonCommentText_ReturnsReplacerResultNonCommentText() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// first line 1", "// second line", "copyright" } } }; var licenseHeaderInputs = new List <LicenseHeaderContentInput> { new LicenseHeaderContentInput("test content1", CreateTestFile(".cs"), headers) }; var actualResults = (await replacer.RemoveOrReplaceHeader(licenseHeaderInputs, new Progress <ReplacerProgressContentReport>(), new CancellationToken())).ToList(); Assert.That(actualResults.Count, Is.EqualTo(1)); Assert.That(actualResults.Single().IsSuccess, Is.False); Assert.That(actualResults.Single().Error.Type, Is.EqualTo(ReplacerErrorType.NonCommentText)); }
public async Task RemoveOrReplaceHeader_LicenseHeaderPathInputsValidLicenseHeaderDefinitionFile_ReturnsReplacerResultSuccess() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var path = CreateTestFile(); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// first line 1", "// second line", "// copyright" } } }; var licenseHeaderInputs = new List <LicenseHeaderPathInput> { new LicenseHeaderPathInput(path, headers) }; var actualResults = await replacer.RemoveOrReplaceHeader(licenseHeaderInputs, new Progress <ReplacerProgressReport>(), new CancellationToken()); Assert.That(actualResults.Error, Is.Null); Assert.That(actualResults.IsSuccess, Is.True); }
public async Task RemoveOrReplaceHeader_PathInputWithNonCommentText_ReturnsReplacerResultNonCommentText() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var path = CreateTestFile(".cs"); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "first line 1" } } }; var licenseHeaderInputs = new List <LicenseHeaderPathInput> { new LicenseHeaderPathInput(path, headers) }; var actualResults = await replacer.RemoveOrReplaceHeader(licenseHeaderInputs, new Progress <ReplacerProgressReport>(), new CancellationToken()); Assert.That(actualResults.IsSuccess, Is.False); Assert.That(actualResults.Error, Has.Count.EqualTo(1)); Assert.That(actualResults.Error.Single().Type, Is.EqualTo(ReplacerErrorType.NonCommentText)); }
public async Task RemoveOrReplaceHeader_PathInputLanguagesWithExtensionNull_ReturnsReplacerResultMiscellaneous() { var languages = new List <Language> { new Language { Extensions = null, LineComment = "//", BeginComment = "/*", EndComment = "*/", BeginRegion = "#region", EndRegion = "#endregion" } }; var replacer = new LicenseHeaderReplacer(languages, Enumerable.Empty <string>()); var path = CreateTestFile(".cs"); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// first line 1", "// second line", "copyright" } } }; var actual = await replacer.RemoveOrReplaceHeader(new LicenseHeaderPathInput (path, headers)); Assert.That(actual.Error.Type, Is.EqualTo(ReplacerErrorType.Miscellaneous)); }
public void Handle(LicenseHeaderReplacer licenseHeaderReplacer, ILinkedFileFilter linkedFileFilter) { foreach (ProjectItem projectItem in linkedFileFilter.ToBeProgressed) { var headers = LicenseHeaderFinder.GetHeaderRecursive(projectItem); licenseHeaderReplacer.RemoveOrReplaceHeader(projectItem, headers, true); } if (linkedFileFilter.NoLicenseHeaderFile.Any() || linkedFileFilter.NotInSolution.Any()) { List <ProjectItem> notProgressedItems = linkedFileFilter.NoLicenseHeaderFile.Concat(linkedFileFilter.NotInSolution).ToList(); List <string> notProgressedNames = notProgressedItems.Select(x => x.Name).ToList(); Message += string.Format(Resources.LinkedFileUpdateInformation, string.Join("\n", notProgressedNames)) .Replace(@"\n", "\n"); } }
public async Task RemoveOrReplaceHeader_ContentInputWithInvalidHeader_ReturnsReplacerResultParsingError() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// test header" } } }; var licenseHeaderInputs = new List <LicenseHeaderContentInput> { new LicenseHeaderContentInput("#endregion", CreateTestFile(".cs"), headers) { IgnoreNonCommentText = true } }; var actualResults = (await replacer.RemoveOrReplaceHeader(licenseHeaderInputs, new Progress <ReplacerProgressContentReport>(), new CancellationToken())).ToList(); var replacerResult = actualResults[0]; Assert.That(replacerResult.IsSuccess, Is.False); Assert.That(replacerResult.Error.Type, Is.EqualTo(ReplacerErrorType.ParsingError)); }
public async Task RemoveOrReplaceHeader_LicenseHeaderContentInputsValid_ReturnsReplacerResultSuccess() { var replacer = new LicenseHeaderReplacer(_languages, Enumerable.Empty <string>()); var headers = new Dictionary <string, string[]> { { ".cs", new[] { "// first line", "// copyright" } }, { ".ts", new[] { "// first line", "// copyright" } } }; var licenseHeaderInputs = new List <LicenseHeaderContentInput> { new LicenseHeaderContentInput("test content1", CreateTestFile(".cs"), headers), new LicenseHeaderContentInput("test content2", CreateTestFile(".ts"), headers) }; var actualResults = (await replacer.RemoveOrReplaceHeader(licenseHeaderInputs, new Progress <ReplacerProgressContentReport>(), new CancellationToken())).ToList(); Assert.That(actualResults.Count, Is.EqualTo(2)); foreach (var result in actualResults) { Assert.That(result.IsSuccess, Is.True); } }
private static void RunProgram(Options options) { if (!options.IsValid(out var errorMessage)) { WriteLineColor("The command-line invocation was syntactically correct, but the following semantic errors were detected:", c_colorError); WriteLineColor(errorMessage, c_colorError); Exit(false); } if (options.Configuration != null) { System.Console.WriteLine($"Loading configuration from \"{options.Configuration.FullName}\""); s_defaultCoreSettings = JsonOptionsManager.DeserializeAsync <CoreOptions> (options.Configuration.FullName).Result; } else { System.Console.WriteLine("No configuration file specified, using default configuration."); s_defaultCoreSettings = new CoreOptions(true); } s_headerExtractor = new LicenseHeaderExtractor(); s_replacer = new LicenseHeaderReplacer(s_defaultCoreSettings.Languages, CoreOptions.RequiredKeywordsAsEnumerable(s_defaultCoreSettings.RequiredKeywords)); UpdateLicenseHeaders(options); }
public RemoveLicenseHeaderFromAllFilesInSolutionCommand(IVsStatusbar statusBar, LicenseHeaderReplacer licenseReplacer) { _statusBar = statusBar; _licenseReplacer = licenseReplacer; }
public AddLicenseHeaderToAllProjectsButtonHandler(LicenseHeaderReplacer licenseReplacer, DTE2 dte2) { _licenseReplacer = licenseReplacer; _dte2 = dte2; }
public AddLicenseHeaderToAllProjectsButtonHandler(LicenseHeaderReplacer licenseReplacer, IDefaultLicenseHeaderPage defaultLicenseHeaderPage, DTE2 dte2) { _licenseReplacer = licenseReplacer; _defaultLicenseHeaderPage = defaultLicenseHeaderPage; _dte2 = dte2; }
public AddLicenseHeaderToAllFilesCommand(LicenseHeaderReplacer licenseReplacer) { this.licenseReplacer = licenseReplacer; }
public AddLicenseHeaderToAllFilesInProjectCommand(LicenseHeaderReplacer licenseReplacer) { _licenseReplacer = licenseReplacer; }