< Summary

Class:BlockerHandlerCan
Assembly:BlockerControllerTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BlockerController/Tests/BlockerHandlerCan.cs
Covered lines:49
Uncovered lines:0
Coverable lines:49
Total lines:119
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%110100%
TearDown()0%110100%
ShowBlocker()0%110100%
HideBlocker()0%110100%
ShowBlockerInstantly()0%110100%
HideBlockerInstantly()0%110100%
SetParent()0%110100%
DestroyAllBlockers()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BlockerController/Tests/BlockerHandlerCan.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Helpers;
 3using System.Collections;
 4using System.Collections.Generic;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7using DCL;
 8using System.Linq;
 9using NSubstitute;
 10using NUnit.Framework;
 11
 12public class BlockerHandlerCan
 13{
 14    private IBlockerInstanceHandler blockerInstanceHandler;
 15    private IBlockerAnimationHandler blockerAnimationHandler;
 16    private ISceneHandler sceneHandler;
 17    private GameObject blockersParent;
 18
 19    [SetUp]
 20    protected void SetUp()
 21    {
 622        RenderProfileManifest.i.Initialize();
 23
 624        sceneHandler = Substitute.For<ISceneHandler>();
 25
 626        var allLoadedParcelCoords = new HashSet<Vector2Int>();
 627        allLoadedParcelCoords.Add(new Vector2Int(0, 0));
 628        allLoadedParcelCoords.Add(new Vector2Int(-1, 0));
 629        allLoadedParcelCoords.Add(new Vector2Int(-1, 1));
 30
 631        sceneHandler.GetAllLoadedScenesCoords().Returns(allLoadedParcelCoords);
 32
 633        blockerAnimationHandler = Substitute.For<IBlockerAnimationHandler>();
 34
 35        //NOTE(Brian): Call OnFinish() when blockerAnimationHandler.FadeOut is called.
 636        blockerAnimationHandler.FadeOut(Arg.Any<GameObject>(), Arg.Invoke());
 37
 638        var newBlockerInstanceHandler = new BlockerInstanceHandler();
 639        newBlockerInstanceHandler.Initialize(blockerAnimationHandler, null);
 40
 641        blockerInstanceHandler = newBlockerInstanceHandler;
 642        blockersParent = new GameObject();
 43
 644        blockerInstanceHandler.SetParent(blockersParent.transform);
 645    }
 46
 47    [TearDown]
 1248    protected void TearDown() { Object.Destroy(blockersParent); }
 49
 50    [Test]
 51    public void ShowBlocker()
 52    {
 153        blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0));
 154        blockerAnimationHandler.ReceivedWithAnyArgs(1).FadeIn(default);
 155        Assert.AreEqual(1, blockerInstanceHandler.GetBlockers().Count);
 156    }
 57
 58    [Test]
 59    public void HideBlocker()
 60    {
 161        blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true);
 162        blockerInstanceHandler.HideBlocker(new Vector2Int(0, 0), false);
 163        blockerAnimationHandler.ReceivedWithAnyArgs(1).FadeOut(default, default);
 164        Assert.AreEqual(0, blockerInstanceHandler.GetBlockers().Count);
 165    }
 66
 67    [Test]
 68    public void ShowBlockerInstantly()
 69    {
 170        blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true);
 171        blockerAnimationHandler.DidNotReceiveWithAnyArgs().FadeIn(default);
 172        Assert.AreEqual(1, blockerInstanceHandler.GetBlockers().Count);
 173    }
 74
 75    [Test]
 76    public void HideBlockerInstantly()
 77    {
 178        blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true);
 179        blockerInstanceHandler.HideBlocker(new Vector2Int(0, 0), true);
 180        blockerAnimationHandler.DidNotReceiveWithAnyArgs().FadeOut(default, default);
 181        Assert.AreEqual(0, blockerInstanceHandler.GetBlockers().Count);
 182    }
 83
 84    [Test]
 85    public void SetParent()
 86    {
 87        // Arrange
 188        GameObject testParent = new GameObject();
 189        blockerInstanceHandler.SetParent(testParent.transform);
 190        blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true);
 91
 92        // Act
 193        var blocker = blockerInstanceHandler.GetBlockers().First().Value.gameObject;
 94
 95        // Assert
 196        Assert.IsTrue(blocker.transform.parent == testParent.transform);
 97
 98        // Dispose
 199        Object.Destroy(testParent);
 1100    }
 101
 102    [Test]
 103    public void DestroyAllBlockers()
 104    {
 105        // Arrange
 1106        blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true);
 1107        blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 1), true);
 1108        blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 2), true);
 109
 1110        Assert.AreEqual(3, blockerInstanceHandler.GetBlockers().Count);
 111
 112        // Act
 1113        blockerInstanceHandler.DestroyAllBlockers();
 114
 115        // Assert
 1116        blockerAnimationHandler.DidNotReceiveWithAnyArgs().FadeOut(default, default);
 1117        Assert.AreEqual(0, blockerInstanceHandler.GetBlockers().Count);
 1118    }
 119}