mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-07 05:58:07 +01:00
Write settings, presets and favourites whole or not at all
A failed write leaves the old file in place. Settings that could not be read are not saved over. UI exceptions reach the log. Started from a shortcut set up elsewhere, the starter moves to its own folder when only that one holds a game.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Domain.Sceneries;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
@@ -35,4 +34,43 @@ public class FavoriteSceneriesTests
|
||||
|
||||
Assert.False(favorites.Contains(scenery));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_file_that_could_not_be_read_goes_aside_before_a_star_replaces_it()
|
||||
{
|
||||
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||
.WithLegacyFile(TestInstallation.At("scenery", "td.scn"), "//$n Testowa")
|
||||
.WithFile(FavoritesPath, "one.scn\ntwo.scn")
|
||||
.FailReading(FavoritesPath));
|
||||
var scenery = Assert.Single(installation.Sceneries.LoadAll());
|
||||
var favorites = new FavoriteSceneries(installation.Files, installation.Log, FavoritesPath);
|
||||
|
||||
installation.Files.AllowReading(FavoritesPath);
|
||||
favorites.Toggle(scenery);
|
||||
|
||||
Assert.Equal("one.scn\ntwo.scn", installation.Files.ReadAllText(FavoritesPath + ".unreadable"));
|
||||
Assert.Equal("td.scn", installation.Files.ReadAllText(FavoritesPath));
|
||||
Assert.Contains(FavoritesPath + ".unreadable", installation.Log.Text);
|
||||
|
||||
// Set aside once: the file is the starter's own again.
|
||||
favorites.Toggle(scenery);
|
||||
Assert.False(installation.Files.FileExists(FavoritesPath + ".unreadable-2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_locked_file_is_left_alone_when_no_copy_of_it_can_be_made()
|
||||
{
|
||||
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||
.WithLegacyFile(TestInstallation.At("scenery", "td.scn"), "//$n Testowa")
|
||||
.WithFile(FavoritesPath, "one.scn\ntwo.scn")
|
||||
.FailReading(FavoritesPath));
|
||||
var scenery = Assert.Single(installation.Sceneries.LoadAll());
|
||||
var favorites = new FavoriteSceneries(installation.Files, installation.Log, FavoritesPath);
|
||||
|
||||
favorites.Toggle(scenery);
|
||||
|
||||
installation.Files.AllowReading(FavoritesPath);
|
||||
Assert.Equal("one.scn\ntwo.scn", installation.Files.ReadAllText(FavoritesPath));
|
||||
Assert.Contains("writing", installation.Log.Text);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user