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 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 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 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 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 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 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 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 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 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); }