< Summary

Class:UserProfileController
Assembly:UserProfile
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfileController.cs
Covered lines:13
Uncovered lines:33
Coverable lines:46
Total lines:109
Line coverage:28.2% (13 of 46)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
LoadProfile(...)0%12300%
AddUserProfileToCatalog(...)0%2100%
AddUserProfilesToCatalog(...)0%6200%
AddUserProfileToCatalog(...)0%220100%
GetProfileByName(...)0%12300%
GetProfileByUserId(...)0%110100%
RemoveUserProfilesFromCatalog(...)0%6200%
RemoveUserProfileFromCatalog(...)0%6200%
ClearProfilesCatalog()0%6200%

File(s)

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

#LineLine coverage
 1using System;
 2using DCL;
 3using UnityEngine;
 4
 5public class UserProfileController : MonoBehaviour
 6{
 5687    public static UserProfileController i { get; private set; }
 8
 9    public event Action OnBaseWereablesFail;
 10
 11    private static UserProfileDictionary userProfilesCatalogValue;
 12    private bool baseWearablesAlreadyRequested = false;
 13
 14    public static UserProfileDictionary userProfilesCatalog
 15    {
 16        get
 17        {
 12518            if (userProfilesCatalogValue == null)
 19            {
 120                userProfilesCatalogValue = Resources.Load<UserProfileDictionary>("UserProfilesCatalog");
 21            }
 22
 12523            return userProfilesCatalogValue;
 24        }
 25    }
 26
 27    [NonSerialized] public UserProfile ownUserProfile;
 28
 29    public void Awake()
 30    {
 1431        i = this;
 1432        ownUserProfile = UserProfile.GetOwnUserProfile();
 1433    }
 34
 35    public void LoadProfile(string payload)
 36    {
 037        if (!baseWearablesAlreadyRequested)
 38        {
 039            baseWearablesAlreadyRequested = true;
 040            CatalogController.RequestBaseWearables()
 41                             .Catch((error) =>
 42                             {
 043                                 OnBaseWereablesFail?.Invoke();
 044                                 Debug.LogError(error);
 045                             });
 46        }
 47
 048        if (payload == null)
 049            return;
 50
 051        var model = JsonUtility.FromJson<UserProfileModel>(payload);
 052        ownUserProfile.UpdateData(model);
 053        userProfilesCatalog.Add(model.userId, ownUserProfile);
 054    }
 55
 056    public void AddUserProfileToCatalog(string payload) { AddUserProfileToCatalog(JsonUtility.FromJson<UserProfileModel>
 57
 58    public void AddUserProfilesToCatalog(string payload)
 59    {
 060        UserProfileModel[] items = JsonUtility.FromJson<UserProfileModel[]>(payload);
 061        int count = items.Length;
 062        for (int i = 0; i < count; ++i)
 63        {
 064            AddUserProfileToCatalog(items[i]);
 65        }
 066    }
 67
 68    public void AddUserProfileToCatalog(UserProfileModel model)
 69    {
 1770        if (!userProfilesCatalog.TryGetValue(model.userId, out UserProfile userProfile))
 571            userProfile = ScriptableObject.CreateInstance<UserProfile>();
 72
 1773        userProfile.UpdateData(model);
 1774        userProfilesCatalog.Add(model.userId, userProfile);
 1775    }
 76
 77    public static UserProfile GetProfileByName(string targetUserName)
 78    {
 079        foreach (var userProfile in userProfilesCatalogValue)
 80        {
 081            if (userProfile.Value.userName.ToLower() == targetUserName.ToLower())
 082                return userProfile.Value;
 83        }
 84
 085        return null;
 086    }
 87
 488    public static UserProfile GetProfileByUserId(string targetUserId) { return userProfilesCatalog.Get(targetUserId); }
 89
 90    public void RemoveUserProfilesFromCatalog(string payload)
 91    {
 092        string[] usernames = JsonUtility.FromJson<string[]>(payload);
 093        for (int index = 0; index < usernames.Length; index++)
 94        {
 095            RemoveUserProfileFromCatalog(userProfilesCatalog.Get(usernames[index]));
 96        }
 097    }
 98
 99    public void RemoveUserProfileFromCatalog(UserProfile userProfile)
 100    {
 0101        if (userProfile == null)
 0102            return;
 103
 0104        userProfilesCatalog.Remove(userProfile.userId);
 0105        Destroy(userProfile);
 0106    }
 107
 0108    public void ClearProfilesCatalog() { userProfilesCatalog?.Clear(); }
 109}