diff --git a/Pomo-Shiny/App.config b/Pomo-Shiny/App.config
deleted file mode 100644
index 56efbc7..0000000
--- a/Pomo-Shiny/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Pomo-Shiny/App.xaml b/Pomo-Shiny/App.xaml
index 6b812e3..713b9ea 100644
--- a/Pomo-Shiny/App.xaml
+++ b/Pomo-Shiny/App.xaml
@@ -1,8 +1,6 @@
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
diff --git a/Pomo-Shiny/App.xaml.cs b/Pomo-Shiny/App.xaml.cs
index 51b297d..1848050 100644
--- a/Pomo-Shiny/App.xaml.cs
+++ b/Pomo-Shiny/App.xaml.cs
@@ -1,16 +1,46 @@
using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Linq;
-using System.Threading.Tasks;
+using System.IO;
using System.Windows;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
namespace Pomo_Shiny
{
///
- /// Interaction logic for App.xaml
+ /// Interaction logic for App.xaml
///
public partial class App : Application
{
+ private IServiceProvider ServiceProvider { get; set; }
+ private IConfiguration Configuration { get; set; }
+
+ protected override void OnStartup(StartupEventArgs e)
+ {
+ var builder = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", false, true);
+
+ Configuration = builder.Build();
+
+ var services = new ServiceCollection();
+ ConfigureServices(services);
+
+ ServiceProvider = services.BuildServiceProvider();
+
+ var mainWindow = ServiceProvider.GetRequiredService();
+ mainWindow.Show();
+ }
+
+ private void ConfigureServices(IServiceCollection services)
+ {
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
+ services.Configure(Configuration.GetSection(nameof(AppSettings)));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/Pomo-Shiny/AppSettings.cs b/Pomo-Shiny/AppSettings.cs
new file mode 100644
index 0000000..4454d46
--- /dev/null
+++ b/Pomo-Shiny/AppSettings.cs
@@ -0,0 +1,9 @@
+using Microsoft.Extensions.Configuration;
+
+namespace Pomo_Shiny
+{
+ public class AppSettings
+ {
+ public bool IsSoundOn { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Pomo-Shiny/MainWindow.xaml.cs b/Pomo-Shiny/MainWindow.xaml.cs
index cb558b9..cef5cf9 100644
--- a/Pomo-Shiny/MainWindow.xaml.cs
+++ b/Pomo-Shiny/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using System.Diagnostics.CodeAnalysis;
+using System.Configuration;
+using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Input;
@@ -10,10 +11,9 @@ namespace Pomo_Shiny
[ExcludeFromCodeCoverage]
public partial class MainWindow : Window
{
- public MainWindow()
+ public MainWindow(MainWindowViewModel mainWindowViewModel)
{
- DataContext = new MainWindowViewModel(new ApplicationAccessor(),
- new CountdownTimer(new TimerFacade(), new SoundProvider()));
+ DataContext = mainWindowViewModel;
InitializeComponent();
}
diff --git a/Pomo-Shiny/MainWindowViewModel.cs b/Pomo-Shiny/MainWindowViewModel.cs
index 342f39b..44db40a 100644
--- a/Pomo-Shiny/MainWindowViewModel.cs
+++ b/Pomo-Shiny/MainWindowViewModel.cs
@@ -1,5 +1,7 @@
-using System;
+using Microsoft.Extensions.Configuration;
+using System;
using System.Windows.Input;
+using Microsoft.Extensions.Options;
namespace Pomo_Shiny
{
@@ -7,12 +9,14 @@ public class MainWindowViewModel : ObservableObject
{
private readonly IApplicationAccessor _applicationAccessor;
private readonly ICountdownTimer _countdownTimer;
+ private readonly AppSettings _appSettings;
private TimeSpan _remainingTime;
- public MainWindowViewModel(IApplicationAccessor applicationAccessor, ICountdownTimer countdownTimer)
+ public MainWindowViewModel(IApplicationAccessor applicationAccessor, ICountdownTimer countdownTimer, IOptions appSettings)
{
_applicationAccessor = applicationAccessor;
_countdownTimer = countdownTimer;
+ _appSettings = appSettings.Value;
_countdownTimer.Callback = val => RemainingTime = val;
ExitCommand = new DelegateCommand(Exit);
@@ -48,7 +52,7 @@ private set
private void StartTimer()
{
- _countdownTimer.StartCountdown(25, false);
+ _countdownTimer.StartCountdown(25, _appSettings.IsSoundOn);
}
private void StopTimer()
@@ -58,7 +62,7 @@ private void StopTimer()
private void StartBreakTimer()
{
- _countdownTimer.StartCountdown(5, false);
+ _countdownTimer.StartCountdown(5, _appSettings.IsSoundOn);
}
private void Exit()
diff --git a/Pomo-Shiny/Pomo-Shiny.csproj b/Pomo-Shiny/Pomo-Shiny.csproj
index 66563e2..07efabf 100644
--- a/Pomo-Shiny/Pomo-Shiny.csproj
+++ b/Pomo-Shiny/Pomo-Shiny.csproj
@@ -2,19 +2,23 @@
WinExe
- netcoreapp3.0
+ netcoreapp3.1
Pomo_Shiny
true
-
-
+
+ PreserveNewest
+
+
+
-
-
+
+
+
\ No newline at end of file
diff --git a/Pomo-Shiny/appsettings.json b/Pomo-Shiny/appsettings.json
new file mode 100644
index 0000000..5ff2ef4
--- /dev/null
+++ b/Pomo-Shiny/appsettings.json
@@ -0,0 +1,5 @@
+{
+ "AppSettings": {
+ "SoundOn": false
+ }
+}
\ No newline at end of file
diff --git a/Tests/MainWindowViewModelTests.cs b/Tests/MainWindowViewModelTests.cs
index 9f072f2..bd8363d 100644
--- a/Tests/MainWindowViewModelTests.cs
+++ b/Tests/MainWindowViewModelTests.cs
@@ -1,5 +1,6 @@
using System;
using FakeItEasy;
+using Microsoft.Extensions.Options;
using NUnit.Framework;
using Pomo_Shiny;
@@ -10,13 +11,16 @@ public class MainWindowViewModelTests
private IApplicationAccessor _fakeApplicationAccessor;
private ICountdownTimer _fakeCountdownTimer;
private MainWindowViewModel _sut;
+ private IOptions _fakeAppSettings;
[SetUp]
public void Setup()
{
_fakeApplicationAccessor = A.Fake();
_fakeCountdownTimer = A.Fake();
- _sut = new MainWindowViewModel(_fakeApplicationAccessor, _fakeCountdownTimer);
+ _fakeAppSettings = A.Fake>();
+
+ _sut = new MainWindowViewModel(_fakeApplicationAccessor, _fakeCountdownTimer, _fakeAppSettings);
}
[Test]
@@ -32,7 +36,7 @@ public void StartTimerCommand_starts_timer_for_25_minutes()
{
_sut.StartTimerCommand.Execute(null);
- A.CallTo(() => _fakeCountdownTimer.StartCountdown(25, false)).MustHaveHappened();
+ A.CallTo(() => _fakeCountdownTimer.StartCountdown(25, A._)).MustHaveHappened();
}
[Test]
@@ -40,7 +44,7 @@ public void StartBreakTimerCommand_starts_timer_for_5_minutes()
{
_sut.StartBreakTimerCommand.Execute(null);
- A.CallTo(() => _fakeCountdownTimer.StartCountdown(5, false)).MustHaveHappened();
+ A.CallTo(() => _fakeCountdownTimer.StartCountdown(5, A._)).MustHaveHappened();
}
[Test]
@@ -102,5 +106,25 @@ public void Title_depends_on_PercentageToGo(double value, string expectedTitle)
A.CallTo(() => _fakeCountdownTimer.PercentageToGo).Returns(value);
Assert.AreEqual(expectedTitle, _sut.Title);
}
+
+ [TestCase(true)]
+ [TestCase(false)]
+ public void StartTimerCountdown_sound_controlled_by_config(bool soundIsOn)
+ {
+ _fakeAppSettings.Value.IsSoundOn = soundIsOn;
+
+ _sut.StartTimerCommand.Execute(null);
+ A.CallTo(() => _fakeCountdownTimer.StartCountdown(25, soundIsOn)).MustHaveHappened();
+ }
+
+ [TestCase(true)]
+ [TestCase(false)]
+ public void StartBreakTimerCountdown_sound_controlled_by_config(bool soundIsOn)
+ {
+ _fakeAppSettings.Value.IsSoundOn = soundIsOn;
+
+ _sut.StartBreakTimerCommand.Execute(null);
+ A.CallTo(() => _fakeCountdownTimer.StartCountdown(5, soundIsOn)).MustHaveHappened();
+ }
}
}
\ No newline at end of file
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 52502ba..85bcba8 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -1,13 +1,14 @@
- netcoreapp3.0
+ netcoreapp3.1
false
+