|
4 | 4 | using Moq.AutoMock; |
5 | 5 | using NUnit.Framework; |
6 | 6 | using Ombi.Core; |
| 7 | +using Ombi.Core.Settings; |
7 | 8 | using Ombi.Hubs; |
8 | 9 | using Ombi.Notifications.Models; |
9 | 10 | using Ombi.Schedule.Jobs; |
| 11 | +using Ombi.Settings.Settings.Models.External; |
10 | 12 | using Ombi.Store.Entities; |
11 | 13 | using Ombi.Store.Entities.Requests; |
| 14 | +using Ombi.Store.Repository; |
12 | 15 | using Ombi.Store.Repository.Requests; |
13 | 16 | using Ombi.Tests; |
14 | 17 | using System.Collections.Generic; |
@@ -177,15 +180,190 @@ public async Task All_One_Episode_Is_Available_In_Request() |
177 | 180 | _mocker.Verify<INotificationHelper>(x => x.Notify(It.Is<NotificationOptions>(x => x.NotificationType == Helpers.NotificationType.PartiallyAvailable && x.RequestId == 1)), Times.Once); |
178 | 181 | }); |
179 | 182 | } |
| 183 | + |
| 184 | + [Test] |
| 185 | + public async Task ShouldDeferToRadarr_WhenRadarrDisabled_ReturnsFalse() |
| 186 | + { |
| 187 | + var subject = CreateSubjectWithArrDependencies(); |
| 188 | + _mocker.Setup<ISettingsService<RadarrSettings>, Task<RadarrSettings>>(x => x.GetSettingsAsync()) |
| 189 | + .ReturnsAsync(new RadarrSettings { Enabled = false, ScanForAvailability = true, PrioritizeArrAvailability = true }); |
| 190 | + |
| 191 | + var result = await subject.TestShouldDeferToRadarr(123, false); |
| 192 | + |
| 193 | + Assert.That(result, Is.False); |
| 194 | + } |
| 195 | + |
| 196 | + [Test] |
| 197 | + public async Task ShouldDeferToRadarr_WhenScanForAvailabilityDisabled_ReturnsFalse() |
| 198 | + { |
| 199 | + var subject = CreateSubjectWithArrDependencies(); |
| 200 | + _mocker.Setup<ISettingsService<RadarrSettings>, Task<RadarrSettings>>(x => x.GetSettingsAsync()) |
| 201 | + .ReturnsAsync(new RadarrSettings { Enabled = true, ScanForAvailability = false, PrioritizeArrAvailability = true }); |
| 202 | + |
| 203 | + var result = await subject.TestShouldDeferToRadarr(123, false); |
| 204 | + |
| 205 | + Assert.That(result, Is.False); |
| 206 | + } |
| 207 | + |
| 208 | + [Test] |
| 209 | + public async Task ShouldDeferToRadarr_WhenPrioritizeArrAvailabilityDisabled_ReturnsFalse() |
| 210 | + { |
| 211 | + var subject = CreateSubjectWithArrDependencies(); |
| 212 | + _mocker.Setup<ISettingsService<RadarrSettings>, Task<RadarrSettings>>(x => x.GetSettingsAsync()) |
| 213 | + .ReturnsAsync(new RadarrSettings { Enabled = true, ScanForAvailability = true, PrioritizeArrAvailability = false }); |
| 214 | + |
| 215 | + var result = await subject.TestShouldDeferToRadarr(123, false); |
| 216 | + |
| 217 | + Assert.That(result, Is.False); |
| 218 | + } |
| 219 | + |
| 220 | + [Test] |
| 221 | + public async Task ShouldDeferToRadarr_WhenNotInCache_ReturnsFalse() |
| 222 | + { |
| 223 | + var subject = CreateSubjectWithArrDependencies(); |
| 224 | + _mocker.Setup<ISettingsService<RadarrSettings>, Task<RadarrSettings>>(x => x.GetSettingsAsync()) |
| 225 | + .ReturnsAsync(new RadarrSettings { Enabled = true, ScanForAvailability = true, PrioritizeArrAvailability = true }); |
| 226 | + _mocker.Setup<IExternalRepository<RadarrCache>, IQueryable<RadarrCache>>(x => x.GetAll()) |
| 227 | + .Returns(new List<RadarrCache>().AsQueryable().BuildMock()); |
| 228 | + |
| 229 | + var result = await subject.TestShouldDeferToRadarr(123, false); |
| 230 | + |
| 231 | + Assert.That(result, Is.False); |
| 232 | + } |
| 233 | + |
| 234 | + [Test] |
| 235 | + public async Task ShouldDeferToRadarr_WhenInCacheWithFile_ReturnsTrue() |
| 236 | + { |
| 237 | + var subject = CreateSubjectWithArrDependencies(); |
| 238 | + _mocker.Setup<ISettingsService<RadarrSettings>, Task<RadarrSettings>>(x => x.GetSettingsAsync()) |
| 239 | + .ReturnsAsync(new RadarrSettings { Enabled = true, ScanForAvailability = true, PrioritizeArrAvailability = true }); |
| 240 | + _mocker.Setup<IExternalRepository<RadarrCache>, IQueryable<RadarrCache>>(x => x.GetAll()) |
| 241 | + .Returns(new List<RadarrCache> { new RadarrCache { TheMovieDbId = 123, HasFile = true, HasRegular = true } }.AsQueryable().BuildMock()); |
| 242 | + |
| 243 | + var result = await subject.TestShouldDeferToRadarr(123, false); |
| 244 | + |
| 245 | + Assert.That(result, Is.True); |
| 246 | + } |
| 247 | + |
| 248 | + [Test] |
| 249 | + public async Task ShouldDeferToRadarr_4K_WhenInCacheWith4K_ReturnsTrue() |
| 250 | + { |
| 251 | + var subject = CreateSubjectWithArrDependencies(); |
| 252 | + _mocker.Setup<ISettingsService<RadarrSettings>, Task<RadarrSettings>>(x => x.GetSettingsAsync()) |
| 253 | + .ReturnsAsync(new RadarrSettings { Enabled = true, ScanForAvailability = true, PrioritizeArrAvailability = true }); |
| 254 | + _mocker.Setup<IExternalRepository<RadarrCache>, IQueryable<RadarrCache>>(x => x.GetAll()) |
| 255 | + .Returns(new List<RadarrCache> { new RadarrCache { TheMovieDbId = 123, HasFile = true, Has4K = true } }.AsQueryable().BuildMock()); |
| 256 | + |
| 257 | + var result = await subject.TestShouldDeferToRadarr(123, true); |
| 258 | + |
| 259 | + Assert.That(result, Is.True); |
| 260 | + } |
| 261 | + |
| 262 | + [Test] |
| 263 | + public async Task ShouldDeferToSonarr_WhenSonarrDisabled_ReturnsFalse() |
| 264 | + { |
| 265 | + var subject = CreateSubjectWithArrDependencies(); |
| 266 | + _mocker.Setup<ISettingsService<SonarrSettings>, Task<SonarrSettings>>(x => x.GetSettingsAsync()) |
| 267 | + .ReturnsAsync(new SonarrSettings { Enabled = false, ScanForAvailability = true, PrioritizeArrAvailability = true }); |
| 268 | + |
| 269 | + var result = await subject.TestShouldDeferToSonarr(456); |
| 270 | + |
| 271 | + Assert.That(result, Is.False); |
| 272 | + } |
| 273 | + |
| 274 | + [Test] |
| 275 | + public async Task ShouldDeferToSonarr_WhenScanForAvailabilityDisabled_ReturnsFalse() |
| 276 | + { |
| 277 | + var subject = CreateSubjectWithArrDependencies(); |
| 278 | + _mocker.Setup<ISettingsService<SonarrSettings>, Task<SonarrSettings>>(x => x.GetSettingsAsync()) |
| 279 | + .ReturnsAsync(new SonarrSettings { Enabled = true, ScanForAvailability = false, PrioritizeArrAvailability = true }); |
| 280 | + |
| 281 | + var result = await subject.TestShouldDeferToSonarr(456); |
| 282 | + |
| 283 | + Assert.That(result, Is.False); |
| 284 | + } |
| 285 | + |
| 286 | + [Test] |
| 287 | + public async Task ShouldDeferToSonarr_WhenPrioritizeArrAvailabilityDisabled_ReturnsFalse() |
| 288 | + { |
| 289 | + var subject = CreateSubjectWithArrDependencies(); |
| 290 | + _mocker.Setup<ISettingsService<SonarrSettings>, Task<SonarrSettings>>(x => x.GetSettingsAsync()) |
| 291 | + .ReturnsAsync(new SonarrSettings { Enabled = true, ScanForAvailability = true, PrioritizeArrAvailability = false }); |
| 292 | + |
| 293 | + var result = await subject.TestShouldDeferToSonarr(456); |
| 294 | + |
| 295 | + Assert.That(result, Is.False); |
| 296 | + } |
| 297 | + |
| 298 | + [Test] |
| 299 | + public async Task ShouldDeferToSonarr_WhenNoEpisodesInCache_ReturnsFalse() |
| 300 | + { |
| 301 | + var subject = CreateSubjectWithArrDependencies(); |
| 302 | + _mocker.Setup<ISettingsService<SonarrSettings>, Task<SonarrSettings>>(x => x.GetSettingsAsync()) |
| 303 | + .ReturnsAsync(new SonarrSettings { Enabled = true, ScanForAvailability = true, PrioritizeArrAvailability = true }); |
| 304 | + _mocker.Setup<IExternalRepository<SonarrEpisodeCache>, IQueryable<SonarrEpisodeCache>>(x => x.GetAll()) |
| 305 | + .Returns(new List<SonarrEpisodeCache>().AsQueryable().BuildMock()); |
| 306 | + |
| 307 | + var result = await subject.TestShouldDeferToSonarr(456); |
| 308 | + |
| 309 | + Assert.That(result, Is.False); |
| 310 | + } |
| 311 | + |
| 312 | + [Test] |
| 313 | + public async Task ShouldDeferToSonarr_WhenEpisodesInCacheWithFile_ReturnsTrue() |
| 314 | + { |
| 315 | + var subject = CreateSubjectWithArrDependencies(); |
| 316 | + _mocker.Setup<ISettingsService<SonarrSettings>, Task<SonarrSettings>>(x => x.GetSettingsAsync()) |
| 317 | + .ReturnsAsync(new SonarrSettings { Enabled = true, ScanForAvailability = true, PrioritizeArrAvailability = true }); |
| 318 | + _mocker.Setup<IExternalRepository<SonarrEpisodeCache>, IQueryable<SonarrEpisodeCache>>(x => x.GetAll()) |
| 319 | + .Returns(new List<SonarrEpisodeCache> { new SonarrEpisodeCache { TvDbId = 456, HasFile = true } }.AsQueryable().BuildMock()); |
| 320 | + |
| 321 | + var result = await subject.TestShouldDeferToSonarr(456); |
| 322 | + |
| 323 | + Assert.That(result, Is.True); |
| 324 | + } |
| 325 | + |
| 326 | + private TestAvailabilityCheckerWithArrSupport CreateSubjectWithArrDependencies() |
| 327 | + { |
| 328 | + _mocker.Setup<ISettingsService<RadarrSettings>, Task<RadarrSettings>>(x => x.GetSettingsAsync()) |
| 329 | + .ReturnsAsync(new RadarrSettings()); |
| 330 | + _mocker.Setup<ISettingsService<SonarrSettings>, Task<SonarrSettings>>(x => x.GetSettingsAsync()) |
| 331 | + .ReturnsAsync(new SonarrSettings()); |
| 332 | + _mocker.Setup<IExternalRepository<RadarrCache>, IQueryable<RadarrCache>>(x => x.GetAll()) |
| 333 | + .Returns(new List<RadarrCache>().AsQueryable().BuildMock()); |
| 334 | + _mocker.Setup<IExternalRepository<SonarrEpisodeCache>, IQueryable<SonarrEpisodeCache>>(x => x.GetAll()) |
| 335 | + .Returns(new List<SonarrEpisodeCache>().AsQueryable().BuildMock()); |
| 336 | + |
| 337 | + return _mocker.CreateInstance<TestAvailabilityCheckerWithArrSupport>(); |
| 338 | + } |
180 | 339 | } |
181 | 340 |
|
182 | 341 |
|
183 | 342 | public class TestAvailabilityChecker : AvailabilityChecker |
184 | 343 | { |
185 | | - public TestAvailabilityChecker(ITvRequestRepository tvRequest, INotificationHelper notification, ILogger log, INotificationHubService notificationHubService) : base(tvRequest, notification, log, notificationHubService) |
| 344 | + public TestAvailabilityChecker(ITvRequestRepository tvRequest, INotificationHelper notification, ILogger log, INotificationHubService notificationHubService) : base(tvRequest, notification, log, notificationHubService, null, null, null, null) |
186 | 345 | { |
187 | 346 | } |
188 | 347 |
|
189 | 348 | public new Task ProcessTvShow(IQueryable<IBaseMediaServerEpisode> seriesEpisodes, ChildRequests child) => base.ProcessTvShow(seriesEpisodes, child); |
190 | 349 | } |
| 350 | + |
| 351 | + public class TestAvailabilityCheckerWithArrSupport : AvailabilityChecker |
| 352 | + { |
| 353 | + public TestAvailabilityCheckerWithArrSupport( |
| 354 | + ITvRequestRepository tvRequest, |
| 355 | + INotificationHelper notification, |
| 356 | + ILogger log, |
| 357 | + INotificationHubService notificationHubService, |
| 358 | + ISettingsService<RadarrSettings> radarrSettings, |
| 359 | + ISettingsService<SonarrSettings> sonarrSettings, |
| 360 | + IExternalRepository<RadarrCache> radarrCache, |
| 361 | + IExternalRepository<SonarrEpisodeCache> sonarrEpisodeCache) |
| 362 | + : base(tvRequest, notification, log, notificationHubService, radarrSettings, sonarrSettings, radarrCache, sonarrEpisodeCache) |
| 363 | + { |
| 364 | + } |
| 365 | + |
| 366 | + public Task<bool> TestShouldDeferToRadarr(int theMovieDbId, bool is4K) => base.ShouldDeferToRadarr(theMovieDbId, is4K); |
| 367 | + public Task<bool> TestShouldDeferToSonarr(int tvDbId) => base.ShouldDeferToSonarr(tvDbId); |
| 368 | + } |
191 | 369 | } |
0 commit comments