< Summary

Class:UserProfileController
Assembly:UserProfile
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfileController.cs
Covered lines:15
Uncovered lines:34
Coverable lines:49
Total lines:112
Line coverage:30.6% (15 of 49)
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%440100%
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{
 5727    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        {
 12918            if (userProfilesCatalogValue == null)
 19            {
 120                userProfilesCatalogValue = Resources.Load<UserProfileDictionary>("UserProfilesCatalog");
 21            }
 22
 12923            return userProfilesCatalogValue;
 24        }
 25    }
 26
 27    [NonSerialized] public UserProfile ownUserProfile;
 28
 29    public void Awake()
 30    {
 1631        i = this;
 1632        ownUserProfile = UserProfile.GetOwnUserProfile();
 1633    }
 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        var usersPayload = JsonUtility.FromJson<AddUserProfilesToCatalogPayload>(payload);
 061        var users = usersPayload.users;
 062        var count = users.Length;
 63
 064        for (var i = 0; i < count; ++i)
 065            AddUserProfileToCatalog(users[i]);
 066    }
 67
 68    public void AddUserProfileToCatalog(UserProfileModel model)
 69    {
 1970        model.userId = model.userId.ToLower();
 1971        model.ethAddress = model.ethAddress?.ToLower();
 72
 1973        if (!userProfilesCatalog.TryGetValue(model.userId, out UserProfile userProfile))
 574            userProfile = ScriptableObject.CreateInstance<UserProfile>();
 75
 1976        userProfile.UpdateData(model);
 1977        userProfilesCatalog.Add(model.userId, userProfile);
 1978    }
 79
 80    public static UserProfile GetProfileByName(string targetUserName)
 81    {
 082        foreach (var userProfile in userProfilesCatalogValue)
 83        {
 084            if (userProfile.Value.userName.ToLower() == targetUserName.ToLower())
 085                return userProfile.Value;
 86        }
 87
 088        return null;
 089    }
 90
 491    public static UserProfile GetProfileByUserId(string targetUserId) { return userProfilesCatalog.Get(targetUserId); }
 92
 93    public void RemoveUserProfilesFromCatalog(string payload)
 94    {
 095        string[] usernames = JsonUtility.FromJson<string[]>(payload);
 096        for (int index = 0; index < usernames.Length; index++)
 97        {
 098            RemoveUserProfileFromCatalog(userProfilesCatalog.Get(usernames[index]));
 99        }
 0100    }
 101
 102    public void RemoveUserProfileFromCatalog(UserProfile userProfile)
 103    {
 0104        if (userProfile == null)
 0105            return;
 106
 0107        userProfilesCatalog.Remove(userProfile.userId);
 0108        Destroy(userProfile);
 0109    }
 110
 0111    public void ClearProfilesCatalog() { userProfilesCatalog?.Clear(); }
 112}