Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 9 additions & 6 deletions CentCom.Server/Services/TgBanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ public class TgBanService : RestBanService
{
private static readonly BanSource BanSource = new BanSource { Name = "tgstation" };

public static readonly JsonSerializerOptions JsonOptions = new()
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter() },
NumberHandling = JsonNumberHandling.AllowReadingFromString
};

public TgBanService(ILogger<TgBanService> logger) : base(logger)
{
// Re-initialize to control JSON serialization behaviour
InitializeClient(o =>o.UseSystemTextJson(new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter() }
}));
InitializeClient(o => o.UseSystemTextJson(JsonOptions));
}

protected override string BaseUrl => "https://statbus.space/";
Expand All @@ -50,7 +53,7 @@ public async Task<IEnumerable<Ban>> GetBansBatchedAsync()
var bans = await GetBansAsync(page);
if (bans.Count == 0)
break;

allBans.AddRange(bans);
page++;
}
Expand Down
1 change: 1 addition & 0 deletions CentCom.Test/BanServices/TgBanSample.json

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions CentCom.Test/BanServices/TgBanServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using CentCom.Server.External;
using CentCom.Server.External.Raw;
using CentCom.Server.Services;
using Xunit;

namespace CentCom.Test.BanServices;

public class TgBanServiceTests
{
[Fact]
public async Task TgBans_ShouldParseData()
{
var testData = await File.ReadAllTextAsync("BanServices/TgBanSample.json");
var result = JsonSerializer.Deserialize<TgApiResponse>(testData, TgBanService.JsonOptions);
var banData = result.Data.Select(x => x.AsBan(null));
Assert.NotNull(result);
Assert.NotEmpty(banData);
}
}
6 changes: 6 additions & 0 deletions CentCom.Test/CentCom.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@
<ProjectReference Include="..\CentCom.Server\CentCom.Server.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="BanServices\TgBanSample.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading