From e9ad8ea6b91cc255c1e1a397ce6fadb273fb8538 Mon Sep 17 00:00:00 2001 From: snixtho Date: Sat, 5 Oct 2024 11:59:51 +0200 Subject: [PATCH] Don't start manual tracking if automatic tracking is enabled. (#312) --- .../MatchTrackerEventController.cs | 10 +++++++++- .../MatchTrackerEventControllerTests.cs | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Modules/MatchTrackerModule/Controllers/MatchTrackerEventController.cs b/src/Modules/MatchTrackerModule/Controllers/MatchTrackerEventController.cs index 5ba23a519..ffa353ba7 100644 --- a/src/Modules/MatchTrackerModule/Controllers/MatchTrackerEventController.cs +++ b/src/Modules/MatchTrackerModule/Controllers/MatchTrackerEventController.cs @@ -31,7 +31,15 @@ public Task OnBeginMatchAsync(object sender, EventArgs args) } [Subscribe(FlowControlEvent.MatchStarted)] - public Task OnMatchStarted(object sender, EventArgs args) => tracker.BeginMatchAsync(); + public Task OnMatchStarted(object sender, EventArgs args) + { + if (settings.AutomaticTracking) + { + return Task.CompletedTask; + } + + return tracker.BeginMatchAsync(); + } [Subscribe(FlowControlEvent.MatchEnded)] public Task OnMatchEnded(object sender, EventArgs args) => tracker.EndMatchAsync(); diff --git a/tests/Modules/MatchTrackerModule.Tests/Controllers/MatchTrackerEventControllerTests.cs b/tests/Modules/MatchTrackerModule.Tests/Controllers/MatchTrackerEventControllerTests.cs index 0dcfaaed3..da20eaf4d 100644 --- a/tests/Modules/MatchTrackerModule.Tests/Controllers/MatchTrackerEventControllerTests.cs +++ b/tests/Modules/MatchTrackerModule.Tests/Controllers/MatchTrackerEventControllerTests.cs @@ -49,4 +49,24 @@ public async Task Begin_Match_Is_Tracked_Depending_On_Settings(bool automaticTra _tracker.Verify(m => m.BeginMatchAsync(), timesCalled); } + + [Fact] + public async Task Manual_Match_Tracking_Is_Disabled_If_Automatic_Tracking_Is_Enabled() + { + _settings.Setup(m => m.AutomaticTracking).Returns(true); + + await Controller.OnMatchStarted(null, null); + + _tracker.Verify(m => m.BeginMatchAsync(), Times.Never); + } + + [Fact] + public async Task Manual_Match_Tracking_Is_Triggered_If_Automatic_Tracking_Is_Disabled() + { + _settings.Setup(m => m.AutomaticTracking).Returns(false); + + await Controller.OnMatchStarted(null, null); + + _tracker.Verify(m => m.BeginMatchAsync(), Times.Once); + } }