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
78
79
80
81
82
83
84
85
|
using System;
using Emby.Server.Implementations.Data;
using Jellyfin.Data.Enums;
using Jellyfin.Database.Implementations.Entities;
using Jellyfin.Server.Implementations.Item;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Persistence;
using Moq;
using Xunit;
namespace Jellyfin.Server.Implementations.Tests.Item;
/// <summary>
/// Covers <see cref="InternalPeopleQuery.MustHaveItem"/>. A caller that hands back by-name items can
/// only return the people that have one, so the count it reports has to leave out the rest rather than
/// describe a larger set than it can page through.
/// </summary>
public sealed class PeopleRepositoryMustHaveItemTests : SqliteDbTestFixture
{
private readonly PeopleRepository _people;
private readonly Guid _movie = Guid.NewGuid();
public PeopleRepositoryMustHaveItemTests()
{
var lookup = new ItemTypeLookup();
using (var context = CreateDbContext())
{
context.BaseItems.Add(new BaseItemEntity
{
Id = _movie,
Name = "Movie",
Type = lookup.BaseItemKindNames[BaseItemKind.Movie]
});
// Only one of the two credits has a by-name item behind it.
context.BaseItems.Add(new BaseItemEntity
{
Id = Guid.NewGuid(),
Name = "With Item",
Type = lookup.BaseItemKindNames[BaseItemKind.Person]
});
context.SaveChanges();
}
_people = new PeopleRepository(CreateDbContextFactory(), lookup, Mock.Of<IItemQueryHelpers>());
_people.UpdatePeople(_movie, [
new PersonInfo { Name = "With Item", Type = PersonKind.Actor },
new PersonInfo { Name = "Without Item", Type = PersonKind.Actor }
]);
}
[Fact]
public void WithoutMustHaveItem_ReturnsAndCountsEveryCredit()
{
var result = _people.GetPeople(new InternalPeopleQuery());
Assert.Equal(2, result.TotalRecordCount);
Assert.Equal(2, result.Items.Count);
}
[Fact]
public void MustHaveItem_DropsTheCreditWithoutAnItem()
{
var result = _people.GetPeople(new InternalPeopleQuery { MustHaveItem = true });
Assert.Equal("With Item", Assert.Single(result.Items).Name);
}
[Fact]
public void MustHaveItem_CountsOnlyWhatItCanReturn()
{
var result = _people.GetPeople(new InternalPeopleQuery { MustHaveItem = true });
Assert.Equal(1, result.TotalRecordCount);
}
[Fact]
public void MustHaveItem_CountAgreesWithThePageWhenLimited()
{
var result = _people.GetPeople(new InternalPeopleQuery { MustHaveItem = true, Limit = 10 });
Assert.Equal(result.Items.Count, result.TotalRecordCount);
}
}
|