diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-04-05 16:51:39 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-05 16:51:39 -0500 |
| commit | ac53fb5b3639292113b06876a05f402f7d1f0520 (patch) | |
| tree | 29726be4a5ecdb1aae6e4f296ad5af7152ea9ce2 /tests | |
| parent | eec6e0f098effcb9bfda297a441ca7ffd8d33934 (diff) | |
| parent | 1a3e8c9d8a1857e1ac0c3fe92d5ab1408aa3d0df (diff) | |
| download | slskd-ac53fb5b3639292113b06876a05f402f7d1f0520.tar.gz | |
Merge pull request #1303 from dkschruteBeets/feature/add-profile-picture-support
Feature/add profile picture support
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/slskd.Tests.Unit/Users/UserServiceTests.cs | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/tests/slskd.Tests.Unit/Users/UserServiceTests.cs b/tests/slskd.Tests.Unit/Users/UserServiceTests.cs index 1fd21c32..28f54629 100644 --- a/tests/slskd.Tests.Unit/Users/UserServiceTests.cs +++ b/tests/slskd.Tests.Unit/Users/UserServiceTests.cs @@ -1,9 +1,10 @@ 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; using Soulseek; using Xunit; @@ -120,12 +121,66 @@ } } + 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); var service = new UserService( mocks.SoulseekClient.Object, - mocks.OptionsMonitor); + mocks.OptionsMonitor, + mocks.FileService); return (service, mocks); } @@ -135,10 +190,12 @@ public Mocks(Options options = null) { OptionsMonitor = new TestOptionsMonitor<Options>(options ?? new Options()); + FileService = new FileService(OptionsMonitor); } public Mock<ISoulseekClient> SoulseekClient { get; } = new Mock<ISoulseekClient>(); public TestOptionsMonitor<Options> OptionsMonitor { get; init; } + public FileService FileService { get; init; } } } } |
