mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-21 03:54:07 +02:00
.github
.idea
Application
Browser
Configuration
Controls
Dialogs
Management
Plugins
Properties
Resources
Updates
Utils
bld
lib
TweetLib.Communication
TweetLib.Core
TweetTest.System
Configuration
TestUserConfig.cs
Data
Properties
TweetTest.System.csproj
UnitTestIO.cs
packages.config
TweetTest.Unit
subprocess
video
.gitattributes
.gitignore
LICENSE.md
Program.cs
README.md
Reporter.cs
TweetDuck.csproj
TweetDuck.sln
TweetDuck.sln.DotSettings
Version.cs
packages.config
* Switch to .NET Framework 4.7.2 & C# 8.0, update libraries * Add TweetLib.Core project targeting .NET Standard 2.0 * Enable reference nullability checks for TweetLib.Core * Move a bunch of utility classes into TweetLib.Core & refactor * Partially move TweetDuck plugin & update system to TweetLib.Core * Move some constants and CultureInfo setup to TweetLib.Core * Move some configuration classes to TweetLib.Core * Minor refactoring and warning suppression * Add App to TweetLib.Core * Add IAppErrorHandler w/ implementation * Continue moving config, plugin, and update classes to TweetLib.Core * Fix a few nullability checks * Update installers to check for .NET Framework 4.7.2
134 lines
4.4 KiB
C#
134 lines
4.4 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace TweetTest.Configuration{
|
|
[TestClass]
|
|
public class TestUserConfig : TestIO{ /* TODO
|
|
private static void WriteTestConfig(string file, bool withBackup){
|
|
UserConfig cfg = UserConfig.Load(file);
|
|
cfg.ZoomLevel = 123;
|
|
cfg.Save();
|
|
|
|
if (withBackup){
|
|
cfg.Save();
|
|
}
|
|
}
|
|
|
|
[Pure] // used to display a warning when not using the return value
|
|
private static bool CheckTestConfig(string file){
|
|
return UserConfig.Load(file).ZoomLevel == 123;
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestMissing(){
|
|
Assert.IsNotNull(UserConfig.Load("missing"));
|
|
Assert.IsFalse(File.Exists("missing"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestBasic(){
|
|
Assert.IsFalse(CheckTestConfig("basic"));
|
|
WriteTestConfig("basic", false);
|
|
Assert.IsTrue(CheckTestConfig("basic"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestBackupName(){
|
|
Assert.AreEqual("name.bak", UserConfig.GetBackupFile("name"));
|
|
Assert.AreEqual("name.cfg.bak", UserConfig.GetBackupFile("name.cfg"));
|
|
Assert.AreEqual("name.bak.bak", UserConfig.GetBackupFile("name.bak"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestBackupCreate(){
|
|
WriteTestConfig("nobackup", false);
|
|
Assert.IsTrue(File.Exists("nobackup"));
|
|
Assert.IsFalse(File.Exists(UserConfig.GetBackupFile("nobackup")));
|
|
|
|
WriteTestConfig("withbackup", true);
|
|
Assert.IsTrue(File.Exists("withbackup"));
|
|
Assert.IsTrue(File.Exists(UserConfig.GetBackupFile("withbackup")));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestBackupRestore(){
|
|
WriteTestConfig("gone", true);
|
|
Assert.IsTrue(File.Exists("gone"));
|
|
Assert.IsTrue(File.Exists(UserConfig.GetBackupFile("gone")));
|
|
File.Delete("gone");
|
|
Assert.IsTrue(CheckTestConfig("gone"));
|
|
|
|
WriteTestConfig("corrupted", true);
|
|
Assert.IsTrue(File.Exists("corrupted"));
|
|
Assert.IsTrue(File.Exists(UserConfig.GetBackupFile("corrupted")));
|
|
File.WriteAllText("corrupted", "oh no corrupt");
|
|
Assert.IsTrue(CheckTestConfig("corrupted"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestReload(){
|
|
UserConfig cfg = UserConfig.Load("reloaded");
|
|
cfg.ZoomLevel = 123;
|
|
cfg.Save();
|
|
|
|
cfg.ZoomLevel = 200;
|
|
cfg.Reload();
|
|
Assert.AreEqual(123, cfg.ZoomLevel);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestReset(){
|
|
UserConfig cfg = UserConfig.Load("reset");
|
|
cfg.ZoomLevel = 123;
|
|
cfg.Save();
|
|
|
|
File.Delete("reset");
|
|
cfg.Reload();
|
|
Assert.AreEqual(100, cfg.ZoomLevel);
|
|
Assert.IsTrue(File.Exists("reset"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestEventsNoTrigger(){
|
|
void Fail(object sender, EventArgs args) => Assert.Fail();
|
|
|
|
UserConfig cfg = UserConfig.Load("events");
|
|
cfg.MuteNotifications = true;
|
|
cfg.TrayBehavior = TrayIcon.Behavior.Combined;
|
|
cfg.ZoomLevel = 99;
|
|
|
|
cfg.MuteToggled += Fail;
|
|
cfg.TrayBehaviorChanged += Fail;
|
|
cfg.ZoomLevelChanged += Fail;
|
|
|
|
cfg.MuteNotifications = true;
|
|
cfg.TrayBehavior = TrayIcon.Behavior.Combined;
|
|
cfg.ZoomLevel = 99;
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestEventsTrigger(){
|
|
int triggers = 0;
|
|
void Trigger(object sender, EventArgs args) => ++triggers;
|
|
|
|
UserConfig cfg = UserConfig.Load("events");
|
|
cfg.MuteNotifications = false;
|
|
cfg.TrayBehavior = TrayIcon.Behavior.Disabled;
|
|
cfg.ZoomLevel = 100;
|
|
|
|
cfg.MuteToggled += Trigger;
|
|
cfg.TrayBehaviorChanged += Trigger;
|
|
cfg.ZoomLevelChanged += Trigger;
|
|
|
|
cfg.MuteNotifications = true;
|
|
cfg.TrayBehavior = TrayIcon.Behavior.Combined;
|
|
cfg.ZoomLevel = 99;
|
|
|
|
cfg.MuteNotifications = false;
|
|
cfg.TrayBehavior = TrayIcon.Behavior.Disabled;
|
|
cfg.ZoomLevel = 100;
|
|
|
|
Assert.AreEqual(6, triggers);
|
|
}*/
|
|
}
|
|
}
|