< Summary

Class:Tests.WSSTests
Assembly:WSSTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/WSS/Tests/WSSTests.cs
Covered lines:0
Uncovered lines:43
Coverable lines:43
Total lines:113
Line coverage:0% (0 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%6200%
BasicConnectionTest()0%72800%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/WSS/Tests/WSSTests.cs

#LineLine coverage
 1using DCL;
 2using NUnit.Framework;
 3using System;
 4using System.Collections;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7using WebSocketSharp;
 8using Environment = DCL.Environment;
 9
 10namespace Tests
 11{
 12    [Explicit]
 13    public class WSSTests : IntegrationTestSuite
 14    {
 15        protected override IEnumerator SetUp()
 16        {
 017            Environment.SetupWithBuilders
 18            (
 19                MessagingContextFactory.CreateDefault,
 20                PlatformContextFactory.CreateDefault,
 21                WorldRuntimeContextFactory.CreateDefault,
 22                HUDContextFactory.CreateDefault
 23            );
 024            yield break;
 25        }
 26
 27        [UnityTest]
 28        public IEnumerator BasicConnectionTest()
 29        {
 030            GameObject wssControllerGO = new GameObject("WSS Controller");
 31
 032            WSSController wssController = wssControllerGO.AddComponent<WSSController>();
 033            DCLCharacterController.i.gravity = 0;
 34
 035            yield return new WaitForSeconds(1.0f);
 36
 037            Assert.IsTrue(wssController.isServerReady);
 38
 039            using (WebSocket ws = new WebSocket("ws://localhost:5000/dcl"))
 40            {
 41                try
 42                {
 043                    ws.Connect();
 044                }
 045                catch (Exception e)
 46                {
 047                    Debug.LogError("message: " + e.ToString());
 048                    Assert.Fail("Failed to connect to decentraland service!");
 049                }
 50
 051                string payloadTest = (Resources.Load("TestJSON/SceneLoadingTest") as TextAsset).text;
 52
 053                DCLWebSocketService.Message message = new DCLWebSocketService.Message()
 54                {
 55                    type = "LoadParcelScenes",
 56                    payload = payloadTest
 57                };
 58
 059                string json = "";
 60                try
 61                {
 062                    json = JsonUtility.ToJson(message);
 063                }
 64                catch (Exception e)
 65                {
 066                    Debug.LogError(e.ToString());
 067                    Assert.Fail("Invalid object?: " + json);
 068                }
 69
 070                ws.Send(json);
 071                Debug.Log("<color=#007F00><b>WSSTests</b></color> >>> Waiting for server response...");
 72
 073                string lastMessage = "";
 74
 075                ws.OnMessage += (sender, e) =>
 76                {
 077                    Debug.Log("<color=#007F00><b>WSSTests</b></color> >>> Server sent: " + e.Data);
 078                    lastMessage = e.Data;
 079                };
 80
 081                float time = 0;
 082                while (time < 8.0f)
 83                {
 084                    time += Time.unscaledDeltaTime;
 85
 086                    if (lastMessage.Contains("OK!"))
 87                    {
 88                        break;
 89                    }
 90
 091                    yield return null;
 92                }
 93
 094                Assert.LessOrEqual(Mathf.FloorToInt(time), 8);
 95
 096                string loadedSceneID = "0,0";
 97
 098                yield return null;
 99
 0100                Assert.IsTrue(DCL.Environment.i.world.state.loadedScenes.ContainsKey(loadedSceneID),
 101                    "Expected loadedScene not found!");
 0102                Assert.IsTrue(DCL.Environment.i.world.state.loadedScenes[loadedSceneID] != null,
 103                    "Expected loadedScene found but was null!!!");
 0104            }
 105
 106
 0107            UnityEngine.Object.Destroy(wssControllerGO);
 108            // Use the Assert class to test conditions.
 109            // Use yield to skip a frame.
 0110            yield return null;
 0111        }
 112    }
 113}

Methods/Properties

SetUp()
BasicConnectionTest()