using System.Reflection; using System.Text.Json; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using RadicadeServer.API.Matchmaking; using RadicadeServer.API.Moderation; using RadicadeServer.DB; using Xunit; namespace RadicadeServer.Tests; public class LoggedRouteCompatibilityTests { [Theory] [InlineData("rooms/requiring/developer")] [InlineData("rooms/requiring/rrplus")] public void RestrictedRoomsHasStartupRouteAndReturnsEmptyArray(string route) { Assert.Equal("matchmaking", typeof(MatchmakingAPI).GetCustomAttribute()!.Template); var method = typeof(MatchmakingAPI).GetMethod(nameof(MatchmakingAPI.GetRestrictedRooms))!; Assert.Contains(method.GetCustomAttributes(), attribute => attribute.Template == route); using var db = new RecDBContext(TestDbOptions.Create() .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options); var result = Assert.IsType(new MatchmakingAPI(db).GetRestrictedRooms()); var json = JsonSerializer.SerializeToElement(result.Value); Assert.Equal(JsonValueKind.Array, json.ValueKind); Assert.Equal(0, json.GetArrayLength()); } [Fact] public void SelectedCheerAcceptsLoggedClientRouteWithoutDuplicateCaseAliases() { var routes = typeof(ReputationAPI).GetMethod(nameof(ReputationAPI.SetSelectedCheer))! .GetCustomAttributes().Select(attribute => attribute.Template!).ToArray(); Assert.Contains("~/api/PlayerCheer/v1/SetSelectedCheer", routes); Assert.Equal(routes.Length, routes.Distinct(StringComparer.OrdinalIgnoreCase).Count()); } }