public void TestLoad() { var theme = new Theme(); theme.LoadFromPath(_themePath); // Assert the loaded theme has expected values foreach (var field in _themeDict) { Assert.That(theme.Config[field.Key], Is.EqualTo(field.Value)); } }
public void TestDelete() { // copy test theme var copyPath = Path.GetTempFileName(); File.Copy(_themePath, copyPath, true); // load the copy var theme = new Theme(); theme.LoadFromPath(copyPath); // delete theme.Delete(); // assert the file does not exist Assert.That(File.Exists(copyPath), Is.False); }
public void TestLoadParseException() { // create new file var corruptThemePath = Path.GetTempFileName(); // load the test theme file, and write a corrupt version var contents = File.ReadAllText(_themePath); contents = contents.Replace("{", "!!!"); File.WriteAllText(corruptThemePath, contents); // assert that loading causes exception Assert.That(() => { var theme = new Theme(); theme.LoadFromPath(corruptThemePath); }, Throws.Exception.TypeOf<JsonReaderException>()); }
public void TestSave() { // load test theme var theme = new Theme(); theme.LoadFromPath(_themePath); // export to another path var themeSavePath = Path.GetTempFileName(); theme.Save(themeSavePath); // load the export var exportedTheme = new Theme(); exportedTheme.LoadFromPath(themeSavePath); // Assert the loaded theme has expected values foreach (var field in _themeDict) { Assert.That(theme.Config[field.Key], Is.EqualTo(field.Value)); } }
public void TestResourceDictionary() { var theme = new Theme(); theme.LoadFromPath(_themePath); var resourceDictionary = theme.ToResourceDictionary(); // test the resource dictionary for correctness by comparing each color foreach (var colorKey in _colorKeys) { var actualColor = ((SolidColorBrush) resourceDictionary[colorKey]).Color; var expectedColor = ((SolidColorBrush) new BrushConverter().ConvertFromString(_themeDict[colorKey])).Color; Assert.That(actualColor, Is.EqualTo(expectedColor)); } }
public void TestLoadWithBadPath() { var theme = new Theme(); var randomPath = Path.Combine("c:\\", Path.GetRandomFileName()); Assert.Throws<FileNotFoundException>(() => theme.LoadFromPath(randomPath)); }