< Summary

Class:ChatController
Assembly:ChatController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/ChatController.cs
Covered lines:1
Uncovered lines:22
Coverable lines:23
Total lines:83
Line coverage:4.3% (1 of 23)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
ChatController()0%2100%
AddMessageToChatWindow(...)0%12300%
GetEntries()0%2100%
FakePrivateMessage()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/ChatController.cs

#LineLine coverage
 1using DCL.Interface;
 2using System;
 3using System.Collections.Generic;
 4using UnityEngine;
 5
 6public interface IChatController
 7{
 8    double initTime { get; }
 9    event Action<ChatMessage> OnAddMessage;
 10    List<ChatMessage> GetEntries();
 11
 12    void AddMessageToChatWindow(string jsonMessage);
 13}
 14
 15public class ChatController : MonoBehaviour, IChatController
 16{
 2217    public static ChatController i { get; private set; }
 018    public double initTime { get; private set; }
 19
 20    public void Awake()
 21    {
 022        i = this;
 023        initTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() / 1000.0;
 024    }
 25
 026    [NonSerialized] public List<ChatMessage> entries = new List<ChatMessage>();
 27
 28    public event Action<ChatMessage> OnAddMessage;
 29
 30    public void AddMessageToChatWindow(string jsonMessage)
 31    {
 032        ChatMessage message = JsonUtility.FromJson<ChatMessage>(jsonMessage);
 33
 034        if (message == null)
 035            return;
 36
 037        entries.Add(message);
 038        OnAddMessage?.Invoke(message);
 039    }
 40
 041    public List<ChatMessage> GetEntries() { return new List<ChatMessage>(entries); }
 42
 43    [ContextMenu("Fake Private Message")]
 44    public void FakePrivateMessage()
 45    {
 046        UserProfile ownProfile = UserProfile.GetOwnUserProfile();
 47
 048        var model = new UserProfileModel()
 49        {
 50            userId = "test user 1",
 51            name = "test user 1",
 52        };
 53
 054        UserProfileController.i.AddUserProfileToCatalog(model);
 55
 056        var model2 = new UserProfileModel()
 57        {
 58            userId = "test user 2",
 59            name = "test user 2",
 60        };
 61
 062        UserProfileController.i.AddUserProfileToCatalog(model2);
 63
 064        var msg = new ChatMessage()
 65        {
 66            body = "test message",
 67            sender = model.userId,
 68            recipient = ownProfile.userId,
 69            messageType = ChatMessage.Type.PRIVATE
 70        };
 71
 072        var msg2 = new ChatMessage()
 73        {
 74            body = "test message 2",
 75            recipient = model2.userId,
 76            sender = ownProfile.userId,
 77            messageType = ChatMessage.Type.PRIVATE
 78        };
 79
 080        AddMessageToChatWindow(JsonUtility.ToJson(msg));
 081        AddMessageToChatWindow(JsonUtility.ToJson(msg2));
 082    }
 83}