diff options
| -rw-r--r-- | tests/slskd.Tests.Unit/Users/UserServiceTests.cs | 56 |
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>(); |
