public void PatternEmpty() { bool expectedReturn = false; string expectedMessage = @"Error in ReplaceInFile: Pattern cannot be null or empty."; string expectedMessageCode = MessageCodes.ReplaceInFile.EmptyPattern; string file = Path.Combine(DataFolder, "ReplaceTest.txt"); string pattern = null; string substitute = null; bool useRegex = false; bool regexMultiline = false; bool regexSingleline = false; bool escapeBackslash = false; ReplaceInFile task = new ReplaceInFile() { File = file, Pattern = pattern, Substitute = substitute, UseRegex = useRegex, RegexMultilineMode = regexMultiline, RegexSinglelineMode = regexSingleline, EscapeBackslash = escapeBackslash }; Assert.AreEqual(expectedReturn, task.Execute()); MockTaskLogger logger = task.Logger as MockTaskLogger; MockLogEntry logMessage = logger.LogEntries.First(); Assert.AreEqual(expectedMessage, logMessage.Message); Assert.AreEqual(expectedMessageCode, logMessage.MessageCode); }
public void InvalidPropertiesRequiresBsipa_ThrowsException() { Directory.CreateDirectory(OutputPath); string targetPath = Path.Combine(OutputPath, nameof(InvalidProperties_ThrowsException) + ".json"); MockTaskLogger logger = new MockTaskLogger(nameof(GenerateManifest)); var task = new GenerateManifest() { RequiresBsipa = true, TargetPath = targetPath, Logger = logger, DependsOn = MockTaskItem.FromDictString("DependsOn", "BSIPA|^4.3.0"), }; Assert.IsFalse(task.Execute()); var logEntry = logger.LogEntries.First(); Console.Write(logEntry.Message); var exception = logEntry.Exception as ManifestValidationException; Assert.IsNotNull(exception); var props = exception.InvalidProperties; Assert.IsTrue(props.Any(p => p == nameof(GenerateManifest.Id))); Assert.IsTrue(props.Any(p => p == nameof(GenerateManifest.Name))); Assert.IsTrue(props.Any(p => p == nameof(GenerateManifest.Author))); Assert.IsTrue(props.Any(p => p == nameof(GenerateManifest.Version))); Assert.IsTrue(props.Any(p => p == nameof(GenerateManifest.GameVersion))); Assert.IsTrue(props.Any(p => p == nameof(GenerateManifest.Description))); }
public void NotMatching() { bool expectedResult = true; string assemblyVersion = "1.1.0"; string pluginVersion = "1.2.0"; CompareVersions task = new CompareVersions() { AssemblyVersion = assemblyVersion, PluginVersion = pluginVersion }; string[] logMessages = new string[] { $"{task.GetType().Name}: PluginVersion {pluginVersion} does not match AssemblyVersion {assemblyVersion}." }; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(logMessages.Length, mockTaskLogger.LogEntries.Count); for (int i = 0; i < logMessages.Length; i++) { Assert.AreEqual(logMessages[i], mockTaskLogger.LogEntries[i].ToString()); } Assert.AreEqual(expectedResult, taskResult); }
public void MissingAssemblyVersion() { string assemblyFilePath = Path.Combine("AssemblyInfos", "MissingAssemblyVersion.cs"); bool expectedResult = false; string expectedAssemblyVersion = MessageCodes.ErrorString; GetAssemblyInfo task = new GetAssemblyInfo { AssemblyInfoPath = assemblyFilePath }; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(2, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries[0]; Assert.AreEqual($"{task.GetType().Name}: Unable to parse the AssemblyVersion from {assemblyFilePath}", logEntry.ToString()); logEntry = mockTaskLogger.LogEntries[1]; Assert.AreEqual($"{task.GetType().Name}: AssemblyVersion could not be determined.", logEntry.ToString()); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedAssemblyVersion, task.AssemblyVersion); }
public void BadAssemblyFileVersion_FailOnError() { string assemblyFilePath = Path.Combine("AssemblyInfos", "BadAssemblyFileVersion.cs"); bool expectedResult = false; string expectedAssemblyVersion = MessageCodes.ErrorString; GetAssemblyInfo task = new GetAssemblyInfo { AssemblyInfoPath = assemblyFilePath, FailOnError = true }; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries.First(); Assert.AreEqual($"{task.GetType().Name}: Unable to parse the AssemblyFileVersion from {assemblyFilePath}", logEntry.ToString()); Assert.AreEqual(LogEntryType.Error, logEntry.EntryType); Assert.AreEqual(36, logEntry.LineNumber); Assert.AreEqual(36, logEntry.EndLineNumber); Assert.AreEqual(32, logEntry.ColumnNumber); Assert.AreEqual(32, logEntry.EndColumnNumber); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedAssemblyVersion, task.AssemblyVersion); }
public void MissingAssemblyInfo_FailOnError() { string assemblyFilePath = Path.Combine("AssemblyInfos", "MissingAssemblyInfo.cs"); bool expectedResult = false; string expectedAssemblyVersion = MessageCodes.ErrorString; GetAssemblyInfo task = new GetAssemblyInfo { AssemblyInfoPath = assemblyFilePath, FailOnError = true }; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries[0]; Assert.AreEqual($"{task.GetType().Name}: Could not find AssemblyInfo: {assemblyFilePath}", logEntry.ToString()); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedAssemblyVersion, task.AssemblyVersion); }
public void EmptyFile() { string file = ""; string pattern = null; string substitute = null; bool useRegex = false; bool regexMultiline = false; bool regexSingleline = false; bool escapeBackslash = false; ReplaceInFile task = new ReplaceInFile() { File = file, Pattern = pattern, Substitute = substitute, UseRegex = useRegex, RegexMultilineMode = regexMultiline, RegexSinglelineMode = regexSingleline, EscapeBackslash = escapeBackslash }; bool expectedReturn = false; string expectedMessage = $"{task.GetType().Name}: 'File' is null or empty."; string expectedMessageCode = MessageCodes.ReplaceInFile.EmptyFile; Assert.AreEqual(expectedReturn, task.Execute()); MockTaskLogger logger = task.Logger as MockTaskLogger; MockLogEntry logMessage = logger.LogEntries.First(); Assert.AreEqual(expectedMessage, logMessage.Message); Assert.AreEqual(expectedMessageCode, logMessage.MessageCode); }
public void BadVersion() { string manifestPath = Path.GetFullPath(Path.Combine("Manifests", "ParsingError.json")); Assert.IsTrue(File.Exists(manifestPath), $"File not found: '{manifestPath}'"); Console.WriteLine(Path.GetFullPath(manifestPath)); GetManifestInfo task = new GetManifestInfo() { ManifestPath = manifestPath }; bool expectedResult = false; string expectedPluginVersion = "1.b.0"; string expectedBasePluginVersion = "E.R.R"; string expectedGameVersion = "E.R.R"; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries.First(); Assert.AreEqual($"{task.GetType().Name}: Error reading version in manifest: 1.b.0 is not a valid SemVer version string.", logEntry.ToString()); Assert.AreEqual(8, logEntry.LineNumber); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedPluginVersion, task.PluginVersion); Assert.AreEqual(expectedBasePluginVersion, task.BasePluginVersion); Assert.AreEqual(expectedGameVersion, task.GameVersion); }
public void ManifestNotFound() { string manifestPath = Path.Combine("Manifests", "DoesNotExist.json"); bool expectedResult = false; string expectedPluginVersion = MessageCodes.ErrorString; string expectedGameVersion = MessageCodes.ErrorString; GetManifestInfo getManifestInfo = new GetManifestInfo() { ManifestPath = manifestPath }; bool taskResult = getManifestInfo.Execute(); MockTaskLogger mockTaskLogger = getManifestInfo.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries.First(); Assert.AreEqual($"Error in GetManifestInfo: Manifest file not found at {manifestPath}", logEntry.ToString()); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedPluginVersion, getManifestInfo.PluginVersion); Assert.AreEqual(expectedGameVersion, getManifestInfo.GameVersion); }
public void Matching_AsmVerLeading0() { bool expectedResult = true; string assemblyVersion = "0.1.1.0"; string pluginVersion = "1.1.0"; string[] logMessages = new string[] { }; CompareVersions task = new CompareVersions() { AssemblyVersion = assemblyVersion, PluginVersion = pluginVersion }; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(logMessages.Length, mockTaskLogger.LogEntries.Count); for (int i = 0; i < logMessages.Length; i++) { Assert.AreEqual(logMessages[i], mockTaskLogger.LogEntries[i].ToString()); } Assert.AreEqual(expectedResult, taskResult); }
public void BadVersion() { string manifestPath = Path.GetFullPath(Path.Combine("Manifests", "ParsingError.json")); Assert.IsTrue(File.Exists(manifestPath), $"File not found: '{manifestPath}'"); Console.WriteLine(Path.GetFullPath(manifestPath)); GetManifestInfo getManifestInfo = new GetManifestInfo() { ManifestPath = manifestPath }; bool expectedResult = false; string expectedPluginVersion = "E.R.R"; string expectedGameVersion = "E.R.R"; bool taskResult = getManifestInfo.Execute(); MockTaskLogger mockTaskLogger = getManifestInfo.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries.First(); Assert.AreEqual($"Error reading version in manifest: Could not parse 'b' in '1.b.0' to an integer.", logEntry.ToString()); Assert.AreEqual(8, logEntry.LineNumber); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedPluginVersion, getManifestInfo.PluginVersion); Assert.AreEqual(expectedGameVersion, getManifestInfo.GameVersion); }
public void FileDoesntExist() { bool expectedReturn = false; string expectedMessage = @"Error in ReplaceInFile: File 'C:\DoesntExist.cs' does not exist."; string expectedMessageCode = MessageCodes.ReplaceInFile.MissingSource; string file = "C:\\DoesntExist.cs"; string pattern = null; string substitute = null; bool useRegex = false; bool regexMultiline = false; bool regexSingleline = false; bool escapeBackslash = false; ReplaceInFile task = new ReplaceInFile() { File = file, Pattern = pattern, Substitute = substitute, UseRegex = useRegex, RegexMultilineMode = regexMultiline, RegexSinglelineMode = regexSingleline, EscapeBackslash = escapeBackslash }; Assert.AreEqual(expectedReturn, task.Execute()); MockTaskLogger logger = task.Logger as MockTaskLogger; MockLogEntry logMessage = logger.LogEntries.First(); Assert.AreEqual(expectedMessage, logMessage.Message.Replace(Environment.CurrentDirectory + '/', "")); Assert.AreEqual(expectedMessageCode, logMessage.MessageCode); }
public void NoGameVersionLine_ErrorOnMismatch() { string manifestPath = Path.Combine("Manifests", "NoGameVersionLine.json"); bool expectedResult = false; string expectedPluginVersion = "1.1.0"; string expectedGameVersion = MessageCodes.ErrorString; GetManifestInfo getManifestInfo = new GetManifestInfo() { ManifestPath = manifestPath, FailOnError = true }; bool taskResult = getManifestInfo.Execute(); MockTaskLogger mockTaskLogger = getManifestInfo.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries.First(); Assert.AreEqual($"GameVersion not found in {manifestPath}", logEntry.ToString()); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedPluginVersion, getManifestInfo.PluginVersion); Assert.AreEqual(expectedGameVersion, getManifestInfo.GameVersion); }
public void BadAssemblyFileVersion() { string assemblyFilePath = Path.Combine("AssemblyInfos", "BadAssemblyFileVersion.cs"); bool expectedResult = true; string expectedAssemblyVersion = "1.1.0"; GetAssemblyInfo task = new GetAssemblyInfo(); task.AssemblyInfoPath = assemblyFilePath; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries.First(); Assert.AreEqual($"Unable to parse the AssemblyFileVersion from {assemblyFilePath}", logEntry.ToString()); Assert.AreEqual(LogEntryType.Warning, logEntry.EntryType); Assert.AreEqual(36, logEntry.LineNumber); Assert.AreEqual(36, logEntry.EndLineNumber); Assert.AreEqual(32, logEntry.ColumnNumber); Assert.AreEqual(32, logEntry.EndColumnNumber); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedAssemblyVersion, task.AssemblyVersion); }
public void Matching_ExtendedSemVer() { string manifestPath = Path.Combine("Manifests", "ExtendedSemVerVersion.json"); bool expectedResult = true; string expectedPluginVersion = "1.2.3-rc4"; string expectedBasePluginVersion = "1.2.3"; string expectedGameVersion = "1.9.1"; GetManifestInfo task = new GetManifestInfo() { ManifestPath = manifestPath }; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(0, mockTaskLogger.LogEntries.Count); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedPluginVersion, task.PluginVersion); Assert.AreEqual(expectedBasePluginVersion, task.BasePluginVersion); Assert.AreEqual(expectedGameVersion, task.GameVersion); }
public void AssemblyFileMismatch_FailOnError() { string assemblyFilePath = Path.Combine("AssemblyInfos", "AssemblyFileMismatch.cs"); bool expectedResult = false; string expectedAssemblyVersion = MessageCodes.ErrorString; GetAssemblyInfo task = new GetAssemblyInfo() { FailOnError = true }; task.AssemblyInfoPath = assemblyFilePath; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); MockLogEntry logEntry = mockTaskLogger.LogEntries.First(); Assert.AreEqual($"{task.GetType().Name}: AssemblyVersion 1.1.0 does not match AssemblyFileVersion 1.2.0 in {assemblyFilePath}", logEntry.ToString()); Assert.AreEqual(LogEntryType.Error, logEntry.EntryType); Assert.AreEqual(36, logEntry.LineNumber); Assert.AreEqual(36, logEntry.EndLineNumber); Assert.AreEqual(33, logEntry.ColumnNumber); Assert.AreEqual(38, logEntry.EndColumnNumber); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedAssemblyVersion, task.AssemblyVersion); }
public void GetGitStatus_Test() { string directory = Environment.CurrentDirectory; IGitRunner gitRunner = new GitCommandRunner(directory); //string expectedUser = "******"; MockTaskLogger logger = new MockTaskLogger("GitCommandRunner"); GitInfo status = GetCommitInfo.GetGitStatus(gitRunner, logger); string logEntries = string.Join('\n', logger.LogEntries.Select(e => e.ToString())); Assert.IsFalse(string.IsNullOrEmpty(status.Branch), $"Branch should not be null/empty.\n{logEntries}"); Assert.IsFalse(string.IsNullOrEmpty(status.Modified), $"'Modified' should not be null/empty.\n{logEntries}"); Assert.IsTrue(status.Modified == "Unmodified" || status.Modified == "Modified", $"'Modified' has an unrecognized value.\n{logEntries}"); Assert.IsFalse(string.IsNullOrWhiteSpace(status.GitUser), $"GitUser should not be null/empty.\n{logEntries}"); //Assert.AreEqual(expectedUser, status.GitUser); }
public void Matching_DefaultPaths() { bool expectedResult = true; string expectedAssemblyVersion = "1.1.0"; GetAssemblyInfo task = new GetAssemblyInfo(); bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(0, mockTaskLogger.LogEntries.Count); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedAssemblyVersion, task.AssemblyVersion); }
public void Matching_KnownAssemblyVersion() { bool expectedResult = true; string expectedPluginVersion = "1.1.0"; string expectedGameVersion = "1.9.1"; GetManifestInfo getManifestInfo = new GetManifestInfo(); bool taskResult = getManifestInfo.Execute(); MockTaskLogger mockTaskLogger = getManifestInfo.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(0, mockTaskLogger.LogEntries.Count); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedPluginVersion, getManifestInfo.PluginVersion); Assert.AreEqual(expectedGameVersion, getManifestInfo.GameVersion); }
public void AssemblyFileVersionFirst() { string assemblyFilePath = Path.Combine("AssemblyInfos", "AssemblyFileVersionFirst.cs"); bool expectedResult = true; string expectedAssemblyVersion = "1.1.0"; GetAssemblyInfo task = new GetAssemblyInfo() { AssemblyInfoPath = assemblyFilePath }; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(0, mockTaskLogger.LogEntries.Count); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedAssemblyVersion, task.AssemblyVersion); }
public void NormalReplace_NullSubstitute() { string fileName = "ReplaceTest.txt"; string sourceFile = Path.Combine(DataFolder, fileName); string outDir = Path.Combine(OutputFolder, "NormalReplace_NullSubstitute"); Directory.CreateDirectory(outDir); File.Copy(sourceFile, Path.Combine(outDir, fileName), true); bool expectedReturn = true; string expectedMessage = @"Replacing '$test$' with '' in "; string expectedReplacedString = "Left Right"; string file = Path.Combine(outDir, fileName); string pattern = "$test$"; string substitute = null; bool useRegex = false; bool regexMultiline = false; bool regexSingleline = false; bool escapeBackslash = false; ReplaceInFile task = new ReplaceInFile() { File = file, Pattern = pattern, Substitute = substitute, UseRegex = useRegex, RegexMultilineMode = regexMultiline, RegexSinglelineMode = regexSingleline, EscapeBackslash = escapeBackslash }; Assert.AreEqual(expectedReturn, task.Execute()); MockTaskLogger logger = task.Logger as MockTaskLogger; MockLogEntry logMessage = logger.LogEntries.First(); Console.WriteLine(logMessage); Assert.IsTrue(logMessage.Message.StartsWith(expectedMessage)); string replacedText = File.ReadAllText(file); Assert.AreEqual(expectedReplacedString, replacedText); }
public void NoVersionLine() { string manifestPath = Path.Combine("Manifests", "NoVersionLine.json"); bool expectedResult = true; string expectedPluginVersion = MessageCodes.ErrorString; string expectedGameVersion = "1.9.1"; GetManifestInfo getManifestInfo = new GetManifestInfo() { ManifestPath = manifestPath }; bool taskResult = getManifestInfo.Execute(); MockTaskLogger mockTaskLogger = getManifestInfo.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedPluginVersion, getManifestInfo.PluginVersion); Assert.AreEqual(expectedGameVersion, getManifestInfo.GameVersion); }
public void NoVersionLine_ErrorOnMismatch() { string manifestPath = Path.Combine("Manifests", "NoVersionLine.json"); bool expectedResult = false; string expectedPluginVersion = MessageCodes.ErrorString; string expectedGameVersion = MessageCodes.ErrorString; GetManifestInfo task = new GetManifestInfo() { ManifestPath = manifestPath, FailOnError = true }; bool taskResult = task.Execute(); MockTaskLogger mockTaskLogger = task.Logger as MockTaskLogger; foreach (MockLogEntry entry in mockTaskLogger.LogEntries) { Console.WriteLine(entry); } Assert.AreEqual(1, mockTaskLogger.LogEntries.Count); Assert.AreEqual(expectedResult, taskResult); Assert.AreEqual(expectedPluginVersion, task.PluginVersion); Assert.AreEqual(expectedGameVersion, task.GameVersion); }