97 lines
3.7 KiB
C#
97 lines
3.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Paca.Server;
|
|
using Xunit;
|
|
|
|
namespace Paca.Tests.Server;
|
|
|
|
public class ServerSmartPlaylistGateTests
|
|
{
|
|
[Fact]
|
|
public async Task Gate235_ServerHost_GetPlaylistM3u8_ReturnsValidContent()
|
|
{
|
|
var tempDir = Path.Combine(Path.GetTempPath(), "paca_playlist_test_" + Guid.NewGuid());
|
|
Directory.CreateDirectory(tempDir);
|
|
try
|
|
{
|
|
var testFile1 = Path.Combine(tempDir, "video1.mp4");
|
|
File.WriteAllBytes(testFile1, new byte[1024]);
|
|
|
|
var options = new ServerOptions
|
|
{
|
|
Port = 0,
|
|
Token = "test-token-123456",
|
|
LibraryFolder = tempDir,
|
|
DeviceName = "TestPC",
|
|
Queue = new TestQueueAdapter()
|
|
};
|
|
|
|
await using var host = await ServerHost.StartAsync(options);
|
|
using var client = new HttpClient();
|
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "test-token-123456");
|
|
|
|
var resp = await client.GetAsync($"http://127.0.0.1:{host.Port}/api/playlist/all.m3u8");
|
|
Assert.True(resp.IsSuccessStatusCode);
|
|
Assert.Contains("mpegurl", resp.Content.Headers.ContentType?.MediaType ?? "");
|
|
|
|
var body = await resp.Content.ReadAsStringAsync();
|
|
Assert.StartsWith("#EXTM3U", body.Trim());
|
|
Assert.Contains("video1.mp4", body);
|
|
}
|
|
finally
|
|
{
|
|
try { Directory.Delete(tempDir, true); } catch { }
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Gate236_ServerHost_GetPlaylistM3u8_SpecificCollection_FiltersCorrectly()
|
|
{
|
|
var tempDir = Path.Combine(Path.GetTempPath(), "paca_playlist_test_filtered_" + Guid.NewGuid());
|
|
Directory.CreateDirectory(tempDir);
|
|
try
|
|
{
|
|
var audioFile = Path.Combine(tempDir, "song.mp3");
|
|
var videoFile = Path.Combine(tempDir, "lecture.mp4");
|
|
File.WriteAllBytes(audioFile, new byte[1024]);
|
|
File.WriteAllBytes(videoFile, new byte[1024]);
|
|
|
|
var options = new ServerOptions
|
|
{
|
|
Port = 0,
|
|
Token = "test-token-789",
|
|
LibraryFolder = tempDir,
|
|
DeviceName = "TestPC",
|
|
Queue = new TestQueueAdapter()
|
|
};
|
|
|
|
await using var host = await ServerHost.StartAsync(options);
|
|
using var client = new HttpClient();
|
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "test-token-789");
|
|
|
|
var resp = await client.GetAsync($"http://127.0.0.1:{host.Port}/api/playlist/Music%20%26%20Podcasts.m3u8");
|
|
Assert.True(resp.IsSuccessStatusCode);
|
|
|
|
var body = await resp.Content.ReadAsStringAsync();
|
|
Assert.StartsWith("#EXTM3U", body.Trim());
|
|
Assert.Contains("song.mp3", body);
|
|
Assert.DoesNotContain("lecture.mp4", body);
|
|
}
|
|
finally
|
|
{
|
|
try { Directory.Delete(tempDir, true); } catch { }
|
|
}
|
|
}
|
|
|
|
private class TestQueueAdapter : IQueueAdapter
|
|
{
|
|
public Task<string> AddAsync(string url, string? title = null) => Task.FromResult("q1");
|
|
public Task CancelAsync(string id) => Task.CompletedTask;
|
|
public Task<IReadOnlyList<QueueItemDto>> GetItemsAsync() => Task.FromResult<IReadOnlyList<QueueItemDto>>(Array.Empty<QueueItemDto>());
|
|
public Task PauseAsync(string id) => Task.CompletedTask;
|
|
public Task ResumeAsync(string id) => Task.CompletedTask;
|
|
public event Action? Changed { add { } remove { } }
|
|
}
|
|
}
|