Skip to content

Commit

Permalink
Fix TestBeatmapProvider not ensuring beatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Syriiin committed May 18, 2024
1 parent 3edb9da commit e656d9f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Difficalcy/Services/TestBeatmapProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;

namespace Difficalcy.Services
{
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
Expand Down

0 comments on commit e656d9f

Please sign in to comment.