blob: 272c434fe9cb5f44263218319a73e76c20ca9b21 (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using Moq;
using Xunit;
namespace Jellyfin.Controller.Tests.Entities;
[Collection("LibraryManagerTests")]
public class AggregateFolderTests
{
[Fact]
public void Children_ClearedAfterALibraryWasAdded_ListsTheNewLibrary()
{
var existing = new Folder { Id = Guid.NewGuid(), Path = "/libraries/movies" };
var added = new Folder { Id = Guid.NewGuid(), Path = "/libraries/collections" };
// What the repository holds grows once the new library has been resolved and stored.
var stored = new List<BaseItem> { existing };
var itemRepository = new Mock<IItemRepository>();
itemRepository.Setup(x => x.GetItemList(It.IsAny<InternalItemsQuery>()))
.Returns(() => stored.ToList());
var libraryManager = new Mock<ILibraryManager>();
libraryManager.Setup(x => x.GetItemById(It.IsAny<Guid>()))
.Returns((Guid id) => stored.Find(i => i.Id.Equals(id)));
BaseItem.ItemRepository = itemRepository.Object;
BaseItem.LibraryManager = libraryManager.Object;
var root = new AggregateFolder { Id = Guid.NewGuid(), Path = "/libraries" };
Assert.Equal([existing.Id], root.Children.Select(i => i.Id));
stored.Add(added);
root.Children = null;
// Null-forgiving: the setter takes null to mean "drop the cache", the getter reloads.
Assert.Equal([existing.Id, added.Id], root.Children!.Select(i => i.Id));
}
[Fact]
public void Children_AssignedASet_KeepsThatSet()
{
var itemRepository = new Mock<IItemRepository>(MockBehavior.Strict);
BaseItem.ItemRepository = itemRepository.Object;
var assigned = new Folder { Id = Guid.NewGuid(), Path = "/libraries/movies" };
var root = new AggregateFolder { Id = Guid.NewGuid(), Path = "/libraries" };
root.Children = [assigned];
// Never goes to the repository, so the strict mock stays unused.
Assert.Equal([assigned.Id], root.Children.Select(i => i.Id));
}
}
|