1 files changed, 56 insertions, 0 deletions
diff --git a/Tests/LibMatrix.Tests/Tests/AuthMediaTests.cs b/Tests/LibMatrix.Tests/Tests/AuthMediaTests.cs
new file mode 100644
index 0000000..b2f5627
--- /dev/null
+++ b/Tests/LibMatrix.Tests/Tests/AuthMediaTests.cs
@@ -0,0 +1,56 @@
+using ArcaneLibs.Extensions;
+using ArcaneLibs.Extensions.Streams;
+using LibMatrix.Homeservers;
+using LibMatrix.Services;
+using LibMatrix.Tests.Abstractions;
+using LibMatrix.Tests.Fixtures;
+using Xunit.Abstractions;
+using Xunit.Microsoft.DependencyInjection.Abstracts;
+
+namespace LibMatrix.Tests.Tests;
+
+public class AuthMediaTests : TestBed<TestFixture> {
+ private readonly TestFixture _fixture;
+ private readonly HomeserverResolverService _resolver;
+ private readonly Config _config;
+ private readonly HomeserverProviderService _provider;
+
+ public AuthMediaTests(ITestOutputHelper testOutputHelper, TestFixture fixture) : base(testOutputHelper, fixture) {
+ _fixture = fixture;
+ _resolver = _fixture.GetService<HomeserverResolverService>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(HomeserverResolverService)}");
+ _config = _fixture.GetService<Config>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(Config)}");
+ _provider = _fixture.GetService<HomeserverProviderService>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(HomeserverProviderService)}");
+ }
+
+ private async Task<AuthenticatedHomeserverGeneric> GetHomeserver() => await HomeserverAbstraction.GetHomeserver();
+
+ [Fact]
+ public async Task UploadFileAsync() {
+ var hs = await HomeserverAbstraction.GetHomeserver();
+
+ var mxcUri = await hs.UploadFile("test", "LibMatrix test file".AsBytes());
+ Assert.NotNull(mxcUri);
+ }
+
+ [Fact]
+ public async Task DownloadFileAsync() {
+ var hs = await HomeserverAbstraction.GetHomeserver();
+
+ var mxcUri = await hs.UploadFile("test", "LibMatrix test file".AsBytes());
+ Assert.NotNull(mxcUri);
+
+ var file = await hs.GetMediaStreamAsync(mxcUri);
+ Assert.NotNull(file);
+
+ var data = file!.ReadToEnd().AsString();
+ Assert.Equal("LibMatrix test file", data);
+ }
+
+ [SkippableFact(typeof(LibMatrixException))] // This test will fail if the homeserver does not support URL previews
+ public async Task GetUrlPreviewAsync() {
+ var hs = await HomeserverAbstraction.GetHomeserver();
+ var preview = await hs.GetUrlPreviewAsync("https://matrix.org");
+
+ Assert.NotNull(preview);
+ }
+}
\ No newline at end of file
|