|
2 | 2 | using System.Collections; |
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.IO; |
| 5 | +using Jellyfin.Plugin.Themerr; |
5 | 6 | using Jellyfin.Plugin.Themerr.Api; |
6 | 7 | using Jellyfin.Plugin.Themerr.Storage; |
7 | 8 | using MediaBrowser.Common.Configuration; |
@@ -68,6 +69,18 @@ public void TestGetProgress() |
68 | 69 | Assert.Empty(items); |
69 | 70 | } |
70 | 71 |
|
| 72 | + /// <summary> |
| 73 | + /// Test TriggerUpdateRequest starts and completes an update. |
| 74 | + /// </summary> |
| 75 | + [Fact] |
| 76 | + [Trait("Category", "Unit")] |
| 77 | + public async Task TestTriggerUpdateRequest() |
| 78 | + { |
| 79 | + await _controller.TriggerUpdateRequest(); |
| 80 | + |
| 81 | + Assert.NotNull(_controller); |
| 82 | + } |
| 83 | + |
71 | 84 | /// <summary> |
72 | 85 | /// Test GetProgress from API with items pre-populated in the database. |
73 | 86 | /// </summary> |
@@ -135,4 +148,71 @@ public async Task TestReplaceThemeNotFound() |
135 | 148 | var result = await _controller.ReplaceTheme(Guid.NewGuid()); |
136 | 149 | Assert.IsType<NotFoundResult>(result); |
137 | 150 | } |
| 151 | + |
| 152 | + /// <summary> |
| 153 | + /// Test ReplaceTheme returns 204 when the item theme is replaced. |
| 154 | + /// </summary> |
| 155 | + [Fact] |
| 156 | + [Trait("Category", "Unit")] |
| 157 | + public async Task TestReplaceThemeNoContent() |
| 158 | + { |
| 159 | + var tempPath = Path.Combine(Path.GetTempPath(), "ThemerrJellyfinTests", Guid.NewGuid().ToString("N")); |
| 160 | + Directory.CreateDirectory(tempPath); |
| 161 | + var movie = new Movie |
| 162 | + { |
| 163 | + Name = "Controller Replace", |
| 164 | + Path = Path.Combine(tempPath, "Controller Replace (1970).mp4"), |
| 165 | + ProductionYear = 1970, |
| 166 | + ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), "controller-replace" } }, |
| 167 | + }; |
| 168 | + var themePath = ThemerrManager.GetThemePath(movie); |
| 169 | + var audioStubPath = Path.Combine(Directory.GetCurrentDirectory(), "data", "audio_stub.mp3"); |
| 170 | + var repository = new ThemerrRepository( |
| 171 | + Path.Combine(tempPath, "themerr.db"), |
| 172 | + new Mock<ILogger>().Object); |
| 173 | + repository.Save(movie, new ThemerrMediaItemSaveOptions |
| 174 | + { |
| 175 | + ThemePath = themePath, |
| 176 | + ThemeProvider = ThemerrThemeProvider.User, |
| 177 | + InThemerrDb = true, |
| 178 | + InThemerrDbCheckedUtc = DateTime.UtcNow, |
| 179 | + YoutubeThemeUrl = "https://www.youtube.com/watch?v=controller-replace", |
| 180 | + }); |
| 181 | + |
| 182 | + var mockApplicationPaths = TestHelper.GetMockApplicationPaths(tempPath); |
| 183 | + var mockLibraryManager = new Mock<ILibraryManager>(); |
| 184 | + mockLibraryManager |
| 185 | + .Setup(x => x.GetItemById(movie.Id)) |
| 186 | + .Returns(movie); |
| 187 | + var mockYoutubeClient = new Mock<IYoutubeClientWrapper>(); |
| 188 | + mockYoutubeClient |
| 189 | + .Setup(x => x.DownloadAudioAsync(It.IsAny<string>(), It.IsAny<string>())) |
| 190 | + .Returns<string, string>((_, destination) => |
| 191 | + { |
| 192 | + File.Copy(audioStubPath, destination, true); |
| 193 | + return Task.CompletedTask; |
| 194 | + }); |
| 195 | + var manager = new ThemerrManager( |
| 196 | + mockApplicationPaths.Object, |
| 197 | + mockLibraryManager.Object, |
| 198 | + new Mock<ILogger<ThemerrManager>>().Object, |
| 199 | + mockYoutubeClient.Object, |
| 200 | + repository); |
| 201 | + var controller = new ThemerrController(manager, new Mock<ILogger<ThemerrController>>().Object); |
| 202 | + |
| 203 | + try |
| 204 | + { |
| 205 | + var result = await controller.ReplaceTheme(movie.Id); |
| 206 | + |
| 207 | + Assert.IsType<NoContentResult>(result); |
| 208 | + Assert.True(File.Exists(themePath)); |
| 209 | + } |
| 210 | + finally |
| 211 | + { |
| 212 | + if (File.Exists(themePath)) |
| 213 | + { |
| 214 | + File.Delete(themePath); |
| 215 | + } |
| 216 | + } |
| 217 | + } |
138 | 218 | } |
0 commit comments