< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionFactory_Mock()0%110100%
GetSectionController(...)0%440100%
SetViewContainer(...)0%110100%
Dispose()0%110100%
OnShow()0%110100%
OnHide()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        {
 14            sectionFactory_Mock = new SectionFactory_Mock();
 15            controller = new SectionsController(sectionFactory_Mock, null);
 16        }
 17
 18        [TearDown]
 19        public void TearDown() { controller.Dispose(); }
 20
 21        [Test]
 22        public void OpenSection()
 23        {
 24            bool openCallbackCalled = false;
 25            SectionBase sectionOpened = null;
 26
 27            void OnSectionOpen(SectionBase section)
 28            {
 29                openCallbackCalled = true;
 30                sectionOpened = section;
 31            }
 32
 33            controller.OnSectionShow += OnSectionOpen;
 34            controller.OpenSection(SectionId.SCENES_MAIN);
 35
 36            Assert.IsTrue(openCallbackCalled);
 37            Assert.IsTrue(sectionFactory_Mock.sectionScenesMain.isVisible);
 38            Assert.AreEqual(sectionFactory_Mock.sectionScenesMain, sectionOpened);
 39        }
 40
 41        [Test]
 42        public void SwitchOpenSection()
 43        {
 44            SectionBase openSection = null;
 45            SectionBase hiddenSection = null;
 46
 47            void OnSectionOpen(SectionBase section) { openSection = section; }
 48
 49            void OnSectionHide(SectionBase section) { hiddenSection = section; }
 50
 51            controller.OnSectionShow += OnSectionOpen;
 52            controller.OnSectionHide += OnSectionHide;
 53
 54            controller.OpenSection(SectionId.SCENES_MAIN);
 55
 56            Assert.IsTrue(sectionFactory_Mock.sectionScenesMain.isVisible);
 57            Assert.AreEqual(sectionFactory_Mock.sectionScenesMain, openSection);
 58
 59            controller.OpenSection(SectionId.SCENES_PROJECT);
 60
 61            Assert.IsFalse(sectionFactory_Mock.sectionScenesMain.isVisible);
 62            Assert.IsTrue(sectionFactory_Mock.sectionScenesProjects.isVisible);
 63
 64            Assert.AreEqual(sectionFactory_Mock.sectionScenesProjects, openSection);
 65            Assert.AreEqual(sectionFactory_Mock.sectionScenesMain, hiddenSection);
 66        }
 67    }
 68
 69    class SectionFactory_Mock : ISectionFactory
 70    {
 71        public SectionBase sectionScenesMain;
 72        public SectionBase sectionScenesProjects;
 73
 274        public SectionFactory_Mock()
 75        {
 276            sectionScenesMain = new Section_Mock();
 277            sectionScenesProjects =  new Section_Mock();
 278        }
 79
 80        SectionBase ISectionFactory.GetSectionController(SectionId id)
 81        {
 382            SectionBase result = null;
 83            switch (id)
 84            {
 85                case SectionId.SCENES_MAIN:
 286                    result = sectionScenesMain;
 287                    break;
 88                case SectionId.SCENES_DEPLOYED:
 89                    break;
 90                case SectionId.SCENES_PROJECT:
 191                    result = sectionScenesProjects;
 92                    break;
 93                case SectionId.LAND:
 94                    break;
 95            }
 96
 397            return result;
 98        }
 99
 100        class Section_Mock : SectionBase
 101        {
 3102            public override void SetViewContainer(Transform viewContainer) { }
 103
 3104            public override void Dispose() { }
 105
 3106            protected override void OnShow() { }
 107
 1108            protected override void OnHide() { }
 109        }
 110    }
 111}