| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.TestTools; |
| | 7 | |
|
| | 8 | | public class HotScenesControllerTests : IntegrationTestSuite_Legacy |
| | 9 | | { |
| | 10 | | [UnityTest] |
| | 11 | | public IEnumerator HotScenesControllerShouldParseJsonCorrectly() |
| | 12 | | { |
| 1 | 13 | | var controller = HotScenesController.i; |
| | 14 | |
|
| 1 | 15 | | var hotSceneList = GetTestHotSceneList(); |
| | 16 | |
|
| 1 | 17 | | var payload = new HotScenesController.HotScenesUpdatePayload |
| | 18 | | { |
| | 19 | | chunkIndex = 0, |
| | 20 | | chunksCount = 1, |
| | 21 | | scenesInfo = hotSceneList.ToArray() |
| | 22 | | }; |
| | 23 | |
|
| 1 | 24 | | Action onListUpdate = () => |
| | 25 | | { |
| 1 | 26 | | CheckListEquals(controller.hotScenesList, hotSceneList); |
| 1 | 27 | | }; |
| 1 | 28 | | controller.OnHotSceneListChunkUpdated += onListUpdate; |
| | 29 | |
|
| 1 | 30 | | controller.UpdateHotScenesList(JsonUtility.ToJson(payload)); |
| | 31 | |
|
| 1 | 32 | | controller.OnHotSceneListChunkUpdated -= onListUpdate; |
| | 33 | |
|
| 1 | 34 | | CheckListEquals(controller.hotScenesList, hotSceneList); |
| | 35 | |
|
| 1 | 36 | | yield return null; |
| 1 | 37 | | } |
| | 38 | |
|
| | 39 | | List<HotScenesController.HotSceneInfo> GetTestHotSceneList() |
| | 40 | | { |
| 1 | 41 | | var hotSceneList = new List<HotScenesController.HotSceneInfo>(); |
| 1 | 42 | | 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 | |
|
| 1 | 65 | | 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 | |
|
| 1 | 81 | | 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 | |
|
| 1 | 97 | | return hotSceneList; |
| | 98 | | } |
| | 99 | | void CheckListEquals(List<HotScenesController.HotSceneInfo> l1, List<HotScenesController.HotSceneInfo> l2) |
| | 100 | | { |
| 2 | 101 | | Assert.IsTrue(l1.Count == l2.Count, "HotScenesLists length mismatch"); |
| | 102 | |
|
| 16 | 103 | | for (int i = 0; i < l1.Count; i++) |
| | 104 | | { |
| 6 | 105 | | 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 | |
|
| 6 | 108 | | Assert.IsTrue(l1[i].usersTotalCount == l2[i].usersTotalCount, $"HotScenesLists usersTotalCount mismatch at i |
| | 109 | |
|
| 6 | 110 | | Assert.IsTrue(l1[i].realms.Length == l2[i].realms.Length, $"HotScenesLists realms length mismatch at index { |
| | 111 | |
|
| 28 | 112 | | for (int j = 0; j < l1[i].realms.Length; j++) |
| | 113 | | { |
| 8 | 114 | | Assert.IsTrue(l1[i].realms[j].serverName == l2[i].realms[j].serverName, $"HotScenesLists realms serverNa |
| 8 | 115 | | Assert.IsTrue(l1[i].realms[j].layer == l2[i].realms[j].layer, $"HotScenesLists realms layer mismatch at |
| 8 | 116 | | Assert.IsTrue(l1[i].realms[j].usersCount == l2[i].realms[j].usersCount, $"HotScenesLists realms usersCou |
| 8 | 117 | | Assert.IsTrue(l1[i].realms[j].usersMax == l2[i].realms[j].usersMax, $"HotScenesLists realms usersMax mis |
| | 118 | | } |
| | 119 | | } |
| 2 | 120 | | } |
| | 121 | | } |