< Summary

Class:UserProfileFetcher
Assembly:UserProfile
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/Helpers/UserProfileFetcher.cs
Covered lines:11
Uncovered lines:9
Coverable lines:20
Total lines:56
Line coverage:55% (11 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UserProfileFetcher()0%110100%
FetchProfile(...)0%3.073080%
Dispose()0%110100%
OnProfileAddedToCatalog(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/Helpers/UserProfileFetcher.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4using DCL.Interface;
 5
 6public class UserProfileFetcher : IDisposable
 7{
 128    private readonly Dictionary<string, List<Promise<UserProfile>>> pendingPromises = new Dictionary<string, List<Promis
 9
 10    /// <summary>
 11    /// Look for profile in userProfilesCatalog or request kernel for a profile if not available
 12    /// </summary>
 13    /// <param name="userId">id of profile to fetch</param>
 14    /// <returns>a promise of the user profile</returns>
 15    public Promise<UserProfile> FetchProfile(string userId)
 16    {
 2217        Promise<UserProfile> promise = new Promise<UserProfile>();
 2218        if (UserProfileController.userProfilesCatalog.TryGetValue(userId, out UserProfile profile))
 19        {
 020            promise.Resolve(profile);
 021            return promise;
 22        }
 23
 2224        if (!pendingPromises.TryGetValue(userId, out List<Promise<UserProfile>> promisesForUserId))
 25        {
 1626            promisesForUserId = new List<Promise<UserProfile>>();
 1627            pendingPromises.Add(userId, promisesForUserId);
 1628            WebInterface.RequestUserProfile(userId);
 29        }
 30
 2231        promisesForUserId.Add(promise);
 2232        return promise;
 33    }
 34
 3635    public UserProfileFetcher() { UserProfileController.userProfilesCatalog.OnAdded += OnProfileAddedToCatalog; }
 36
 2437    public void Dispose() { UserProfileController.userProfilesCatalog.OnAdded -= OnProfileAddedToCatalog; }
 38
 39    private void OnProfileAddedToCatalog(string userId, UserProfile profile)
 40    {
 041        if (!pendingPromises.TryGetValue(userId, out List<Promise<UserProfile>> promisesForUserId))
 42        {
 043            return;
 44        }
 45
 046        for (int i = 0; i < promisesForUserId.Count; i++)
 47        {
 048            if (promisesForUserId[i] == null)
 49                continue;
 50
 051            promisesForUserId[i].Resolve(profile);
 52        }
 53
 054        pendingPromises.Remove(userId);
 055    }
 56}