2
0
mirror of https://github.com/hirschmann/nbfc synced 2025-08-22 18:07:13 +00:00

68 lines
2.0 KiB
C#
Raw Normal View History

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]
public void AreConfigsValid()
{
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);
Assert.True(cfg != null, $"{name} could not be loaded");
var result = validator.Validate(cfg, false, false);
StringBuilder message = null;
if (!result.Success)
{
message = new StringBuilder();
message.AppendFormat("{0} is not valid:", name);
message.AppendLine();
foreach (var rule in result.FailedRules)
{
message.AppendLine(rule.Description);
}
}
Assert.True(result.Success, message?.ToString());
2017-06-09 15:42:26 +02:00
}
}
[Fact]
public void HaveAllConfigsBeenLoaded()
{
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));
}
private static string GetConfigsDir()
{
string path = Directory.GetParent(Environment.CurrentDirectory)?
.Parent?.Parent?.Parent?.FullName;
if (path == null)
{
return null;
}
return Path.Combine(path, "Configs");
}
}
}