< Summary

Class:UsersSearcher
Assembly:UsersSearcher
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/UsersSearcher/UsersSearcher.cs
Covered lines:18
Uncovered lines:0
Coverable lines:18
Total lines:55
Line coverage:100% (18 of 18)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SearchUser(...)0%220100%
UsersSearcher()0%110100%
UsersSearcher(...)0%220100%
Dispose()0%330100%
OnSearchResult(...)0%330100%

File(s)

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

#LineLine coverage
 1using System;
 2using DCL.Helpers;
 3using DCL.Interface;
 4
 5/// <summary>
 6/// Query profiles by name or address
 7/// ENS query (by name) use a partial match checking if any ENS contains the input string.
 8/// </summary>
 9public class UsersSearcher : IDisposable
 10{
 11    private readonly IUsersSearchBridge bridge;
 12
 13    private Promise<UserProfileModel[]> searchPrommise;
 14    private string currentSearchInput;
 15
 16    /// <summary>
 17    /// Query profiles of users who their owned names contains string "name"
 18    /// If "name" is an address it will return the profile for that address
 19    /// </summary>
 20    /// <param name="name">name or address</param>
 21    /// <param name="maxResults">max results for the query</param>
 22    /// <returns>Profiles or null (if no profile found) promise</returns>
 23    public Promise<UserProfileModel[]> SearchUser(string name, int maxResults)
 24    {
 625        searchPrommise?.Dispose();
 626        searchPrommise = new Promise<UserProfileModel[]>();
 627        currentSearchInput = name;
 628        WebInterface.SearchENSOwner(name, maxResults);
 629        return searchPrommise;
 30    }
 31
 1832    public UsersSearcher() : this(UsersSearchBridge.i) { }
 33
 1234    public UsersSearcher(IUsersSearchBridge bridge)
 35    {
 1236        this.bridge = bridge;
 1237        if (bridge != null)
 1238            bridge.OnSearchResult += OnSearchResult;
 1239    }
 40
 41    public void Dispose()
 42    {
 343        if (bridge != null)
 344            bridge.OnSearchResult -= OnSearchResult;
 345        searchPrommise?.Dispose();
 346    }
 47
 48    private void OnSearchResult(string searchInput, UserProfileModel[] profiles)
 49    {
 550        if (searchInput == currentSearchInput)
 51        {
 352            searchPrommise?.Resolve(profiles);
 53        }
 554    }
 55}