From 0c4d3be91250c3e317554cd6523252dc7cc10d52 Mon Sep 17 00:00:00 2001 From: benbierens Date: Fri, 21 Jun 2024 09:33:52 +0200 Subject: [PATCH] Fixes crash in marketBuffer --- Tests/CodexTests/UtilityTests/DiscordBotTests.cs | 14 ++++++++++---- Tools/TestNetRewarder/MarketBuffer.cs | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Tests/CodexTests/UtilityTests/DiscordBotTests.cs b/Tests/CodexTests/UtilityTests/DiscordBotTests.cs index f78a46c..bcaacbe 100644 --- a/Tests/CodexTests/UtilityTests/DiscordBotTests.cs +++ b/Tests/CodexTests/UtilityTests/DiscordBotTests.cs @@ -50,10 +50,10 @@ namespace CodexTests.UtilityTests apiCalls.Stop(); - Assert.That(receivedEvents.Count(e => e.Contains("Created as New.")), Is.EqualTo(1)); - Assert.That(receivedEvents.Count(e => e.Contains("SlotFilled")), Is.EqualTo(GetNumberOfRequiredHosts())); - Assert.That(receivedEvents.Count(e => e.Contains("Transit: New -> Started")), Is.EqualTo(1)); - Assert.That(receivedEvents.Count(e => e.Contains("Transit: Started -> Finished")), Is.EqualTo(1)); + AssertEventOccurance("Created as New.", 1); + AssertEventOccurance("SlotFilled", Convert.ToInt32(GetNumberOfRequiredHosts())); + AssertEventOccurance("Transit: New -> Started", 1); + AssertEventOccurance("Transit: Started -> Finished", 1); foreach (var r in repo.Rewards) { @@ -71,6 +71,12 @@ namespace CodexTests.UtilityTests return $"({rewardId})'{reward.Message}'"; } + private void AssertEventOccurance(string msg, int expectedCount) + { + Assert.That(receivedEvents.Count(e => e.Contains(msg)), Is.EqualTo(expectedCount), + $"Event '{msg}' did not occure correct number of times."); + } + private void OnCommand(string timestamp, GiveRewardsCommand call) { Log($""); diff --git a/Tools/TestNetRewarder/MarketBuffer.cs b/Tools/TestNetRewarder/MarketBuffer.cs index 4557378..b03ad7a 100644 --- a/Tools/TestNetRewarder/MarketBuffer.cs +++ b/Tools/TestNetRewarder/MarketBuffer.cs @@ -44,7 +44,11 @@ namespace TestNetRewarder private float Average(Func getValue) { - return Average(s => Convert.ToInt32(getValue(s))); + return Average(s => + { + var value = getValue(s); + return (int)value; + }); } private float Average(Func getValue)