aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTerry Wilson <103469370+dkschruteBeets@users.noreply.github.com>2025-03-02 17:54:24 -0700
committerTerry Wilson <103469370+dkschruteBeets@users.noreply.github.com>2025-03-02 17:54:24 -0700
commitcacd8538fb46283c74a399e53ac2cb48ede3734b (patch)
tree85e965a62e09f9fb655ea6fdf4dd46a6186f59ee /tests
parent07952c6ebe125120b848e0e9d5de85644185d9a5 (diff)
downloadslskd-cacd8538fb46283c74a399e53ac2cb48ede3734b.tar.gz
test: add profile picture test
Diffstat (limited to 'tests')
-rw-r--r--tests/slskd.Tests.Unit/Users/UserServiceTests.cs56
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/slskd.Tests.Unit/Users/UserServiceTests.cs b/tests/slskd.Tests.Unit/Users/UserServiceTests.cs
index 01fe855e..28f54629 100644
--- a/tests/slskd.Tests.Unit/Users/UserServiceTests.cs
+++ b/tests/slskd.Tests.Unit/Users/UserServiceTests.cs
@@ -1,8 +1,8 @@
namespace slskd.Tests.Unit.Users
{
using System.Collections.Generic;
+ using System.IO;
using AutoFixture.Xunit2;
- using Microsoft.EntityFrameworkCore;
using Moq;
using slskd.Files;
using slskd.Users;
@@ -121,6 +121,59 @@
}
}
+ public class GetProfilePicture
+ {
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData(" ")]
+ public void Returns_Null_When_Path_Is_NullOrWhitespace(string path)
+ {
+ var (service, _) = GetFixture();
+
+ var result = service.GetProfilePicture(path);
+
+ Assert.Null(result);
+ }
+
+ [Fact]
+ public void Returns_Null_When_File_Does_Not_Exist()
+ {
+ const string nonExistentPath = "nonexistent-file.jpg";
+ var (service, _) = GetFixture();
+
+ var result = service.GetProfilePicture(nonExistentPath);
+
+ Assert.Null(result);
+ }
+
+ [Fact]
+ public void Returns_File_Bytes_When_File_Exists()
+ {
+ var tempFile = Path.GetTempFileName();
+ try
+ {
+ // Write some test data to the temp file
+ System.IO.File.WriteAllBytes(tempFile, new byte[] { 1, 2, 3, 4, 5 });
+
+ var (service, _) = GetFixture();
+
+ var result = service.GetProfilePicture(tempFile);
+
+ Assert.NotNull(result);
+ Assert.Equal(new byte[] { 1, 2, 3, 4, 5 }, result);
+ }
+ finally
+ {
+ // Clean up
+ if (System.IO.File.Exists(tempFile))
+ {
+ System.IO.File.Delete(tempFile);
+ }
+ }
+ }
+ }
+
private static (UserService governor, Mocks mocks) GetFixture(Options options = null)
{
var mocks = new Mocks(options);
@@ -137,6 +190,7 @@
public Mocks(Options options = null)
{
OptionsMonitor = new TestOptionsMonitor<Options>(options ?? new Options());
+ FileService = new FileService(OptionsMonitor);
}
public Mock<ISoulseekClient> SoulseekClient { get; } = new Mock<ISoulseekClient>();