Skip to content

Commit

Permalink
(#129) Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jibedoubleve committed Mar 8, 2023
1 parent d441695 commit 5762517
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 97 deletions.
78 changes: 0 additions & 78 deletions src/Lanceur.Tests/BusinessLogic/SettingsShould.cs

This file was deleted.

101 changes: 82 additions & 19 deletions src/Lanceur.Tests/Functional/SettingsShould.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions;
using Lanceur.Core.Models.Settings;
using Lanceur.Core.Services;
using Lanceur.Infra;
using Lanceur.Infra.Services;
using Lanceur.Infra.SQLite;
using Lanceur.Tests.SQLite;
Expand All @@ -12,6 +12,27 @@ public class SettingsShould : SQLiteTest
{
#region Methods

private static void Assert(Action<IAppSettingsService> assert)
{
var connection = BuildFreshDB();
var scope = new SQLiteConnectionScope(connection);
var settingRepository = new SQLiteAppSettingsService(scope);

assert(settingRepository);
}

[Fact]
public void CreateFileWhenNotExists()
{
var file = Path.GetTempFileName();
var stg = new JsonSettingsService(file);
File.Delete(file);

var value = stg[Setting.DbPath];

value.Should().Be(@"%appdata%\probel\lanceur2\data.sqlite");
}

[Fact]
public void GetAndSetData()
{
Expand All @@ -28,40 +49,82 @@ public void GetAndSetData()
}

[Fact]
public void SaveJsonData()
public void HaveDefaultHotKey()
{
var file = Path.GetTempFileName();
var stg = new JsonSettingsService(file);
Assert(repository =>
{
var settings = repository.Load();
settings.HotKey.ModifierKey.Should().Be(3);
settings.HotKey.Key.Should().Be(18);
});
}

stg[Setting.DbPath] = "undeuxtrois";
stg.Save();
[Fact]
public void HaveDefaultPosition()
{
Assert(repository =>
{
var settings = repository.Load();
settings.Window.Position.Left.Should().Be(600);
settings.Window.Position.Top.Should().Be(150);
});
}

var json = File.ReadAllText(file);
[Fact]
public void Load()
{
var conn = BuildFreshDB();
var scope = new SQLiteConnectionScope(conn);
var settings = new SQLiteAppSettingsService(scope);

json.Should().Be("{\"DbPath\":\"undeuxtrois\"}");
settings.Load();
}

[Theory]
[InlineData(1, 2)]
public void SaveHotKey(int modifierKey, int key)
{
Assert(repository =>
{
var settings = repository.Load();
settings.HotKey = new HotKeySection(modifierKey, key);

repository.Save(settings);
settings.HotKey.ModifierKey.Should().Be(modifierKey);
settings.HotKey.Key.Should().Be(key);
});
}

[Fact]
public void CreateFileWhenNotExists()
public void SaveJsonData()
{
var file = Path.GetTempFileName();
var stg = new JsonSettingsService(file);
File.Delete(file);

var value = stg[Setting.DbPath];
stg[Setting.DbPath] = "undeuxtrois";
stg.Save();

value.Should().Be(@"%appdata%\probel\lanceur2\data.sqlite");
var json = File.ReadAllText(file);

json.Should().Be("{\"DbPath\":\"undeuxtrois\"}");
}

[Fact]
public void Load()
[Theory]
[InlineData(1.1d, 2.1d)]
public void SavePosition(double left, double top)
{
var conn = BuildFreshDB();
var scope = new SQLiteConnectionScope(conn);
var settings = new SQLiteAppSettingsService(scope);

settings.Load();
Assert(repository =>
{
var settings = repository.Load();
settings.Window.Position.Left = left;
settings.Window.Position.Top = top;

repository.Save(settings);

var loaded = repository.Load();
loaded.Window.Position.Left.Should().Be(left);
loaded.Window.Position.Top.Should().Be(top);
});
}

#endregion Methods
Expand Down

0 comments on commit 5762517

Please sign in to comment.