| | 1 | | using NUnit.Framework; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace 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 | |
|
| 2 | 74 | | public SectionFactory_Mock() |
| | 75 | | { |
| 2 | 76 | | sectionScenesMain = new Section_Mock(); |
| 2 | 77 | | sectionScenesProjects = new Section_Mock(); |
| 2 | 78 | | } |
| | 79 | |
|
| | 80 | | SectionBase ISectionFactory.GetSectionController(SectionId id) |
| | 81 | | { |
| 3 | 82 | | SectionBase result = null; |
| | 83 | | switch (id) |
| | 84 | | { |
| | 85 | | case SectionId.SCENES_MAIN: |
| 2 | 86 | | result = sectionScenesMain; |
| 2 | 87 | | break; |
| | 88 | | case SectionId.SCENES_DEPLOYED: |
| | 89 | | break; |
| | 90 | | case SectionId.SCENES_PROJECT: |
| 1 | 91 | | result = sectionScenesProjects; |
| | 92 | | break; |
| | 93 | | case SectionId.LAND: |
| | 94 | | break; |
| | 95 | | } |
| | 96 | |
|
| 3 | 97 | | return result; |
| | 98 | | } |
| | 99 | |
|
| | 100 | | class Section_Mock : SectionBase |
| | 101 | | { |
| 3 | 102 | | public override void SetViewContainer(Transform viewContainer) { } |
| | 103 | |
|
| 3 | 104 | | public override void Dispose() { } |
| | 105 | |
|
| 3 | 106 | | protected override void OnShow() { } |
| | 107 | |
|
| 1 | 108 | | protected override void OnHide() { } |
| | 109 | | } |
| | 110 | | } |
| | 111 | | } |