Files
jdescopingtool/NEW/tests/JdeScoping.ConfigManager.Tests/Services/ConfigFileServiceTests.cs
T
Joseph Doherty 54620ccb2e feat(configmanager): add ConfigFileService with tests
Add config file loading and saving service following TDD approach:
- IConfigFileService interface for loading/saving config files
- ConfigLoadException for descriptive error handling
- ConfigFileService implementation with JSON serialization
- Unit tests with mocked IFileSystem dependency
2026-01-19 17:38:20 -05:00

55 lines
1.6 KiB
C#

using JdeScoping.ConfigManager.Models;
using JdeScoping.ConfigManager.Services;
namespace JdeScoping.ConfigManager.Tests.Services;
public class ConfigFileServiceTests
{
private readonly IFileSystem _fileSystem;
private readonly ConfigFileService _sut;
public ConfigFileServiceTests()
{
_fileSystem = Substitute.For<IFileSystem>();
_sut = new ConfigFileService(_fileSystem);
}
[Fact]
public async Task LoadAppSettingsAsync_WithValidJson_ReturnsConfigModel()
{
// Arrange
var json = """
{
"DataSync": {
"Enabled": true,
"MaxDegreeOfParallelism": 8
}
}
""";
_fileSystem.ReadAllTextAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
.Returns(Task.FromResult(json));
// Act
var result = await _sut.LoadAppSettingsAsync("/config/appsettings.json");
// Assert
result.ShouldNotBeNull();
result.DataSync.Enabled.ShouldBeTrue();
result.DataSync.MaxDegreeOfParallelism.ShouldBe(8);
}
[Fact]
public async Task LoadAppSettingsAsync_WithInvalidJson_ThrowsWithHelpfulMessage()
{
// Arrange
var json = "{ invalid json }";
_fileSystem.ReadAllTextAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
.Returns(Task.FromResult(json));
// Act & Assert
var ex = await Should.ThrowAsync<ConfigLoadException>(
() => _sut.LoadAppSettingsAsync("/config/appsettings.json"));
ex.Message.ShouldContain("parse");
}
}