aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Server.Implementations.Tests/Sorting/PremiereDateComparerTests.cs
blob: 9dfacb2bf40cbc23f5e00e4cfca387fa518e6af4 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using Emby.Server.Implementations.Sorting;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using Xunit;

namespace Jellyfin.Server.Implementations.Tests.Sorting
{
    public class PremiereDateComparerTests
    {
        private readonly PremiereDateComparer _cmp = new PremiereDateComparer();

        [Theory]
        [ClassData(typeof(PremiereDateTestData))]
        public void PremiereDateCompareTest(BaseItem x, BaseItem y, int expected)
        {
            Assert.Equal(expected, _cmp.Compare(x, y));
            Assert.Equal(-expected, _cmp.Compare(y, x));
        }

        private sealed class PremiereDateTestData : TheoryData<BaseItem, BaseItem, int>
        {
            public PremiereDateTestData()
            {
                // Happy case - Both have premier date
                // Expected: x listed first
                Add(
                    new Movie { PremiereDate = new DateTime(2018, 1, 1) },
                    new Movie { PremiereDate = new DateTime(2018, 1, 3) },
                    -1);

                // Both have premiere date, but y has invalid date
                // Expected: y listed first
                Add(
                    new Movie { PremiereDate = new DateTime(2019, 1, 1) },
                    new Movie { PremiereDate = new DateTime(03, 1, 1) },
                    1);

                // Only x has premiere date, with earlier year than y
                // Expected: x listed first
                Add(
                    new Movie { PremiereDate = new DateTime(2020, 1, 1) },
                    new Movie { ProductionYear = 2021 },
                    -1);

                // Only x has premiere date, with same year as y
                // Expected: y listed first
                Add(
                    new Movie { PremiereDate = new DateTime(2022, 1, 2) },
                    new Movie { ProductionYear = 2022 },
                    1);

                // Only x has a premiere date, with later year than y
                // Expected: y listed first
                Add(
                    new Movie { PremiereDate = new DateTime(2024, 3, 1) },
                    new Movie { ProductionYear = 2023 },
                    1);

                // Only x has a premiere date, y has an invalid year
                // Expected: y listed first
                Add(
                    new Movie { PremiereDate = new DateTime(2025, 1, 1) },
                    new Movie { ProductionYear = 0 },
                    1);

                // Only x has a premiere date, y has neither date nor year
                // Expected: y listed first
                Add(
                    new Movie { PremiereDate = new DateTime(2026, 1, 1) },
                    new Movie(),
                    1);
            }
        }
    }
}