Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Globalization;
using Oddin.OddsFeedSdk.API.Entities;
using Oddin.OddsFeedSdk.API.Entities.Abstractions;
using Oddin.OddsFeedSdk.API.Models;
using Oddin.OddsFeedSdk.Common;
using Xunit;

namespace Oddin.OddsFeedSdk.Tests.API.Entities;

public class PlayerUnderageTests
{
[Theory]
[InlineData("1", UnderageStatus.Yes)]
[InlineData("0", UnderageStatus.No)]
[InlineData("-1", UnderageStatus.Unknown)]
[InlineData(null, UnderageStatus.Unknown)]
[InlineData("", UnderageStatus.Unknown)]
[InlineData("true", UnderageStatus.Unknown)]
public void WireEncodingMapsOntoTheEnum(string wire, UnderageStatus expected)
=> Assert.Equal(expected, UnderageStatusParser.Parse(wire));

[Fact]
public void LocalizedPlayerDefaultsToUnknown()
=> Assert.Equal(UnderageStatus.Unknown, new LocalizedPlayer(new URN("od:player:1")).Underage);

[Fact]
public void PlayerModelDeserializesUnderage()
{
const string xml = "<player_profile><player id=\"od:player:1\" name=\"P\" sport=\"od:sport:1\" underage=\"1\"/></player_profile>";
Assert.True(XmlHelper.TryDeserialize<player_profile>(xml, out var profile));
Assert.Equal("1", profile.player.underage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface IPlayer

IReadOnlyDictionary<CultureInfo, string> SportIDs { get; }

UnderageStatus Underage { get; }

string GetName(CultureInfo culture);

string GetFullName(CultureInfo culture);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Oddin.OddsFeedSdk.API.Entities.Abstractions;

/// <summary>
/// Whether a competitor or player is flagged as underage. The feed encodes it
/// as -1 (unknown), 0 (no) and 1 (yes); anything else reads as <see cref="Unknown"/>.
/// </summary>
public enum UnderageStatus
{
Unknown = -1,
No = 0,
Yes = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal class LocalizedPlayer : ILocalizedItem

internal IDictionary<CultureInfo, string> SportID { get; set; } = new Dictionary<CultureInfo, string>();

internal UnderageStatus Underage { get; set; } = UnderageStatus.Unknown;

public IEnumerable<CultureInfo> LoadedLocals => GetLoadedLocals();

private IEnumerable<CultureInfo> GetLoadedLocals()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public IReadOnlyDictionary<CultureInfo, string> SportIDs
}
}

public UnderageStatus Underage => FetchPlayer(_cultures)?.Underage ?? UnderageStatus.Unknown;

public string GetName(CultureInfo culture) =>
FetchPlayer(new[] { culture })
?.Name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Oddin.OddsFeedSdk.API.Entities.Abstractions;

namespace Oddin.OddsFeedSdk.API.Entities;

internal static class UnderageStatusParser
{
internal static UnderageStatus Parse(string value) =>
value switch
{
"0" => UnderageStatus.No,
"1" => UnderageStatus.Yes,
_ => UnderageStatus.Unknown
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public string full_name
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("sport")]
public string sportID { get; set; }

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("underage")]
public string underage { get; set; }
}

/// <remarks/>
Expand Down
2 changes: 2 additions & 0 deletions src/Oddin.OddsFeedSdk/Oddin.OddsFeedSdk/API/PlayerCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ private void RefreshOrInsertItem(URN id, CultureInfo culture, player_profilePlay
item.Name[culture] = data.name;
item.FullName[culture] = data.full_name;
item.SportID[culture] = data.sportID;
item.Underage = UnderageStatusParser.Parse(data.underage);
}
else
{
item = new LocalizedPlayer(id);
item.Name[culture] = data.name;
item.FullName[culture] = data.full_name;
item.SportID[culture] = data.sportID;
item.Underage = UnderageStatusParser.Parse(data.underage);
}

_cache.Set(id.ToString(), item, _cacheTtl.AsCachePolicy());
Expand Down
Loading