summaryrefslogtreecommitdiff
path: root/src/Notepad/Presentation/Core
diff options
context:
space:
mode:
authormo <mo.khan@gmail.com>2018-11-04 15:22:16 -0700
committermo <mo.khan@gmail.com>2018-11-04 15:22:16 -0700
commit5ee1f55497a4e30322a56f133f897ecde1612967 (patch)
treebf544e0879234c3623869627d8786776cb19b8e9 /src/Notepad/Presentation/Core
initial commit.HEADmaster
Diffstat (limited to 'src/Notepad/Presentation/Core')
-rw-r--r--src/Notepad/Presentation/Core/ApplicationController.cs13
-rw-r--r--src/Notepad/Presentation/Core/ApplicationControllerSpecs.cs54
-rw-r--r--src/Notepad/Presentation/Core/IApplicationController.cs5
-rw-r--r--src/Notepad/Presentation/Core/IPresenter.cs5
-rw-r--r--src/Notepad/Presentation/Core/IPresenterRegistry.cs13
5 files changed, 90 insertions, 0 deletions
diff --git a/src/Notepad/Presentation/Core/ApplicationController.cs b/src/Notepad/Presentation/Core/ApplicationController.cs
new file mode 100644
index 0000000..4970593
--- /dev/null
+++ b/src/Notepad/Presentation/Core/ApplicationController.cs
@@ -0,0 +1,13 @@
+namespace Notepad.Presentation.Core {
+ public class ApplicationController : IApplicationController {
+ private readonly IPresenterRegistry registeredPresenters;
+
+ public ApplicationController(IPresenterRegistry presenterRegistry) {
+ registeredPresenters = presenterRegistry;
+ }
+
+ public void Run<Presenter>() where Presenter : IPresenter {
+ registeredPresenters.FindAnImplementationOf<Presenter>().Initialize();
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Core/ApplicationControllerSpecs.cs b/src/Notepad/Presentation/Core/ApplicationControllerSpecs.cs
new file mode 100644
index 0000000..834ec7c
--- /dev/null
+++ b/src/Notepad/Presentation/Core/ApplicationControllerSpecs.cs
@@ -0,0 +1,54 @@
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Notepad.Presentation.Core {
+ public class ApplicationControllerSpecs {}
+
+ [TestFixture]
+ public class when_the_application_controller_is_asked_to_run_a_presenter_ {
+ private MockRepository mockery;
+ private IPresenterRegistry presenterRegistry;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ presenterRegistry = mockery.DynamicMock<IPresenterRegistry>();
+ }
+
+ [Test]
+ public void should_ask_the_registered_presenters_for_an_instance_of_the_presenter_to_run() {
+ var implementationOfThePresenter = mockery.DynamicMock<IPresenter>();
+ using (mockery.Record()) {
+ Expect
+ .Call(presenterRegistry.FindAnImplementationOf<IPresenter>())
+ .Return(implementationOfThePresenter)
+ .Repeat
+ .AtLeastOnce();
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT().Run<IPresenter>();
+ }
+ }
+
+ [Test]
+ public void should_initialize_the_presenter_to_run() {
+ var presenterToInitialize = mockery.DynamicMock<IPresenter>();
+ using (mockery.Record()) {
+ SetupResult
+ .For(presenterRegistry.FindAnImplementationOf<IPresenter>())
+ .Return(presenterToInitialize);
+
+ presenterToInitialize.Initialize();
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT().Run<IPresenter>();
+ }
+ }
+
+ private IApplicationController CreateSUT() {
+ return new ApplicationController(presenterRegistry);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Core/IApplicationController.cs b/src/Notepad/Presentation/Core/IApplicationController.cs
new file mode 100644
index 0000000..735ef04
--- /dev/null
+++ b/src/Notepad/Presentation/Core/IApplicationController.cs
@@ -0,0 +1,5 @@
+namespace Notepad.Presentation.Core {
+ public interface IApplicationController {
+ void Run<Presenter>() where Presenter : IPresenter;
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Core/IPresenter.cs b/src/Notepad/Presentation/Core/IPresenter.cs
new file mode 100644
index 0000000..45d40b2
--- /dev/null
+++ b/src/Notepad/Presentation/Core/IPresenter.cs
@@ -0,0 +1,5 @@
+namespace Notepad.Presentation.Core {
+ public interface IPresenter {
+ void Initialize();
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Core/IPresenterRegistry.cs b/src/Notepad/Presentation/Core/IPresenterRegistry.cs
new file mode 100644
index 0000000..9117489
--- /dev/null
+++ b/src/Notepad/Presentation/Core/IPresenterRegistry.cs
@@ -0,0 +1,13 @@
+using Notepad.Infrastructure.Container;
+
+namespace Notepad.Presentation.Core {
+ public interface IPresenterRegistry {
+ Presenter FindAnImplementationOf<Presenter>() where Presenter : IPresenter;
+ }
+
+ public class RegisteredPresenter : IPresenterRegistry {
+ public Presenter FindAnImplementationOf<Presenter>() where Presenter : IPresenter {
+ return Resolve.DependencyFor<Presenter>();
+ }
+ }
+} \ No newline at end of file