< Summary

Class:HotScenesControllerTests
Assembly:HotScenesControllerTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HotScenesController/Tests/HotScenesControllerTests.cs
Covered lines:28
Uncovered lines:0
Coverable lines:28
Total lines:121
Line coverage:100% (28 of 28)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HotScenesControllerShouldParseJsonCorrectly()0%330100%
GetTestHotSceneList()0%110100%
CheckListEquals(...)0%440100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HotScenesController/Tests/HotScenesControllerTests.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using NUnit.Framework;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7
 8public class HotScenesControllerTests : IntegrationTestSuite_Legacy
 9{
 10    [UnityTest]
 11    public IEnumerator HotScenesControllerShouldParseJsonCorrectly()
 12    {
 113        var controller = HotScenesController.i;
 14
 115        var hotSceneList = GetTestHotSceneList();
 16
 117        var payload = new HotScenesController.HotScenesUpdatePayload
 18        {
 19            chunkIndex = 0,
 20            chunksCount = 1,
 21            scenesInfo = hotSceneList.ToArray()
 22        };
 23
 124        Action onListUpdate = () =>
 25        {
 126            CheckListEquals(controller.hotScenesList, hotSceneList);
 127        };
 128        controller.OnHotSceneListChunkUpdated += onListUpdate;
 29
 130        controller.UpdateHotScenesList(JsonUtility.ToJson(payload));
 31
 132        controller.OnHotSceneListChunkUpdated -= onListUpdate;
 33
 134        CheckListEquals(controller.hotScenesList, hotSceneList);
 35
 136        yield return null;
 137    }
 38
 39    List<HotScenesController.HotSceneInfo> GetTestHotSceneList()
 40    {
 141        var hotSceneList = new List<HotScenesController.HotSceneInfo>();
 142        hotSceneList.Add(new HotScenesController.HotSceneInfo()
 43        {
 44            baseCoords = new Vector2Int(0, 0),
 45            realms = new HotScenesController.HotSceneInfo.Realm[]
 46            {
 47                new HotScenesController.HotSceneInfo.Realm()
 48                {
 49                    layer = "amber",
 50                    serverName = "fenrir",
 51                    usersCount = 10,
 52                    usersMax = 50
 53                },
 54                new HotScenesController.HotSceneInfo.Realm()
 55                {
 56                    layer = "blue",
 57                    serverName = "unicorn",
 58                    usersCount = 2,
 59                    usersMax = 50
 60                }
 61            },
 62            usersTotalCount = 12
 63        });
 64
 165        hotSceneList.Add(new HotScenesController.HotSceneInfo()
 66        {
 67            baseCoords = new Vector2Int(20, 20),
 68            realms = new HotScenesController.HotSceneInfo.Realm[]
 69            {
 70                new HotScenesController.HotSceneInfo.Realm()
 71                {
 72                    layer = "amber",
 73                    serverName = "fenrir",
 74                    usersCount = 1,
 75                    usersMax = 50
 76                }
 77            },
 78            usersTotalCount = 1
 79        });
 80
 181        hotSceneList.Add(new HotScenesController.HotSceneInfo()
 82        {
 83            baseCoords = new Vector2Int(70, -135),
 84            realms = new HotScenesController.HotSceneInfo.Realm[]
 85            {
 86                new HotScenesController.HotSceneInfo.Realm()
 87                {
 88                    layer = "red",
 89                    serverName = "temptation",
 90                    usersCount = 100,
 91                    usersMax = 50
 92                }
 93            },
 94            usersTotalCount = 100
 95        });
 96
 197        return hotSceneList;
 98    }
 99    void CheckListEquals(List<HotScenesController.HotSceneInfo> l1, List<HotScenesController.HotSceneInfo> l2)
 100    {
 2101        Assert.IsTrue(l1.Count == l2.Count, "HotScenesLists length mismatch");
 102
 16103        for (int i = 0; i < l1.Count; i++)
 104        {
 6105            Assert.IsTrue(l1[i].baseCoords.x == l2[i].baseCoords.x && l1[i].baseCoords.y == l2[i].baseCoords.y,
 106                $"HotScenesLists baseCoords mismatch at index {i}");
 107
 6108            Assert.IsTrue(l1[i].usersTotalCount == l2[i].usersTotalCount, $"HotScenesLists usersTotalCount mismatch at i
 109
 6110            Assert.IsTrue(l1[i].realms.Length == l2[i].realms.Length, $"HotScenesLists realms length mismatch at index {
 111
 28112            for (int j = 0; j < l1[i].realms.Length; j++)
 113            {
 8114                Assert.IsTrue(l1[i].realms[j].serverName == l2[i].realms[j].serverName, $"HotScenesLists realms serverNa
 8115                Assert.IsTrue(l1[i].realms[j].layer == l2[i].realms[j].layer, $"HotScenesLists realms layer mismatch at 
 8116                Assert.IsTrue(l1[i].realms[j].usersCount == l2[i].realms[j].usersCount, $"HotScenesLists realms usersCou
 8117                Assert.IsTrue(l1[i].realms[j].usersMax == l2[i].realms[j].usersMax, $"HotScenesLists realms usersMax mis
 118            }
 119        }
 2120    }
 121}