/
afanasevn
/
PdfEncoder
Обзор
Документация
Войти
/
afanasevn
/
PdfEncoder
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/PdfEncoder.UnitTests/Configuration/EnvLoaderTests.cs
67 строк
2 KB
IBS\NAfanasev
Add project files.
01 июл 2026, 14:54
01 июл 2026, 14:54
8414644
Код
Авторство
О чём код?
using PdfEncoder.Infrastructure.Configuration; namespace PdfEncoder.UnitTests.Configuration; public sealed class EnvLoaderTests { [Fact] public void Load_НеПерезаписываетСуществующиеПеременные() { var envFile = Path.Combine(Path.GetTempPath(), $"pdfencoder-{Guid.NewGuid():N}.env"); const string key = "PdfEncoder__TestKey"; const string fileValue = "from-file"; const string existingValue = "from-env"; try { File.WriteAllText(envFile, $"{key}={fileValue}"); Environment.SetEnvironmentVariable(key, existingValue); var loaded = EnvLoader.Load(envFile); Assert.True(loaded); Assert.Equal(existingValue, Environment.GetEnvironmentVariable(key)); } finally { Environment.SetEnvironmentVariable(key, null); if (File.Exists(envFile)) { File.Delete(envFile); } } } [Fact] public void Load_ЗагружаетПеременныеИзФайла() { var envFile = Path.Combine(Path.GetTempPath(), $"pdfencoder-{Guid.NewGuid():N}.env"); const string key = "PdfEncoder__LoadedKey"; try { File.WriteAllText(envFile, $"{key}=loaded-value"); Environment.SetEnvironmentVariable(key, null); var loaded = EnvLoader.Load(envFile); Assert.True(loaded); Assert.Equal("loaded-value", Environment.GetEnvironmentVariable(key)); } finally { Environment.SetEnvironmentVariable(key, null); if (File.Exists(envFile)) { File.Delete(envFile); } } } [Fact] public void IsSensitiveKey_ОпределяетСекретныеКлючи() { Assert.True(EnvLoader.IsSensitiveKey("Llm__ApiKey")); Assert.False(EnvLoader.IsSensitiveKey("Llm__BaseUrl")); } }