public void LicenseHeaderPathInput_ValidInput_ReturnsCorrectProperties() { var headers = new Dictionary <string, string[]>(); var additionalProperties = new List <AdditionalProperty> { new AdditionalProperty("%Prop%", "Value") }; const string extension = ".cs"; var documentPath = CreateTestFile(); var licenseHeaderContentInput = new LicenseHeaderPathInput(documentPath, headers, additionalProperties); var actualHeaders = licenseHeaderContentInput.Headers; var actualAdditionalProperties = licenseHeaderContentInput.AdditionalProperties; var actualIgnoreNonCommentText = licenseHeaderContentInput.IgnoreNonCommentText; var actualDocumentPath = licenseHeaderContentInput.DocumentPath; var actualExtension = licenseHeaderContentInput.Extension; var actualInputMode = licenseHeaderContentInput.InputMode; Assert.That(actualHeaders, Is.EqualTo(headers)); Assert.That(actualAdditionalProperties, Is.EqualTo(additionalProperties)); Assert.That(actualIgnoreNonCommentText, Is.False); Assert.That(actualDocumentPath, Is.EqualTo(documentPath)); Assert.That(actualExtension, Is.EqualTo(extension)); Assert.That(actualInputMode, Is.EqualTo(LicenseHeaderInputMode.FilePath)); }
/// <summary> /// Updates the headers of one file. /// </summary> /// <param name="mode">Specifies whether the license headers should be added or removed to/from the files.</param> /// <param name="definitionFilePath">Specifies the path to the license header definition file.</param> /// <param name="filePath">Specifies the path to the file that should be updated.</param> private static void UpdateLicenseHeaderForOneFile(UpdateMode mode, string definitionFilePath, string filePath) { System.Console.WriteLine($"Updating license headers for one file: \"{filePath}\"."); System.Console.WriteLine($"Using license header definition file: \"{definitionFilePath}\"."); var headers = mode == UpdateMode.Add ? s_headerExtractor.ExtractHeaderDefinitions(definitionFilePath) : null; var replacerInput = new LicenseHeaderPathInput(filePath, headers); var replacerResult = s_replacer.RemoveOrReplaceHeader(replacerInput).Result; if (!replacerResult.IsSuccess) { WriteLineColor($"\nAn error of type '{replacerResult.Error.Type}' occurred: '{replacerResult.Error.Description}'", c_colorError); Exit(false); } WriteLineColor($"\n{(mode == UpdateMode.Add ? "Adding/Replacing" : "Removing")} succeeded.", c_colorSuccess); Exit(true); }