< Summary

Class:DCL.Social.Chat.PoolPrivateChatEntryFactory
Assembly:PrivateChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PoolPrivateChatEntryFactory.cs
Covered lines:1
Uncovered lines:17
Coverable lines:18
Total lines:57
Line coverage:5.5% (1 of 18)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:5
Method coverage:20% (1 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PoolPrivateChatEntryFactory()0%110100%
CreateDateSeparator()0%2100%
Create(...)0%2100%
Destroy(...)0%6200%
GetPool()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PoolPrivateChatEntryFactory.cs

#LineLine coverage
 1using DCL.Social.Chat;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5namespace DCL.Social.Chat
 6{
 7    [CreateAssetMenu(fileName = "PoolPrivateChatEntryFactory", menuName = "DCL/Social/PoolPrivateChatEntryFactory")]
 8    public class PoolPrivateChatEntryFactory : ScriptableObject, IChatEntryFactory
 9    {
 10        private const string POOL_NAME_PREFIX = "ChatDateSeparators_";
 11        private const int PRE_INSTANTIATED_ENTRIES = 30;
 12
 13        [SerializeField] private PoolChatEntryFactory factory;
 14        [SerializeField] private DateSeparatorEntry separatorEntryPrefab;
 15
 116        private readonly Dictionary<ChatEntry, PoolableObject> pooledObjects =
 17            new Dictionary<ChatEntry, PoolableObject>();
 18
 19        public DateSeparatorEntry CreateDateSeparator()
 20        {
 021            var pool = GetPool();
 022            var pooledObj = pool.Get();
 023            var entry = pooledObj.gameObject.GetComponent<DateSeparatorEntry>();
 024            pooledObjects[entry] = pooledObj;
 025            return entry;
 26        }
 27
 028        public ChatEntry Create(ChatEntryModel model) => factory.Create(model);
 29
 30        public void Destroy(ChatEntry entry)
 31        {
 032            if (pooledObjects.TryGetValue(entry, out var pooledObj))
 33            {
 034                pooledObj.Release();
 035                pooledObjects.Remove(entry);
 36            }
 37
 038            factory.Destroy(entry);
 039        }
 40
 41        private Pool GetPool()
 42        {
 043            var poolId = POOL_NAME_PREFIX + GetInstanceID();
 044            var entryPool = PoolManager.i.GetPool(poolId);
 045            if (entryPool != null) return entryPool;
 46
 047            entryPool = PoolManager.i.AddPool(
 48                poolId,
 49                Instantiate(separatorEntryPrefab).gameObject,
 50                maxPrewarmCount: PRE_INSTANTIATED_ENTRIES,
 51                isPersistent: true);
 052            entryPool.ForcePrewarm();
 53
 054            return entryPool;
 55        }
 56    }
 57}