< Summary

Class:IntegrationTestController
Assembly:IntegrationTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Tests/IntegrationTests/IntegrationTestController.cs
Covered lines:0
Uncovered lines:45
Coverable lines:45
Total lines:163
Line coverage:0% (0 of 45)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
IntegrationTestController()0%2100%
Initialize()0%20400%
Verify()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Tests/IntegrationTests/IntegrationTestController.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Configuration;
 4using DCL.Helpers;
 5using DCL.Models;
 6using Newtonsoft.Json;
 7using System.Collections;
 8using DCL.Controllers;
 9using UnityEngine;
 10using UnityEngine.Assertions;
 11
 12public class IntegrationTestController : MonoBehaviour
 13{
 014    string entityId = "a5f571bd-bce1-4cf8-a158-b8f3e92e4fb0";
 015    string sceneName = "the-loaded-scene";
 16
 17    public IEnumerator Initialize()
 18    {
 019        var sceneController = Environment.i.world.sceneController;
 020        DCLCharacterController.i.gravity = 0;
 021        DCLCharacterController.i.Teleport(JsonConvert.SerializeObject(new
 22        {
 23            x = 0f,
 24            y = 0f,
 25            z = 0f
 26        }));
 27
 028        var scenesToLoad = new LoadParcelScenesMessage.UnityParcelScene()
 29        {
 30            id = sceneName,
 31            basePosition = new Vector2Int(3, 3),
 32            parcels = new[]
 33            {
 34                new Vector2Int(3, 3),
 35                new Vector2Int(3, 4)
 36            },
 37            baseUrl = "http://localhost:9991/local-ipfs/contents/"
 38        };
 39
 040        Assert.IsTrue(sceneController != null, "Cannot find SceneController");
 41
 042        sceneController.UnloadAllScenes();
 043        sceneController.LoadParcelScenes(JsonConvert.SerializeObject(scenesToLoad));
 44
 045        yield return new WaitForAllMessagesProcessed();
 46
 047        ParcelScene scene = Environment.i.world.state.GetScene(sceneName) as ParcelScene;
 48
 49        //NOTE(Brian): This is making my eyes bleed.
 050        sceneController.SendSceneMessage(
 51            TestHelpers.CreateSceneMessage(
 52                sceneName,
 53                entityId,
 54                "CreateEntity",
 55                JsonConvert.SerializeObject(
 56                    new Protocol.CreateEntity()
 57                    {
 58                        entityId = entityId
 59                    }))
 60        );
 61
 62        //NOTE(Brian): This is making my eyes bleed. (Zak): Twice
 063        sceneController.SendSceneMessage(
 64            TestHelpers.CreateSceneMessage(
 65                sceneName,
 66                entityId,
 67                "SetEntityParent",
 68                JsonConvert.SerializeObject(
 69                    new
 70                    {
 71                        entityId = entityId,
 72                        parentId = "0"
 73                    })
 74            )
 75        );
 76
 077        yield return new WaitForAllMessagesProcessed();
 78
 079        Assert.IsTrue(scene.entities[entityId].meshRootGameObject == null, "meshGameObject must be null");
 80
 81        // 1st message
 082        TestHelpers.CreateAndSetShape(scene as ParcelScene, entityId, CLASS_ID.BOX_SHAPE, "{}");
 83
 84        {
 085            scene.EntityComponentCreateOrUpdate(
 86                entityId,
 87                CLASS_ID_COMPONENT.TRANSFORM,
 88                "{\"tag\":\"transform\",\"position\":{\"x\":0,\"y\":0,\"z\":0},\"rotation\":{\"x\":0,\"y\":0,\"z\":0,\"w
 89            );
 90        }
 91
 92
 93        // 2nd message
 094        TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}");
 95        {
 096            scene.EntityComponentCreateOrUpdate(
 97                entityId,
 98                CLASS_ID_COMPONENT.TRANSFORM,
 99                "{\"tag\":\"transform\",\"position\":{\"x\":6,\"y\":0,\"z\":5},\"rotation\":{\"x\":0,\"y\":0.39134957508
 100            );
 101        }
 102
 0103        TestHelpers.InstantiateEntityWithTextShape(scene, new Vector3(10, 10, 10),
 104            new TextShape.Model() { value = "Hello World!!!" });
 0105    }
 106
 107    public IEnumerator Verify()
 108    {
 0109        var scene = Environment.i.world.state.GetScene(sceneName) as ParcelScene;
 0110        var cube = scene.entities[entityId];
 111
 0112        Assert.IsTrue(cube != null);
 0113        Vector3 cubePosition = new Vector3(6, 0, 5);
 0114        Assert.AreEqual(cube.gameObject.transform.localPosition, cubePosition);
 115
 116        // because basePosition is at 3,3
 0117        Assert.AreEqual(cube.gameObject.transform.position,
 118            new Vector3(3 * ParcelSettings.PARCEL_SIZE + cubePosition.x, cubePosition.y,
 119                3 * ParcelSettings.PARCEL_SIZE + cubePosition.z));
 0120        Assert.IsTrue(cube.meshRootGameObject != null);
 0121        Assert.IsTrue(cube.meshRootGameObject.GetComponentInChildren<MeshFilter>() != null);
 122
 0123        var mesh = cube.meshRootGameObject.GetComponentInChildren<MeshFilter>().mesh;
 124
 0125        Assert.AreEqual(mesh.name, "DCL Box Instance");
 126
 127        {
 128            // 3nd message, the box should remain the same, including references
 0129            TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}");
 130
 0131            var newMesh = cube.meshRootGameObject.GetComponentInChildren<MeshFilter>().mesh;
 132
 0133            Assert.AreEqual(newMesh.name, "DCL Box Instance");
 0134            Assert.AreEqual(mesh.name, newMesh.name, "A new instance of the box was created");
 135        }
 136
 137        {
 138            // 3nd message, the box should remain the same, including references
 0139            TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}");
 140
 0141            var newMesh = cube.meshRootGameObject.GetComponentInChildren<MeshFilter>().mesh;
 142
 0143            Assert.AreEqual(newMesh.name, "DCL Box Instance");
 0144            Assert.AreEqual(mesh.name, newMesh.name, "A new instance of the box was created");
 145        }
 146
 147        {
 148            // 4nd message, the box should be disposed and the new mesh should be a sphere
 0149            TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.SPHERE_SHAPE,
 150                "{\"withCollisions\":false,\"billboard\":0,\"visible\":true,\"tag\":\"sphere\"}");
 151
 0152            var newMesh = cube.meshRootGameObject.GetComponentInChildren<MeshFilter>().mesh;
 153
 0154            Assert.AreEqual(newMesh.name, "DCL Sphere Instance");
 0155            Assert.AreNotEqual(mesh.name, newMesh.name,
 156                "The mesh instance remains the same, a new instance should have been created.");
 157        }
 158
 159        // TODO: test ComponentRemoved
 160
 0161        yield return null;
 0162    }
 163}