< Summary

Class:Tests.SectionsControllerShould
Assembly:BuilderProjectsPanelTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Tests/SectionsControllerShould.cs
Covered lines:30
Uncovered lines:0
Coverable lines:30
Total lines:111
Line coverage:100% (30 of 30)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
OpenSection()0%110100%
SwitchOpenSection()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Tests/SectionsControllerShould.cs

#LineLine coverage
 1using NUnit.Framework;
 2using UnityEngine;
 3
 4namespace Tests
 5{
 6    public class SectionsControllerShould
 7    {
 8        private SectionsController controller;
 9        private SectionFactory_Mock sectionFactory_Mock;
 10
 11        [SetUp]
 12        public void SetUp()
 13        {
 214            sectionFactory_Mock = new SectionFactory_Mock();
 215            controller = new SectionsController(sectionFactory_Mock, null);
 216        }
 17
 18        [TearDown]
 419        public void TearDown() { controller.Dispose(); }
 20
 21        [Test]
 22        public void OpenSection()
 23        {
 124            bool openCallbackCalled = false;
 125            SectionBase sectionOpened = null;
 26
 27            void OnSectionOpen(SectionBase section)
 28            {
 129                openCallbackCalled = true;
 130                sectionOpened = section;
 131            }
 32
 133            controller.OnSectionShow += OnSectionOpen;
 134            controller.OpenSection(SectionId.SCENES_MAIN);
 35
 136            Assert.IsTrue(openCallbackCalled);
 137            Assert.IsTrue(sectionFactory_Mock.sectionScenesMain.isVisible);
 138            Assert.AreEqual(sectionFactory_Mock.sectionScenesMain, sectionOpened);
 139        }
 40
 41        [Test]
 42        public void SwitchOpenSection()
 43        {
 144            SectionBase openSection = null;
 145            SectionBase hiddenSection = null;
 46
 447            void OnSectionOpen(SectionBase section) { openSection = section; }
 48
 249            void OnSectionHide(SectionBase section) { hiddenSection = section; }
 50
 151            controller.OnSectionShow += OnSectionOpen;
 152            controller.OnSectionHide += OnSectionHide;
 53
 154            controller.OpenSection(SectionId.SCENES_MAIN);
 55
 156            Assert.IsTrue(sectionFactory_Mock.sectionScenesMain.isVisible);
 157            Assert.AreEqual(sectionFactory_Mock.sectionScenesMain, openSection);
 58
 159            controller.OpenSection(SectionId.SCENES_PROJECT);
 60
 161            Assert.IsFalse(sectionFactory_Mock.sectionScenesMain.isVisible);
 162            Assert.IsTrue(sectionFactory_Mock.sectionScenesProjects.isVisible);
 63
 164            Assert.AreEqual(sectionFactory_Mock.sectionScenesProjects, openSection);
 165            Assert.AreEqual(sectionFactory_Mock.sectionScenesMain, hiddenSection);
 166        }
 67    }
 68
 69    class SectionFactory_Mock : ISectionFactory
 70    {
 71        public SectionBase sectionScenesMain;
 72        public SectionBase sectionScenesProjects;
 73
 74        public SectionFactory_Mock()
 75        {
 76            sectionScenesMain = new Section_Mock();
 77            sectionScenesProjects =  new Section_Mock();
 78        }
 79
 80        SectionBase ISectionFactory.GetSectionController(SectionId id)
 81        {
 82            SectionBase result = null;
 83            switch (id)
 84            {
 85                case SectionId.SCENES_MAIN:
 86                    result = sectionScenesMain;
 87                    break;
 88                case SectionId.SCENES_DEPLOYED:
 89                    break;
 90                case SectionId.SCENES_PROJECT:
 91                    result = sectionScenesProjects;
 92                    break;
 93                case SectionId.LAND:
 94                    break;
 95            }
 96
 97            return result;
 98        }
 99
 100        class Section_Mock : SectionBase
 101        {
 102            public override void SetViewContainer(Transform viewContainer) { }
 103
 104            public override void Dispose() { }
 105
 106            protected override void OnShow() { }
 107
 108            protected override void OnHide() { }
 109        }
 110    }
 111}