public void MissingAssemblyInfo()
        {
            string assemblyFilePath        = Path.Combine("AssemblyInfos", "MissingAssemblyInfo.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($"Could not find AssemblyInfo: {assemblyFilePath}", logEntry.ToString());
            logEntry = mockTaskLogger.LogEntries[1];
            Assert.AreEqual("AssemblyVersion could not be determined.", logEntry.ToString());
            Assert.AreEqual(expectedResult, taskResult);
            Assert.AreEqual(expectedAssemblyVersion, task.AssemblyVersion);
        }
        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_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 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 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 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 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);
        }
예제 #8
0
        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);
        }