using EDPlayerJournal; using EDPlayerJournal.BGS; using EDPlayerJournal.Entries; namespace EDPlayerJournalTests; [TestClass] public class TestTransactionParser { private List? LoadTestData(string filename) { string path = Path.GetFullPath("./" + filename); string[] lines = File.ReadAllLines(path); List entries = new(); foreach (string line in lines) { line.Trim(); if (string.IsNullOrEmpty(line)) { continue; } Entry? entry = Entry.Parse(line); if (entry != null) { entries.Add(entry); } } return entries; } [TestMethod] public void DoubleFiveINF() { TransactionParser parser = new(); List? entries = LoadTestData("double-five-inf.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { return; } List? transactions = parser.Parse(entries); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 10); } [TestMethod] public void DoubleSupport() { TransactionParser parser = new(); List? entries = LoadTestData("double-support.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { return; } List? transactions = parser.Parse(entries); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 16); } [TestMethod] public void MissionFailed() { TransactionParser parser = new(); List? entries = LoadTestData("mission-failed.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { return; } List? transactions = parser.Parse(entries); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 18); } [TestMethod] public void MissionNoINF() { TransactionParser parser = new(); List? entries = LoadTestData("mission-noinfforsourceortarget.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { return; } List? transactions = parser.Parse(entries); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 10); } [TestMethod] public void Murder() { TransactionParser parser = new(); List? entries = LoadTestData("murder.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { return; } List? transactions = parser.Parse(entries); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 1); if (transactions == null) { return; } FoulMurder? murder = transactions[0] as FoulMurder; Assert.IsNotNull(murder, "result is not a murder"); Assert.AreEqual(murder.Faction, "Dei Muata Society"); } [TestMethod] public void NoFactionNameNoInfluence() { TransactionParser parser = new(); List? entries = LoadTestData("nofactionname-andnoinfluence.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { return; } List? transactions = parser.Parse(entries); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 1); } [TestMethod] public void SellOrganicData() { TransactionParser parser = new(); List? entries = LoadTestData("SellOrganicData.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { return; } List? transactions = parser.Parse(entries); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 1); Assert.IsInstanceOfType(transactions[0], typeof(OrganicData), "result is not of type Organic Data"); } }