From cacd8538fb46283c74a399e53ac2cb48ede3734b Mon Sep 17 00:00:00 2001 From: Terry Wilson <103469370+dkschruteBeets@users.noreply.github.com> Date: Sun, 2 Mar 2025 17:54:24 -0700 Subject: test: add profile picture test --- tests/slskd.Tests.Unit/Users/UserServiceTests.cs | 56 +++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) 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 ?? new Options()); + FileService = new FileService(OptionsMonitor); } public Mock SoulseekClient { get; } = new Mock(); -- cgit v1.2.3