-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddeab63
commit cdfbf7d
Showing
2 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using DesktopClock.Properties; | ||
|
||
namespace DesktopClock.Tests; | ||
|
||
public class SettingsTests : IAsyncLifetime | ||
{ | ||
public Task InitializeAsync() | ||
{ | ||
// Ensure the settings file does not exist before each test. | ||
if (File.Exists(Settings.FilePath)) | ||
{ | ||
File.Delete(Settings.FilePath); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
// Clean up. | ||
if (File.Exists(Settings.FilePath)) | ||
{ | ||
File.Delete(Settings.FilePath); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
[Fact(Skip = "File path is unauthorized")] | ||
public void Save_ShouldWriteSettingsToFile() | ||
{ | ||
var settings = Settings.Default; | ||
settings.FontFamily = "My custom font"; | ||
|
||
var result = settings.Save(); | ||
|
||
Assert.True(result); | ||
Assert.True(File.Exists(Settings.FilePath)); | ||
|
||
var savedSettings = File.ReadAllText(Settings.FilePath); | ||
Assert.Contains("My custom font", savedSettings); | ||
} | ||
|
||
[Fact(Skip = "File path is unauthorized")] | ||
public void LoadFromFile_ShouldPopulateSettings() | ||
{ | ||
var json = "{\"FontFamily\": \"Consolas\"}"; | ||
File.WriteAllText(Settings.FilePath, json); | ||
var settings = Settings.Default; | ||
Assert.Equal("My custom font", settings.FontFamily); | ||
} | ||
|
||
[Fact] | ||
public void ScaleHeight_ShouldAdjustHeightByExpectedAmount() | ||
{ | ||
var settings = Settings.Default; | ||
|
||
Assert.Equal(48, settings.Height); | ||
|
||
settings.ScaleHeight(2); | ||
|
||
Assert.Equal(64, settings.Height); | ||
|
||
settings.ScaleHeight(-2); | ||
|
||
Assert.Equal(47, settings.Height); | ||
} | ||
|
||
[Fact] | ||
public void GetTimeZoneInfo_ShouldReturnExpectedTimeZoneInfo() | ||
{ | ||
var settings = Settings.Default; | ||
|
||
// Default TimeZone should return Local | ||
var localTimeZone = TimeZoneInfo.Local; | ||
var timeZoneInfo = settings.GetTimeZoneInfo(); | ||
Assert.Equal(localTimeZone, timeZoneInfo); | ||
|
||
// Set to a specific time zone | ||
settings.TimeZone = "Pacific Standard Time"; | ||
timeZoneInfo = settings.GetTimeZoneInfo(); | ||
Assert.Equal("Pacific Standard Time", timeZoneInfo.Id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters