diff --git a/OddsCollector.Functions.Tests/Tests/OddsApi/Configuration/OddsApiOptions.cs b/OddsCollector.Functions.Tests/Tests/OddsApi/Configuration/OddsApiOptions.cs index 387ed0d..7154dcf 100644 --- a/OddsCollector.Functions.Tests/Tests/OddsApi/Configuration/OddsApiOptions.cs +++ b/OddsCollector.Functions.Tests/Tests/OddsApi/Configuration/OddsApiOptions.cs @@ -4,92 +4,104 @@ namespace OddsCollector.Functions.Tests.Tests.OddsApi.Configuration; internal class OddsApiOptions { - private static readonly IEnumerable<(string LeagueString, HashSet ExpectedLeagues)> - TestCases = new List<(string LeagueString, HashSet ExpectedLeagues)> - { - ("league", ["league"]), - ("league1;league2", ["league1", "league2"]), - ("league1;;league2", ["league1", "league2"]), - ("league1;league1", ["league1"]) - }; - - [TestCaseSource(nameof(TestCases))] - public void SetLeagues_WithValidLeagueInputString_ReturnsCorrectLeagues( - (string LeagueString, HashSet ExpectedLeagues) testCase) + [Test] + public void SetLeagues_WithOneLeague_ReturnsCorrectLeagues() + { + var options = new OddsApiClientOptions(); + + options.AddLeagues("league"); + + options.Leagues.Should().NotBeNull().And.BeEquivalentTo(["league"]); + } + + [Test] + public void SetLeagues_WithMultipleLeagues_ReturnsCorrectLeagues() + { + var options = new OddsApiClientOptions(); + + options.AddLeagues("league1;league2"); + + options.Leagues.Should().NotBeNull().And.BeEquivalentTo(["league1", "league2"]); + } + + [Test] + public void SetLeagues_WithDuplicateLeagues_ReturnsOneLeague() + { + var options = new OddsApiClientOptions(); + + options.AddLeagues("league1;league1"); + + options.Leagues.Should().NotBeNull().And.BeEquivalentTo(["league1"]); + } + + [Test] + public void SetLeagues_WithEmptyLeague_ReturnsCorrectLeagues() + { + var options = new OddsApiClientOptions(); + + options.AddLeagues("league1;;league2"); + + options.Leagues.Should().NotBeNull().And.BeEquivalentTo(["league1", "league2"]); + } + + [Test] + public void SetLeagues_WithLeadingAndTrailingCharacters_ReturnsCorrectLeagues() { - // Arrange var options = new OddsApiClientOptions(); - // Act - options.AddLeagues(testCase.LeagueString); + options.AddLeagues("league1\n; league2\r"); - // Assert - options.Leagues.Should().NotBeNull().And.BeEquivalentTo(testCase.ExpectedLeagues); + options.Leagues.Should().NotBeNull().And.BeEquivalentTo(["league1", "league2"]); } [Test] public void SetLeagues_WithNullOrEmptyLeagues_ThrowsException() { - // Arrange var options = new OddsApiClientOptions(); - // Act var action = () => options.AddLeagues(string.Empty); - // Assert - action.Should().ThrowExactly().WithParameterName("leaguesString"); + action.Should().ThrowExactly().WithParameterName("leagues"); } [Test] public void SetLeagues_WithNullLeagues_ThrowsException() { - // Arrange var options = new OddsApiClientOptions(); - // Act var action = () => options.AddLeagues(null); - // Assert - action.Should().ThrowExactly().WithParameterName("leaguesString"); + action.Should().ThrowExactly().WithParameterName("leagues"); } [Test] public void SetApiKey_WithValidKey_ReturnsThisKey() { - // Arrange const string key = nameof(key); var options = new OddsApiClientOptions(); - // Act options.SetApiKey(key); - // Assert options.ApiKey.Should().NotBeNull().And.Be(key); } [Test] public void SetApiKey_WithNullApiKey_ThrowsException() { - // Arrange var options = new OddsApiClientOptions(); - // Act var action = () => options.SetApiKey(null); - // Assert action.Should().ThrowExactly().WithParameterName("apiKey"); } [Test] public void SetApiKey_WithEmptyApiKey_ThrowsException() { - // Arrange var options = new OddsApiClientOptions(); - // Act var action = () => options.SetApiKey(string.Empty); - // Assert action.Should().ThrowExactly().WithParameterName("apiKey"); } } diff --git a/OddsCollector.Functions/OddsApi/Configuration/OddsApiClientOptions.cs b/OddsCollector.Functions/OddsApi/Configuration/OddsApiClientOptions.cs index e9c07f8..b4fb29f 100644 --- a/OddsCollector.Functions/OddsApi/Configuration/OddsApiClientOptions.cs +++ b/OddsCollector.Functions/OddsApi/Configuration/OddsApiClientOptions.cs @@ -6,17 +6,14 @@ internal class OddsApiClientOptions public string ApiKey { get; set; } = string.Empty; - public void AddLeagues(string? leaguesString) + public void AddLeagues(string? leagues) { - ArgumentException.ThrowIfNullOrEmpty(leaguesString); + ArgumentException.ThrowIfNullOrEmpty(leagues); - foreach (var league in leaguesString.Split(";")) - { - if (!string.IsNullOrEmpty(league)) - { - Leagues.Add(league); - } - } + var deserialized = + leagues.Split(";", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + Leagues.UnionWith(deserialized); } public void SetApiKey(string? apiKey)