< Summary

Class:NFTShapeHQImageHandlerShould
Assembly:NFTShapeTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/Tests/NFTShapeHQImageHandlerShould.cs
Covered lines:49
Uncovered lines:0
Coverable lines:49
Total lines:108
Line coverage:100% (49 of 49)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
TearDown()0%110100%
SetHQImageCorrectly()0%110100%
SetPreviewImageWhenCameraIsBehind()0%110100%
SetPreviewImageWhenCameraLookAway()0%110100%
SetPreviewImageWhenPlayerMovesAway()0%110100%
SetInFrontAndLookingToNFT()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/Tests/NFTShapeHQImageHandlerShould.cs

#LineLine coverage
 1using DCL.Helpers;
 2using NUnit.Framework;
 3using UnityEngine;
 4using NSubstitute;
 5using NFTShape_Internal;
 6
 7// NOTE: NFTShapes meshes are rotated, so forward is actually backwards :S
 8
 9public class NFTShapeHQImageHandlerShould
 10{
 11    private INFTAsset asset;
 12    private GameObject nftGO;
 13    private NFTShapeHQImageHandler imageHandler;
 14    private NFTShapeConfig nftShapeConfig;
 15    private bool isHQAsset;
 16    private Camera camera;
 17
 18    [SetUp]
 19    protected void SetUp()
 20    {
 421        isHQAsset = false;
 422        camera = new GameObject("Camera") { tag = "MainCamera" }.AddComponent<Camera>();
 23
 424        asset = Substitute.For<INFTAsset>();
 825        asset.When(a => a.RestorePreviewAsset())
 26             .Do(i =>
 27             {
 428                 isHQAsset = false;
 429                 asset.isHQ.Returns(false);
 430             });
 831        asset.WhenForAnyArgs(a => a.FetchAndSetHQAsset(null, null, null))
 32             .Do(i =>
 33             {
 434                 isHQAsset = true;
 435                 asset.isHQ.Returns(true);
 436             });
 37
 438        nftGO = new GameObject();
 439        var nftController = NFTShapeFactory.InstantiateLoaderController(0).GetComponent<NFTShapeLoaderController>();
 440        nftController.transform.SetParent(nftGO.transform);
 441        nftController.transform.ResetLocalTRS();
 42
 443        nftGO.transform.position = new Vector3(10, 0, 10);
 444        nftShapeConfig = nftController.config;
 45
 446        var config = new NFTShapeHQImageConfig()
 47        {
 48            asset = asset,
 49            controller = nftController,
 50            nftConfig = nftShapeConfig
 51        };
 452        imageHandler = NFTShapeHQImageHandler.Create(config);
 453    }
 54
 55    [TearDown]
 56    protected void TearDown()
 57    {
 458        Object.Destroy(nftGO);
 459        Object.Destroy(camera.gameObject);
 460    }
 61
 62    [Test]
 63    public void SetHQImageCorrectly()
 64    {
 165        Assert.IsFalse(isHQAsset, "Shouldn't use HQ image");
 166        SetInFrontAndLookingToNFT();
 167        Assert.IsTrue(isHQAsset, "Should be using HQ image");
 168    }
 69
 70    [Test]
 71    public void SetPreviewImageWhenCameraIsBehind()
 72    {
 173        SetInFrontAndLookingToNFT();
 174        Assert.IsTrue(isHQAsset, "Should be using HQ image");
 175        Camera.main.transform.position =
 76            nftGO.transform.position + nftGO.transform.forward * nftShapeConfig.hqImgMinDistance;
 177        imageHandler.Update();
 178        Assert.IsFalse(isHQAsset, "Shouldn't use HQ image");
 179    }
 80
 81    [Test]
 82    public void SetPreviewImageWhenCameraLookAway()
 83    {
 184        SetInFrontAndLookingToNFT();
 185        Assert.IsTrue(isHQAsset, "Should be using HQ image");
 186        Camera.main.transform.forward = nftGO.transform.right;
 187        imageHandler.Update();
 188        Assert.IsFalse(isHQAsset, "Shouldn't use HQ image");
 189    }
 90
 91    [Test]
 92    public void SetPreviewImageWhenPlayerMovesAway()
 93    {
 194        SetInFrontAndLookingToNFT();
 195        Assert.IsTrue(isHQAsset, "Should be using HQ image");
 196        CommonScriptableObjects.playerUnityPosition
 97                               .Set(nftGO.transform.position - nftGO.transform.forward * (nftShapeConfig.hqImgMinDistanc
 198        Assert.IsFalse(isHQAsset, "Shouldn't use HQ image");
 199    }
 100
 101    void SetInFrontAndLookingToNFT()
 102    {
 4103        CommonScriptableObjects.playerUnityPosition.Set(nftGO.transform.position - nftGO.transform.forward * nftShapeCon
 4104        Camera.main.transform.position = CommonScriptableObjects.playerUnityPosition.Get();
 4105        Camera.main.transform.LookAt(nftGO.transform);
 4106        imageHandler.Update();
 4107    }
 108}