using System; using System.Collections.Generic; using System.Threading.Tasks; using Jellyfin.Database.Implementations.Entities; using MediaBrowser.Controller.Library; using Moq; namespace Jellyfin.Plugin.WatchedTogether.Tests; /// /// Sets up the members whose signatures differ between Jellyfin 10.11 /// and 12, so the suites read the same whichever generation they are compiled against. /// internal static class UserManagerMockExtensions { /// /// Routes ChangePassword to with the user the real server /// would act on: the instance handed in on 10.11, the stored row looked up by id on 12. /// /// The user manager mock. /// The users the mock knows about, used to resolve ids on 12. /// The behaviour to run for the change. public static void SetupChangePassword( this Mock mock, List users, Func onChange) { #if JELLYFIN_12 mock.Setup(m => m.ChangePassword(It.IsAny(), It.IsAny())) .Returns((Guid id, string password) => { var user = users.Find(u => u.Id == id) ?? throw new KeyNotFoundException($"No user with id {id}"); return onChange(user, password); }); #else mock.Setup(m => m.ChangePassword(It.IsAny(), It.IsAny())) .Returns((User user, string password) => onChange(user, password)); #endif } }