public void ReplaceHeaderIfNecessary() { var skippedText = SkipText(); if (!string.IsNullOrEmpty(skippedText)) { RemoveHeader(skippedText); } string existingHeader = GetExistingHeader(); if (!_header.IsEmpty) { if (existingHeader != _header.Text) { ReplaceHeader(existingHeader, _header.Text); } } else { RemoveHeader(existingHeader); } if (!string.IsNullOrEmpty(skippedText)) { AddHeader(LicenseHeaderPreparer.Prepare(skippedText, GetText(), _commentParser)); } }
public void TestLicenseHeaderWhereCurrentHeaderHasComment() { var currentHeaderText = "//HighlyRelevantComment"; var toBeInsertedHeaderText = "//Testtext" + Environment.NewLine; var commentParserMock = MockRepository.GenerateMock<ICommentParser>(); commentParserMock.Expect(x => x.Parse(currentHeaderText)).Return("OhOurCurrentHeaderTextHasAComment"); string preparedHeader = LicenseHeaderPreparer.Prepare(toBeInsertedHeaderText, currentHeaderText, commentParserMock); Assert.AreEqual (toBeInsertedHeaderText + Environment.NewLine, preparedHeader); }
public void TestLicenseHeaderWithEndingNewLine() { var currentHeaderText = "nothingRelevant"; var toBeInsertedHeaderText = "//Testtext" + Environment.NewLine; var commentParserMock = MockRepository.GenerateMock<ICommentParser>(); commentParserMock.Expect(x => x.Parse(currentHeaderText)).Return(String.Empty); string preparedHeader = LicenseHeaderPreparer.Prepare(toBeInsertedHeaderText, currentHeaderText, commentParserMock); Assert.AreEqual (toBeInsertedHeaderText, preparedHeader); }
public void Prepare_LicenseHeaderWithoutEndingNewLine_ReturnsNewHeaderWithoutEndingNewLine() { const string currentHeaderText = "nothingRelevant"; const string toBeInsertedHeaderText = "//Testtext"; var commentParserMock = MockRepository.GenerateMock <ICommentParser>(); commentParserMock.Expect(x => x.Parse(currentHeaderText)).Return(string.Empty); var preparedHeader = LicenseHeaderPreparer.Prepare(toBeInsertedHeaderText, currentHeaderText, commentParserMock); Assert.That(toBeInsertedHeaderText, Is.EqualTo(preparedHeader)); commentParserMock.VerifyAllExpectations(); }
public void Prepare_CurrentHeaderHasCommentAndFileEndsWithNewLine_ReturnsNewHeaderWithNewLine() { var currentHeaderText = "//HighlyRelevantComment" + Environment.NewLine; const string toBeInsertedHeaderText = "//Testtext"; var commentParserMock = MockRepository.GenerateMock <ICommentParser>(); commentParserMock.Expect(x => x.Parse(currentHeaderText)).Return("OhOurCurrentHeaderTextHasAComment"); var preparedHeader = LicenseHeaderPreparer.Prepare(toBeInsertedHeaderText, currentHeaderText, commentParserMock); Assert.That(toBeInsertedHeaderText + Environment.NewLine, Is.EqualTo(preparedHeader)); commentParserMock.VerifyAllExpectations(); }
public void ReplaceHeaderIfNecessary() { // get the header copyright section of this document string existingHeader = _commentParser.Parse(GetText()); // if the filter keywords exist but none match, return -- no replacement. if (!string.IsNullOrEmpty(existingHeader) && _keywords != null && (_keywords.Any(k => existingHeader.ToLower().Contains(k.ToLower()))) == false) { return; } // if blacklist keywords exist and any of them match, return -- no replacement. if (!string.IsNullOrEmpty(existingHeader) && _blacklist != null && (_blacklist.Any(b => existingHeader.ToLower().Contains(b.ToLower())))) { return; } // check for and process skip expression var skippedText = SkipText(); if (!string.IsNullOrEmpty(skippedText)) { RemoveHeader(skippedText); AddHeader(LicenseHeaderPreparer.Prepare(skippedText, GetText(), _commentParser)); return; } // if new header is not empty and differs from original, replace it if (!_header.IsEmpty) { if (existingHeader != _header.Text) { ReplaceHeader(existingHeader, _header.Text); } } else // else remove it { RemoveHeader(existingHeader); } }
private void ReplaceHeader(string existingHeader, string newHeader) { RemoveHeader(existingHeader); AddHeader(LicenseHeaderPreparer.Prepare(newHeader, GetText(), _commentParser)); }