< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Sorting.DateLastMediaAddedComparer
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Sorting/DateLastMediaAddedComparer.cs
Line coverage
16%
Covered lines: 1
Uncovered lines: 5
Coverable lines: 6
Total lines: 69
Line coverage: 16.6%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%11100%
Compare(...)100%210%
GetDate(...)0%2040%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Sorting/DateLastMediaAddedComparer.cs

#LineLine coverage
 1#nullable disable
 2#pragma warning disable CS1591
 3
 4using System;
 5using Jellyfin.Data.Entities;
 6using Jellyfin.Data.Enums;
 7using MediaBrowser.Controller.Entities;
 8using MediaBrowser.Controller.Library;
 9using MediaBrowser.Controller.Sorting;
 10using MediaBrowser.Model.Querying;
 11
 12namespace Emby.Server.Implementations.Sorting
 13{
 14    public class DateLastMediaAddedComparer : IUserBaseItemComparer
 15    {
 16        /// <summary>
 17        /// Gets or sets the user.
 18        /// </summary>
 19        /// <value>The user.</value>
 20        public User User { get; set; }
 21
 22        /// <summary>
 23        /// Gets or sets the user manager.
 24        /// </summary>
 25        /// <value>The user manager.</value>
 26        public IUserManager UserManager { get; set; }
 27
 28        /// <summary>
 29        /// Gets or sets the user data repository.
 30        /// </summary>
 31        /// <value>The user data repository.</value>
 32        public IUserDataManager UserDataRepository { get; set; }
 33
 34        /// <summary>
 35        /// Gets the name.
 36        /// </summary>
 37        /// <value>The name.</value>
 138        public ItemSortBy Type => ItemSortBy.DateLastContentAdded;
 39
 40        /// <summary>
 41        /// Compares the specified x.
 42        /// </summary>
 43        /// <param name="x">The x.</param>
 44        /// <param name="y">The y.</param>
 45        /// <returns>System.Int32.</returns>
 46        public int Compare(BaseItem x, BaseItem y)
 47        {
 048            return GetDate(x).CompareTo(GetDate(y));
 49        }
 50
 51        /// <summary>
 52        /// Gets the date.
 53        /// </summary>
 54        /// <param name="x">The x.</param>
 55        /// <returns>DateTime.</returns>
 56        private static DateTime GetDate(BaseItem x)
 57        {
 058            if (x is Folder folder)
 59            {
 060                if (folder.DateLastMediaAdded.HasValue)
 61                {
 062                    return folder.DateLastMediaAdded.Value;
 63                }
 64            }
 65
 066            return DateTime.MinValue;
 67        }
 68    }
 69}