1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
using System;
using System.Threading.Tasks;
using Jellyfin.Api.Controllers;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using Moq;
using Xunit;
namespace Jellyfin.Api.Tests.Controllers;
public class ItemUpdateControllerTests
{
private readonly ItemUpdateController _subject;
public ItemUpdateControllerTests()
{
_subject = new ItemUpdateController(
Mock.Of<IFileSystem>(),
Mock.Of<ILibraryManager>(),
Mock.Of<IProviderManager>(),
Mock.Of<ILocalizationManager>(),
Mock.Of<IServerConfigurationManager>());
}
[Fact]
public async Task UpdateItem_WhenOnlyTagsFieldSupplied_DoesNotThrowAndAppliesTags()
{
// Regression test for https://github.com/jellyfin/jellyfin/issues/17366
// A partial update payload that only sets "Tags" leaves every other
// BaseItemDto collection property null (they have no default
// initializer). Genres and ProviderIds used to be fed straight into
// Distinct()/ToList() without a null check, so this call used to throw
// ArgumentNullException before the fix below was applied.
var movie = new Movie();
var request = new BaseItemDto
{
Tags = new[] { "new-tag-1", "new-tag-2" }
};
await InvokeUpdateItem(request, movie);
Assert.Equal(new[] { "new-tag-1", "new-tag-2" }, movie.Tags);
Assert.Empty(movie.Genres);
Assert.Empty(movie.ProviderIds);
}
[Fact]
public async Task UpdateItem_WhenGenresAndProviderIdsOmitted_LeavesExistingValuesUnchanged()
{
var movie = new Movie
{
Genres = new[] { "Action" }
};
movie.ProviderIds["Imdb"] = "tt1234567";
var request = new BaseItemDto
{
Tags = Array.Empty<string>()
};
await InvokeUpdateItem(request, movie);
Assert.Equal(new[] { "Action" }, movie.Genres);
Assert.Equal("tt1234567", movie.ProviderIds["Imdb"]);
}
private Task InvokeUpdateItem(BaseItemDto request, BaseItem item)
{
return _subject.UpdateItem(request, item);
}
}
|