public void TestCrimeConfig() { // Save original data CrimeMonitorConfiguration data = CrimeMonitorConfiguration.FromFile(); CrimeMonitorConfiguration config = CrimeMonitorConfiguration.FromJsonString(crimeConfigJson); Assert.AreEqual(3, config.criminalrecord.Count); Assert.AreEqual(275915, config.claims); Assert.AreEqual(400, config.fines); record = config.criminalrecord.ToList().FirstOrDefault(r => r.faction == "Calennero State Industries"); Assert.AreEqual(Superpower.Empire, record.Allegiance); Assert.AreEqual("Empire", record.allegiance); Assert.AreEqual(105168, record.bountiesAmount); Assert.AreEqual(400, record.finesIncurred.Sum(r => r.amount)); // Verify faction report object Assert.AreEqual(2, record.factionReports.Count); report = record.factionReports[0]; Assert.IsTrue(report.bounty); Assert.AreEqual(Crime.None, report.crimeDef); Assert.AreEqual("HIP 20277", report.system); Assert.AreEqual(105168, report.amount); report = record.factionReports[1]; Assert.IsFalse(report.bounty); Assert.AreEqual(Crime.FromEDName("dockingMinorTresspass"), report.crimeDef); Assert.AreEqual("Fabian City", report.station); // Restore original data data.ToFile(); }
public void TestMissionEventsScenario() { // Save original data MissionMonitorConfiguration missionData = MissionMonitorConfiguration.FromFile(); missionMonitor.initializeMissionMonitor(new MissionMonitorConfiguration()); //MissionsEvent line = @"{""timestamp"":""2018-08-25T23:27:21Z"", ""event"":""Missions"", ""Active"":[ { ""MissionID"":413563499, ""Name"":""Mission_Courier_Elections_name"", ""PassengerMission"":false, ""Expires"":48916 }, { ""MissionID"":413563678, ""Name"":""Mission_Delivery_name"", ""PassengerMission"":false, ""Expires"":48917 }, { ""MissionID"":413563829, ""Name"":""Mission_Salvage_Planet_name"", ""PassengerMission"":false, ""Expires"":264552 } ], ""Failed"":[ ], ""Complete"":[ ] }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionsEvent((MissionsEvent)events[0]); Assert.AreEqual(3, missionMonitor.missions.Count); Assert.AreEqual(3, missionMonitor.missions.Where(m => m.statusEDName == "Active").Count()); //CargoDepotEvent - 'Shared' line = @"{ ""timestamp"":""2018-08-26T02:55:10Z"", ""event"":""CargoDepot"", ""MissionID"":413748365, ""UpdateType"":""WingUpdate"", ""CargoType"":""Gold"", ""Count"":20, ""StartMarketID"":0, ""EndMarketID"":3224777216, ""ItemsCollected"":0, ""ItemsDelivered"":20, ""TotalItemsToDeliver"":54, ""Progress"":0.000000 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleCargoDepotEvent((CargoDepotEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 413748365); Assert.AreEqual(4, missionMonitor.missions.Count); Assert.AreEqual("CollectWing", mission.typeEDName); Assert.AreEqual("Active", mission.statusEDName); Assert.IsTrue(mission.originreturn); Assert.IsTrue(mission.wing); Assert.IsTrue(mission.shared); line = @"{ ""timestamp"":""2018-08-26T02:56:16Z"", ""event"":""CargoDepot"", ""MissionID"":413748365, ""UpdateType"":""Deliver"", ""CargoType"":""Gold"", ""Count"":34, ""StartMarketID"":0, ""EndMarketID"":3224777216, ""ItemsCollected"":0, ""ItemsDelivered"":54, ""TotalItemsToDeliver"":54, ""Progress"":0.000000 }"; events = JournalMonitor.ParseJournalEntry(line); missionMonitor._handleCargoDepotEvent((CargoDepotEvent)events[0]); Assert.AreEqual(3, missionMonitor.missions.Count); //MissionAbandonedEvent line = @"{ ""timestamp"":""2018-08-26T00:50:48Z"", ""event"":""MissionAbandoned"", ""Name"":""Mission_Courier_Elections_name"", ""Fine"":50000, ""MissionID"":413563499 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor.handleMissionAbandonedEvent((MissionAbandonedEvent)events[0]); Assert.AreEqual("Failed", missionMonitor.missions.SingleOrDefault(m => m.missionid == 413563499)?.statusEDName); missionMonitor._postHandleMissionAbandonedEvent((MissionAbandonedEvent)events[0]); Assert.AreEqual(2, missionMonitor.missions.Count); //MissionAcceptedEvent - 'AltruismCredits' line = "{ \"timestamp\":\"2018-09-17T02:54:16Z\", \"event\":\"MissionAccepted\", \"Faction\":\"Merope Expeditionary Fleet\", \"Name\":\"Mission_AltruismCredits\", \"LocalisedName\":\"Donate 450,000 Cr to the cause\", \"Donation\":\"450000\", \"Expiry\":\"2018-09-17T05:01:28Z\", \"Wing\":false, \"Influence\":\"Med\", \"Reputation\":\"Med\", \"MissionID\":419646649 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 419646649); Assert.AreEqual(3, missionMonitor.missions.Count); Assert.IsTrue(mission.originreturn); //MissionAcceptedEvent - 'Collect' line = @"{ ""timestamp"":""2018-08-26T00:50:48Z"", ""event"":""MissionAccepted"", ""Faction"":""Calennero State Industries"", ""Name"":""Mission_Collect_Industrial"", ""LocalisedName"":""Industry needs 54 units of Tantalum"", ""Commodity"":""$Tantalum_Name;"", ""Commodity_Localised"":""Tantalum"", ""Count"":54, ""DestinationSystem"":""HIP 20277"", ""DestinationStation"":""Fabian City"", ""Expiry"":""2018-08-27T00:48:38Z"", ""Wing"":false, ""Influence"":""Med"", ""Reputation"":""Med"", ""Reward"":1909532, ""MissionID"":413748324 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 413748324); Assert.AreEqual(4, missionMonitor.missions.Count); Assert.AreEqual("Collect", mission.typeEDName); Assert.AreEqual("Active", mission.statusEDName); Assert.IsTrue(mission.originreturn); Assert.IsTrue(mission.legal); Assert.IsFalse(mission.wing); // Verify duplication protection events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); Assert.AreEqual(1, missionMonitor.missions.ToList().Where(m => m.missionid == 413748324).Count()); Assert.AreEqual(4, missionMonitor.missions.Count); //CargoDepotEvent - 'Collect' line = @"{ ""timestamp"":""2018-08-26T02:55:10Z"", ""event"":""CargoDepot"", ""MissionID"":413748324, ""UpdateType"":""Deliver"", ""CargoType"":""Tantalum"", ""Count"":54, ""StartMarketID"":0, ""EndMarketID"":3224777216, ""ItemsCollected"":0, ""ItemsDelivered"":54, ""TotalItemsToDeliver"":54, ""Progress"":0.000000 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleCargoDepotEvent((CargoDepotEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 413748324); Assert.AreEqual("Complete", mission.statusEDName); //MissionAcceptedEvent - 'Permit' line = "{ \"timestamp\":\"2018-09-19T01:12:57Z\", \"event\":\"MissionAccepted\", \"Faction\":\"Sublime Order of van Maanen's Star\", \"Name\":\"MISSION_genericPermit1\", \"LocalisedName\":\"Permit Acquisition Opportunity\", \"Wing\":false, \"Influence\":\"None\", \"Reputation\":\"None\", \"MissionID\":420098082 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 420098082); Assert.AreEqual(5, missionMonitor.missions.Count); //MissionAcceptedEvent - 'Smuggle' line = @"{ ""timestamp"":""2018-08-29T20:51:56Z"", ""event"":""MissionAccepted"", ""Faction"":""Gcirithang Crimson Mafia"", ""Name"":""Mission_Smuggle_Famine"", ""LocalisedName"":""Smuggle 36 units of Narcotics to combat famine"", ""Commodity"":""$BasicNarcotics_Name;"", ""Commodity_Localised"":""Narcotics"", ""Count"":36, ""DestinationSystem"":""Carcinus"", ""DestinationStation"":""Wye-Delta Station"", ""Expiry"":""2018-08-30T20:55:33Z"", ""Wing"":false, ""Influence"":""Med"", ""Reputation"":""Med"", ""Reward"":180818, ""MissionID"":414732731 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 414732731); Assert.AreEqual(6, missionMonitor.missions.Count); Assert.AreEqual("Smuggle", mission.typeEDName); Assert.IsFalse(mission.originreturn); Assert.IsFalse(mission.legal); //MissionCompletedEvent line = @"{ ""timestamp"":""2018-08-26T00:40:14Z"", ""event"":""MissionCompleted"", ""Faction"":""HIP 20277 Inc"", ""Name"":""Mission_Salvage_Planet_name"", ""MissionID"":413563829, ""Commodity"":""$Landmines_Name;"", ""Commodity_Localised"":""Landmines"", ""Count"":4, ""DestinationSystem"":""Carthage"", ""Reward"":465824, ""FactionEffects"":[ { ""Faction"":""HIP 20277 Inc"", ""Effects"":[ { ""Effect"":""$MISSIONUTIL_Interaction_Summary_civilUnrest_down;"", ""Effect_Localised"":""$#MinorFaction; are happy to report improved civil contentment, making a period of civil unrest unlikely."", ""Trend"":""DownGood"" } ], ""Influence"":[ { ""SystemAddress"":84053791442, ""Trend"":""UpGood"" } ], ""Reputation"":""UpGood"" } ] }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor.handleMissionCompletedEvent((MissionCompletedEvent)events[0]); Assert.AreEqual("Complete", missionMonitor.missions.SingleOrDefault(m => m.missionid == 413563829)?.statusEDName); missionMonitor._postHandleMissionCompletedEvent((MissionCompletedEvent)events[0]); Assert.AreEqual(5, missionMonitor.missions.Count); //MissionFailedEvent line = @"{ ""timestamp"":""2018-08-26T00:50:48Z"", ""event"":""MissionFailed"", ""Name"":""Mission_Collect_Industrial"", ""Fine"":50000, ""MissionID"":413748324 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); CrimeMonitorConfiguration crimeData = CrimeMonitorConfiguration.FromFile(); CrimeMonitor crimeMonitor = new CrimeMonitor(); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 413748324); long fine = ((MissionFailedEvent)events[0]).fine; crimeMonitor._handleMissionFine(events[0].timestamp, mission, fine); FactionRecord record = crimeMonitor.criminalrecord.ToList().FirstOrDefault(r => r.faction == mission.faction); Assert.IsNotNull(record); Assert.AreEqual(50000, record.fines); FactionReport report = record.factionReports.FirstOrDefault(r => r.crimeDef == Crime.FromEDName("missionFine")); Assert.IsNotNull(report); Assert.AreEqual(50000, report.amount); crimeData.ToFile(); missionMonitor.handleMissionFailedEvent((MissionFailedEvent)events[0]); Assert.AreEqual("Failed", missionMonitor.missions.SingleOrDefault(m => m.missionid == 413748324)?.statusEDName); missionMonitor._postHandleMissionFailedEvent((MissionFailedEvent)events[0]); Assert.AreEqual(4, missionMonitor.missions.Count); //MissionCompletedEvent - Donation line = @"{ ""timestamp"":""2018-12-18T19:14:32Z"", ""event"":""MissionCompleted"", ""Faction"":""Movement for Rabakshany Democrats"", ""Name"":""Mission_AltruismCredits_name"", ""MissionID"":442085549, ""Donation"":""1000000"", ""Donated"":1000000, ""FactionEffects"":[ { ""Faction"":""Movement for Rabakshany Democrats"", ""Effects"":[ { ""Effect"":""$MISSIONUTIL_Interaction_Summary_EP_up;"", ""Effect_Localised"":""The economic status of $#MinorFaction; has improved in the $#System; system."", ""Trend"":""UpGood"" } ], ""Influence"":[ { ""SystemAddress"":8605201797850, ""Trend"":""UpGood"", ""Influence"":""+++++"" } ], ""ReputationTrend"":""UpGood"", ""Reputation"":""++"" } ] }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); MissionCompletedEvent mcEvent = (MissionCompletedEvent)events[0]; Assert.AreEqual(1000000, mcEvent.donation); // Restore original data missionData.ToFile(); }
public void TestCrimeEventsScenario() { // Save original data CrimeMonitorConfiguration data = CrimeMonitorConfiguration.FromFile(); var privateObject = new PrivateObject(crimeMonitor); CrimeMonitorConfiguration config = CrimeMonitorConfiguration.FromJsonString(crimeConfigJson); crimeMonitor.readRecord(config); // Bond Awarded Event line = "{ \"timestamp\":\"2019-04-22T11:51:30Z\", \"event\":\"FactionKillBond\", \"Reward\":32473, \"AwardingFaction\":\"Constitution Party of Aerial\", \"VictimFaction\":\"Ankou Blue Federal Holdings\" }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); privateObject.Invoke("_handleBondAwardedEvent", new object[] { events[0] }); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Constitution Party of Aerial"); Assert.AreEqual(3, record.factionReports.Count); Assert.AreEqual(94492, record.bondsAmount); // Bounty Awarded Event line = "{ \"timestamp\":\"2019-04-22T03:13:36Z\", \"event\":\"Bounty\", \"Rewards\":[ { \"Faction\":\"Calennero State Industries\", \"Reward\":22265 } ], \"Target\":\"adder\", \"TotalReward\":22265, \"VictimFaction\":\"Natural Amemakarna Movement\" }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); privateObject.Invoke("_handleBountyAwardedEvent", new object[] { events[0], true }); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries"); record.factionReports.FirstOrDefault(r => r.amount == 22265).shipId = 10; Assert.AreEqual(2, record.factionReports.Where(r => r.bounty && r.crimeDef == Crime.None).Count()); Assert.AreEqual(127433, record.bountiesAmount); // Fine Incurred Event line = "{ \"timestamp\":\"2019-04-22T03:21:46Z\", \"event\":\"CommitCrime\", \"CrimeType\":\"dockingMinorTresspass\", \"Faction\":\"Constitution Party of Aerial\", \"Fine\":400 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); privateObject.Invoke("_handleFineIncurredEvent", new object[] { events[0] }); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Constitution Party of Aerial"); record.factionReports.FirstOrDefault(r => !r.bounty && r.crimeDef != Crime.None).shipId = 10; Assert.AreEqual(1, record.factionReports.Where(r => !r.bounty && r.crimeDef != Crime.None).Count()); Assert.AreEqual(400, record.finesIncurred.Sum(r => r.amount)); // Bounty Incurred Event line = "{ \"timestamp\":\"2019-04-13T03:58:29Z\", \"event\":\"CommitCrime\", \"CrimeType\":\"assault\", \"Faction\":\"Calennero State Industries\", \"Victim\":\"Christofer\", \"Bounty\":400 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); privateObject.Invoke("_handleBountyIncurredEvent", new object[] { events[0] }); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries"); record.factionReports.FirstOrDefault(r => r.bounty && r.crimeDef != Crime.None).shipId = 10; Assert.AreEqual(1, record.factionReports.Where(r => r.bounty && r.crimeDef != Crime.None).Count()); Assert.AreEqual(400, record.bountiesIncurred.Sum(r => r.amount)); // Redeem Bond Event line = "{ \"timestamp\":\"2019-04-09T10:31:31Z\", \"event\":\"RedeemVoucher\", \"Type\":\"CombatBond\", \"Amount\":94492, \"Factions\":[ { \"Faction\":\"Constitution Party of Aerial\", \"Amount\":94492 } ] }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); privateObject.Invoke("_handleBondRedeemedEvent", new object[] { events[0] }); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Constitution Party of Aerial"); Assert.AreEqual(0, record.factionReports.Where(r => !r.bounty && r.crimeDef == Crime.None).Count()); // Redeem Bounty Event - Multiple line = "{ \"timestamp\":\"2019-04-09T10:31:31Z\", \"event\":\"RedeemVoucher\", \"Type\":\"bounty\", \"Amount\":213896, \"Factions\":[ { \"Faction\":\"Calennero State Industries\", \"Amount\":105168 }, { \"Faction\":\"HIP 20277 Inc\", \"Amount\":108728 } ] }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); privateObject.Invoke("_handleBountyRedeemedEvent", new object[] { events[0] }); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries"); Assert.IsNotNull(record); Assert.AreEqual(0, record.factionReports.Where(r => r.bounty && r.crimeDef == Crime.None).Count()); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "HIP 20277 Inc"); Assert.IsNull(record); // Fine Paid Event line = "{ \"timestamp\":\"2019-04-09T15:12:10Z\", \"event\":\"PayFines\", \"Amount\":800, \"AllFines\":true, \"ShipID\":10 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); privateObject.Invoke("_handleFinePaidEvent", new object[] { events[0] }); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries"); Assert.AreEqual(0, record.factionReports.Where(r => !r.bounty && r.crimeDef != Crime.None).Count()); Assert.AreEqual(0, record.finesIncurred.Sum(r => r.amount)); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Constitution Party of Aerial"); Assert.IsNull(record); // Bounty Paid Event line = "{ \"timestamp\":\"2019-04-14T04:43:05Z\", \"event\":\"PayBounties\", \"Amount\":400, \"Faction\":\"$faction_Empire;\", \"Faction_Localised\":\"Empire\", \"ShipID\":10, \"BrokerPercentage\":25.000000 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); privateObject.Invoke("_handleBountyPaidEvent", new object[] { events[0] }); record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries"); Assert.IsNull(record); // Restore original data data.ToFile(); }