From 9fd50317dd1eea4f59764ad00aec2594c9bb48c7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 6 Feb 2022 20:50:43 -0600 Subject: initial tests for UserService --- src/slskd/Users/UserService.cs | 60 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs index a54005f1..6a42d3d2 100644 --- a/src/slskd/Users/UserService.cs +++ b/src/slskd/Users/UserService.cs @@ -58,38 +58,16 @@ namespace slskd.Users private ISoulseekClient Client { get; } private IDbContextFactory ContextFactory { get; } - private IOptionsMonitor OptionsMonitor { get; } private string LastOptionsHash { get; set; } private ILogger Log { get; set; } = Serilog.Log.ForContext(); private ConcurrentDictionary Map { get; set; } = new ConcurrentDictionary(); + private IOptionsMonitor OptionsMonitor { get; } - private void Configure(Options options) - { - var optionsHash = Compute.Sha1Hash(options.Groups.UserDefined.ToJson()); - - if (optionsHash == LastOptionsHash) - { - return; - } - - var map = new ConcurrentDictionary(); - - // sort by priority, ascending - foreach (var group in options.Groups.UserDefined.OrderBy(kvp => kvp.Value.Upload.Priority)) - { - foreach (var user in group.Value.Members) - { - // if the key already exists, leave the existing entry. - // if a user appears in more than one group, the higher priority (lower numbered) - // group is their effective group. - map.TryAdd(user, group.Key); - } - } - - Map = map; - LastOptionsHash = optionsHash; - } - + /// + /// Gets the name of the group for the specified . + /// + /// The username of the peer. + /// The group for the specified username. public string GetGroup(string username) { return Map.GetValueOrDefault(username, Application.DefaultGroup); @@ -178,5 +156,31 @@ namespace slskd.Users { await Client.AddUserAsync(username); } + + private void Configure(Options options) + { + var optionsHash = Compute.Sha1Hash(options.Groups.UserDefined.ToJson()); + + if (optionsHash == LastOptionsHash) + { + return; + } + + var map = new ConcurrentDictionary(); + + // sort by priority, ascending + foreach (var group in options.Groups.UserDefined.OrderBy(kvp => kvp.Value.Upload.Priority)) + { + foreach (var user in group.Value.Members) + { + // if the key already exists, leave the existing entry. if a user appears in more than one group, the higher + // priority (lower numbered) group is their effective group. + map.TryAdd(user, group.Key); + } + } + + Map = map; + LastOptionsHash = optionsHash; + } } } \ No newline at end of file -- cgit v1.2.3