2017-11-06 01:56:50 +01:00
|
|
|
|
using StagWare.FanControl.Configurations.Validation;
|
|
|
|
|
using System;
|
2017-06-09 15:42:26 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2017-11-06 01:56:50 +01:00
|
|
|
|
using System.Text;
|
2017-06-09 15:42:26 +02:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace StagWare.FanControl.Configurations.Tests
|
|
|
|
|
{
|
|
|
|
|
public class ConfigsTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
2018-10-27 19:23:24 +02:00
|
|
|
|
public static void AreConfigsValid()
|
2017-06-09 15:42:26 +02:00
|
|
|
|
{
|
|
|
|
|
var configMan = new FanControlConfigManager(GetConfigsDir());
|
2017-11-06 01:56:50 +01:00
|
|
|
|
var validator = new FanControlConfigValidator();
|
2017-06-09 15:42:26 +02:00
|
|
|
|
|
|
|
|
|
foreach (string name in configMan.ConfigNames)
|
|
|
|
|
{
|
2017-11-06 01:56:50 +01:00
|
|
|
|
var cfg = configMan.GetConfig(name);
|
2017-11-06 02:13:16 +01:00
|
|
|
|
Assert.True(cfg != null, $"{name} config could not be loaded");
|
2017-11-06 01:56:50 +01:00
|
|
|
|
|
|
|
|
|
var result = validator.Validate(cfg, false, false);
|
|
|
|
|
StringBuilder message = null;
|
|
|
|
|
|
|
|
|
|
if (!result.Success)
|
|
|
|
|
{
|
|
|
|
|
message = new StringBuilder();
|
2017-11-06 02:13:16 +01:00
|
|
|
|
message.AppendFormat("{0} config is not valid:", name);
|
2017-11-06 01:56:50 +01:00
|
|
|
|
message.AppendLine();
|
|
|
|
|
|
2017-12-03 23:55:23 +01:00
|
|
|
|
foreach (var validation in result.Failed)
|
2017-11-06 01:56:50 +01:00
|
|
|
|
{
|
2017-12-03 23:55:23 +01:00
|
|
|
|
message.AppendFormat("- {0}", validation.RuleDescription);
|
|
|
|
|
message.AppendLine();
|
|
|
|
|
message.AppendFormat("--> {0}", validation.Reason);
|
|
|
|
|
message.AppendLine();
|
2017-11-06 02:13:16 +01:00
|
|
|
|
message.AppendLine();
|
2017-11-06 01:56:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.True(result.Success, message?.ToString());
|
2017-06-09 15:42:26 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2018-10-27 19:23:24 +02:00
|
|
|
|
public static void HaveAllConfigsBeenLoaded()
|
2017-06-09 15:42:26 +02:00
|
|
|
|
{
|
|
|
|
|
string path = GetConfigsDir();
|
|
|
|
|
var configMan = new FanControlConfigManager(path);
|
|
|
|
|
var configsLookup = new HashSet<string>(
|
|
|
|
|
Directory.GetFiles(path).Select(x => Path.GetFileNameWithoutExtension(x)));
|
|
|
|
|
|
|
|
|
|
Assert.True(configsLookup.SetEquals(configMan.ConfigNames));
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 00:00:34 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void DoAllConfigsHaveXmlFileExtension()
|
|
|
|
|
{
|
|
|
|
|
string path = GetConfigsDir();
|
|
|
|
|
Assert.True(Directory.GetFiles(path).All(x => x.EndsWith(".xml")));
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 15:42:26 +02:00
|
|
|
|
private static string GetConfigsDir()
|
|
|
|
|
{
|
|
|
|
|
string path = Directory.GetParent(Environment.CurrentDirectory)?
|
|
|
|
|
.Parent?.Parent?.Parent?.FullName;
|
|
|
|
|
|
|
|
|
|
if (path == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Path.Combine(path, "Configs");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|