From e656d9fe6d0460be428950c8fa2eba586dd677d3 Mon Sep 17 00:00:00 2001 From: Samuel Cattini-Schultz Date: Sat, 18 May 2024 19:38:43 +1000 Subject: [PATCH] Fix TestBeatmapProvider not ensuring beatmap --- Difficalcy/Services/TestBeatmapProvider.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Difficalcy/Services/TestBeatmapProvider.cs b/Difficalcy/Services/TestBeatmapProvider.cs index ff2d375..8491efe 100644 --- a/Difficalcy/Services/TestBeatmapProvider.cs +++ b/Difficalcy/Services/TestBeatmapProvider.cs @@ -2,6 +2,7 @@ using System.IO; using System.Reflection; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; namespace Difficalcy.Services { @@ -9,20 +10,22 @@ public class TestBeatmapProvider(string resourceAssemblyName) : IBeatmapProvider { public Task EnsureBeatmap(string beatmapId) { - var resourceName = $"{resourceAssemblyName}.Resources.{beatmapId}"; - var info = ResourceAssembly.GetManifestResourceInfo(resourceName); - return Task.FromResult(info != null); + var resourceName = GetResourceName(beatmapId); + _ = ResourceAssembly.GetManifestResourceInfo(resourceName) ?? throw new BadHttpRequestException($"Beatmap not found: {beatmapId}"); + return Task.CompletedTask; } public Stream GetBeatmapStream(string beatmapId) + { + var resourceName = GetResourceName(beatmapId); + return ResourceAssembly.GetManifestResourceStream(resourceName); + } + + private string GetResourceName(string beatmapId) { var resourceNamespace = "Testing.Beatmaps"; var resourceName = $"{resourceNamespace}.{beatmapId}.osu"; - var fullResourceName = $"{resourceAssemblyName}.Resources.{resourceName}"; - var stream = ResourceAssembly.GetManifestResourceStream(fullResourceName); - if (stream == null) - throw new Exception($@"Unable to find resource ""{fullResourceName}"" in assembly ""{resourceAssemblyName}"""); - return stream; + return $"{resourceAssemblyName}.Resources.{resourceName}"; } private Assembly ResourceAssembly