aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2023-11-30 17:40:06 +0100
committerGitHub <noreply@github.com>2023-11-30 17:40:06 +0100
commitcc276838b4edbb67356b805952262c38e9c9cd19 (patch)
tree8cb27ed0ba34fdd2d941f43c09ccc2be70c10abb /tests
parentcf80ea25413b75bbeddaef136fbeee33aa882a60 (diff)
parente46e3be667c76ff9a242d7499aff83d2d10881ed (diff)
Merge pull request #10558 from barronpm/dlna-plugin2
Move DLNA to Plugin (Part 2)
Diffstat (limited to 'tests')
-rw-r--r--tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs131
-rw-r--r--tests/Jellyfin.Dlna.Tests/GetUuidTests.cs17
-rw-r--r--tests/Jellyfin.Dlna.Tests/Jellyfin.Dlna.Tests.csproj18
-rw-r--r--tests/Jellyfin.Dlna.Tests/Server/DescriptionXmlBuilderTests.cs47
-rw-r--r--tests/Jellyfin.Server.Integration.Tests/Controllers/DlnaControllerTests.cs154
5 files changed, 0 insertions, 367 deletions
diff --git a/tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs b/tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs
deleted file mode 100644
index 78a956f5f..000000000
--- a/tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-using Emby.Dlna;
-using Emby.Dlna.PlayTo;
-using MediaBrowser.Common.Configuration;
-using MediaBrowser.Controller;
-using MediaBrowser.Model.Dlna;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Serialization;
-using Microsoft.Extensions.Logging;
-using Moq;
-using Xunit;
-
-namespace Jellyfin.Dlna.Tests
-{
- public class DlnaManagerTests
- {
- private DlnaManager GetManager()
- {
- var xmlSerializer = new Mock<IXmlSerializer>();
- var fileSystem = new Mock<IFileSystem>();
- var appPaths = new Mock<IApplicationPaths>();
- var loggerFactory = new Mock<ILoggerFactory>();
- var appHost = new Mock<IServerApplicationHost>();
-
- return new DlnaManager(xmlSerializer.Object, fileSystem.Object, appPaths.Object, loggerFactory.Object, appHost.Object);
- }
-
- [Fact]
- public void IsMatch_GivenMatchingName_ReturnsTrue()
- {
- var device = new DeviceInfo()
- {
- Name = "My Device",
- Manufacturer = "LG Electronics",
- ManufacturerUrl = "http://www.lge.com",
- ModelDescription = "LG WebOSTV DMRplus",
- ModelName = "LG TV",
- ModelNumber = "1.0",
- };
-
- var profile = new DeviceProfile()
- {
- Name = "Test Profile",
- FriendlyName = "My Device",
- Manufacturer = "LG Electronics",
- ManufacturerUrl = "http://www.lge.com",
- ModelDescription = "LG WebOSTV DMRplus",
- ModelName = "LG TV",
- ModelNumber = "1.0",
- Identification = new()
- {
- FriendlyName = "My Device",
- Manufacturer = "LG Electronics",
- ManufacturerUrl = "http://www.lge.com",
- ModelDescription = "LG WebOSTV DMRplus",
- ModelName = "LG TV",
- ModelNumber = "1.0",
- }
- };
-
- var profile2 = new DeviceProfile()
- {
- Name = "Test Profile",
- FriendlyName = "My Device",
- Identification = new DeviceIdentification()
- {
- FriendlyName = "My Device",
- }
- };
-
- var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile2.Identification);
- var deviceMatch2 = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
-
- Assert.True(deviceMatch);
- Assert.True(deviceMatch2);
- }
-
- [Fact]
- public void IsMatch_GivenNamesAndManufacturersDoNotMatch_ReturnsFalse()
- {
- var device = new DeviceInfo()
- {
- Name = "My Device",
- Manufacturer = "JVC"
- };
-
- var profile = new DeviceProfile()
- {
- Name = "Test Profile",
- FriendlyName = "My Device",
- Manufacturer = "LG Electronics",
- ManufacturerUrl = "http://www.lge.com",
- ModelDescription = "LG WebOSTV DMRplus",
- ModelName = "LG TV",
- ModelNumber = "1.0",
- Identification = new()
- {
- FriendlyName = "My Device",
- Manufacturer = "LG Electronics",
- ManufacturerUrl = "http://www.lge.com",
- ModelDescription = "LG WebOSTV DMRplus",
- ModelName = "LG TV",
- ModelNumber = "1.0",
- }
- };
-
- var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
-
- Assert.False(deviceMatch);
- }
-
- [Fact]
- public void IsMatch_GivenNamesAndRegExMatch_ReturnsTrue()
- {
- var device = new DeviceInfo()
- {
- Name = "My Device"
- };
-
- var profile = new DeviceProfile()
- {
- Name = "Test Profile",
- FriendlyName = "My .*",
- Identification = new()
- };
-
- var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
-
- Assert.True(deviceMatch);
- }
- }
-}
diff --git a/tests/Jellyfin.Dlna.Tests/GetUuidTests.cs b/tests/Jellyfin.Dlna.Tests/GetUuidTests.cs
deleted file mode 100644
index 7655e3f7c..000000000
--- a/tests/Jellyfin.Dlna.Tests/GetUuidTests.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using Emby.Dlna.PlayTo;
-using Xunit;
-
-namespace Jellyfin.Dlna.Tests
-{
- public static class GetUuidTests
- {
- [Theory]
- [InlineData("uuid:fc4ec57e-b051-11db-88f8-0060085db3f6::urn:schemas-upnp-org:device:WANDevice:1", "fc4ec57e-b051-11db-88f8-0060085db3f6")]
- [InlineData("uuid:IGD{8c80f73f-4ba0-45fa-835d-042505d052be}000000000000", "8c80f73f-4ba0-45fa-835d-042505d052be")]
- [InlineData("uuid:IGD{8c80f73f-4ba0-45fa-835d-042505d052be}000000000000::urn:schemas-upnp-org:device:InternetGatewayDevice:1", "8c80f73f-4ba0-45fa-835d-042505d052be")]
- [InlineData("uuid:00000000-0000-0000-0000-000000000000::upnp:rootdevice", "00000000-0000-0000-0000-000000000000")]
- [InlineData("uuid:fc4ec57e-b051-11db-88f8-0060085db3f6", "fc4ec57e-b051-11db-88f8-0060085db3f6")]
- public static void GetUuid_Valid_Success(string usn, string uuid)
- => Assert.Equal(uuid, PlayToManager.GetUuid(usn));
- }
-}
diff --git a/tests/Jellyfin.Dlna.Tests/Jellyfin.Dlna.Tests.csproj b/tests/Jellyfin.Dlna.Tests/Jellyfin.Dlna.Tests.csproj
deleted file mode 100644
index 69677ce42..000000000
--- a/tests/Jellyfin.Dlna.Tests/Jellyfin.Dlna.Tests.csproj
+++ /dev/null
@@ -1,18 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
- <ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" />
- <PackageReference Include="Moq" />
- <PackageReference Include="xunit" />
- <PackageReference Include="xunit.runner.visualstudio">
- <PrivateAssets>all</PrivateAssets>
- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
- </PackageReference>
- <PackageReference Include="coverlet.collector" />
- </ItemGroup>
-
- <ItemGroup>
- <ProjectReference Include="../../Emby.Dlna/Emby.Dlna.csproj" />
- </ItemGroup>
-
-</Project>
diff --git a/tests/Jellyfin.Dlna.Tests/Server/DescriptionXmlBuilderTests.cs b/tests/Jellyfin.Dlna.Tests/Server/DescriptionXmlBuilderTests.cs
deleted file mode 100644
index c9018fe2f..000000000
--- a/tests/Jellyfin.Dlna.Tests/Server/DescriptionXmlBuilderTests.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using Emby.Dlna.Server;
-using MediaBrowser.Model.Dlna;
-using Xunit;
-
-namespace Jellyfin.Dlna.Server.Tests;
-
-public class DescriptionXmlBuilderTests
-{
- [Fact]
- public void GetFriendlyName_EmptyProfile_ReturnsServerName()
- {
- const string ServerName = "Test Server Name";
- var builder = new DescriptionXmlBuilder(new DeviceProfile(), "serverUdn", "localhost", ServerName, string.Empty);
- Assert.Equal(ServerName, builder.GetFriendlyName());
- }
-
- [Fact]
- public void GetFriendlyName_FriendlyName_ReturnsFriendlyName()
- {
- const string FriendlyName = "Friendly Neighborhood Test Server";
- var builder = new DescriptionXmlBuilder(
- new DeviceProfile()
- {
- FriendlyName = FriendlyName
- },
- "serverUdn",
- "localhost",
- "Test Server Name",
- string.Empty);
- Assert.Equal(FriendlyName, builder.GetFriendlyName());
- }
-
- [Fact]
- public void GetFriendlyName_FriendlyNameInterpolation_ReturnsFriendlyName()
- {
- var builder = new DescriptionXmlBuilder(
- new DeviceProfile()
- {
- FriendlyName = "Friendly Neighborhood ${HostName}"
- },
- "serverUdn",
- "localhost",
- "Test Server Name",
- string.Empty);
- Assert.Equal("Friendly Neighborhood TestServerName", builder.GetFriendlyName());
- }
-}
diff --git a/tests/Jellyfin.Server.Integration.Tests/Controllers/DlnaControllerTests.cs b/tests/Jellyfin.Server.Integration.Tests/Controllers/DlnaControllerTests.cs
deleted file mode 100644
index e5d5e785c..000000000
--- a/tests/Jellyfin.Server.Integration.Tests/Controllers/DlnaControllerTests.cs
+++ /dev/null
@@ -1,154 +0,0 @@
-using System;
-using System.Linq;
-using System.Net;
-using System.Net.Http.Json;
-using System.Net.Mime;
-using System.Text;
-using System.Text.Json;
-using System.Threading.Tasks;
-using Jellyfin.Extensions.Json;
-using MediaBrowser.Model.Dlna;
-using Xunit;
-using Xunit.Priority;
-
-namespace Jellyfin.Server.Integration.Tests.Controllers
-{
- [TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
- public sealed class DlnaControllerTests : IClassFixture<JellyfinApplicationFactory>
- {
- private const string NonExistentProfile = "1322f35b8f2c434dad3cc07c9b97dbd1";
- private readonly JellyfinApplicationFactory _factory;
- private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
- private static string? _accessToken;
- private static string? _newDeviceProfileId;
-
- public DlnaControllerTests(JellyfinApplicationFactory factory)
- {
- _factory = factory;
- }
-
- [Fact]
- [Priority(0)]
- public async Task GetProfile_DoesNotExist_NotFound()
- {
- var client = _factory.CreateClient();
- client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
-
- using var response = await client.GetAsync("/Dlna/Profiles/" + NonExistentProfile);
- Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
- }
-
- [Fact]
- [Priority(0)]
- public async Task DeleteProfile_DoesNotExist_NotFound()
- {
- var client = _factory.CreateClient();
- client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
-
- using var response = await client.DeleteAsync("/Dlna/Profiles/" + NonExistentProfile);
- Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
- }
-
- [Fact]
- [Priority(0)]
- public async Task UpdateProfile_DoesNotExist_NotFound()
- {
- var client = _factory.CreateClient();
- client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
-
- var deviceProfile = new DeviceProfile()
- {
- Name = "ThisProfileDoesNotExist"
- };
-
- using var response = await client.PostAsJsonAsync("/Dlna/Profiles/" + NonExistentProfile, deviceProfile, _jsonOptions);
- Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
- }
-
- [Fact]
- [Priority(1)]
- public async Task CreateProfile_Valid_NoContent()
- {
- var client = _factory.CreateClient();
- client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
-
- var deviceProfile = new DeviceProfile()
- {
- Name = "ThisProfileIsNew"
- };
-
- using var response = await client.PostAsJsonAsync("/Dlna/Profiles", deviceProfile, _jsonOptions);
- Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
- }
-
- [Fact]
- [Priority(2)]
- public async Task GetProfileInfos_Valid_ContainsThisProfileIsNew()
- {
- var client = _factory.CreateClient();
- client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
-
- using var response = await client.GetAsync("/Dlna/ProfileInfos");
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- Assert.Equal(MediaTypeNames.Application.Json, response.Content.Headers.ContentType?.MediaType);
- Assert.Equal(Encoding.UTF8.BodyName, response.Content.Headers.ContentType?.CharSet);
-
- var profiles = await response.Content.ReadFromJsonAsync<DeviceProfileInfo[]>(_jsonOptions);
-
- var newProfile = profiles?.FirstOrDefault(x => string.Equals(x.Name, "ThisProfileIsNew", StringComparison.Ordinal));
- Assert.NotNull(newProfile);
- _newDeviceProfileId = newProfile!.Id;
- }
-
- [Fact]
- [Priority(3)]
- public async Task UpdateProfile_Valid_NoContent()
- {
- var client = _factory.CreateClient();
- client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
-
- var updatedProfile = new DeviceProfile()
- {
- Name = "ThisProfileIsUpdated",
- Id = _newDeviceProfileId
- };
-
- using var postResponse = await client.PostAsJsonAsync("/Dlna/Profiles/" + _newDeviceProfileId, updatedProfile, _jsonOptions);
- Assert.Equal(HttpStatusCode.NoContent, postResponse.StatusCode);
-
- // Verify that the profile got updated
- using var response = await client.GetAsync("/Dlna/ProfileInfos");
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- Assert.Equal(MediaTypeNames.Application.Json, response.Content.Headers.ContentType?.MediaType);
- Assert.Equal(Encoding.UTF8.BodyName, response.Content.Headers.ContentType?.CharSet);
-
- var profiles = await response.Content.ReadFromJsonAsync<DeviceProfileInfo[]>(_jsonOptions);
-
- Assert.Null(profiles?.FirstOrDefault(x => string.Equals(x.Name, "ThisProfileIsNew", StringComparison.Ordinal)));
- var newProfile = profiles?.FirstOrDefault(x => string.Equals(x.Name, "ThisProfileIsUpdated", StringComparison.Ordinal));
- Assert.NotNull(newProfile);
- _newDeviceProfileId = newProfile!.Id;
- }
-
- [Fact]
- [Priority(5)]
- public async Task DeleteProfile_Valid_NoContent()
- {
- var client = _factory.CreateClient();
- client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
-
- using var deleteResponse = await client.DeleteAsync("/Dlna/Profiles/" + _newDeviceProfileId);
- Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode);
-
- // Verify that the profile got deleted
- using var response = await client.GetAsync("/Dlna/ProfileInfos");
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- Assert.Equal(MediaTypeNames.Application.Json, response.Content.Headers.ContentType?.MediaType);
- Assert.Equal(Encoding.UTF8.BodyName, response.Content.Headers.ContentType?.CharSet);
-
- var profiles = await response.Content.ReadFromJsonAsync<DeviceProfileInfo[]>(_jsonOptions);
-
- Assert.Null(profiles?.FirstOrDefault(x => string.Equals(x.Name, "ThisProfileIsUpdated", StringComparison.Ordinal)));
- }
- }
-}