Files
Joseph Doherty 7e36bb4225 refactor: remove unused classes and consolidate ViewModels in Core
Remove 9 unused types from Core (duplicate extension classes, TableSpec, ColumnSpec, LotLocation), move ComponentLotViewModel and OperatorViewModel from Client to Core, and refactor DataSync.Dev to use pipeline-based configuration. Fix Login.razor to use UserInfoDto directly.
2026-01-19 00:13:12 -05:00

102 lines
3.0 KiB
C#

using JdeScoping.DataSync.Dev.Configuration;
using JdeScoping.DataSync.Dev.Contracts;
using JdeScoping.DataSync.Dev.Services;
using JdeScoping.DataSync.Etl.Pipeline;
using JdeScoping.DataSync.Etl.Results;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute;
using Shouldly;
namespace JdeScoping.DataSync.Dev.Tests;
/// <summary>
/// Tests for DevEtlRegistry.
/// </summary>
public class DevEtlRegistryTests : IDisposable
{
private readonly IDevEtlPipelineFactory _mockFactory;
private readonly ILogger<DevEtlRegistry> _logger;
private readonly string _tempDirectory;
public DevEtlRegistryTests()
{
_mockFactory = Substitute.For<IDevEtlPipelineFactory>();
_logger = NullLogger<DevEtlRegistry>.Instance;
// Create a temp directory for tests
_tempDirectory = Path.Combine(Path.GetTempPath(), $"DevEtlRegistryTests_{Guid.NewGuid():N}");
Directory.CreateDirectory(_tempDirectory);
}
[Fact]
public void Constructor_WithValidArguments_Succeeds()
{
// Arrange
_mockFactory.GetAvailableTables().Returns(new[] { "Branch" });
// Act
var registry = new DevEtlRegistry(_mockFactory, _tempDirectory, _logger);
// Assert
registry.ShouldNotBeNull();
}
[Fact]
public void Constructor_WithNullFactory_ThrowsArgumentNullException()
{
// Act & Assert
Should.Throw<ArgumentNullException>(() => new DevEtlRegistry(null!, _tempDirectory, _logger));
}
[Fact]
public void Constructor_WithEmptyCacheDirectory_ThrowsArgumentException()
{
// Act & Assert
Should.Throw<ArgumentException>(() => new DevEtlRegistry(_mockFactory, string.Empty, _logger));
}
[Fact]
public void Constructor_WithNonExistentCacheDirectory_ThrowsDirectoryNotFoundException()
{
// Arrange
var nonExistentPath = "/nonexistent/cache/directory";
// Act & Assert
Should.Throw<DirectoryNotFoundException>(() => new DevEtlRegistry(_mockFactory, nonExistentPath, _logger));
}
[Fact]
public void GetAvailableTables_DelegatesToFactory()
{
// Arrange
var expectedTables = new[] { "Branch", "Item", "Lot" };
_mockFactory.GetAvailableTables().Returns(expectedTables);
var registry = new DevEtlRegistry(_mockFactory, _tempDirectory, _logger);
// Act
var tables = registry.GetAvailableTables().ToList();
// Assert
tables.ShouldBe(expectedTables);
_mockFactory.Received(1).GetAvailableTables();
}
public void Dispose()
{
// Cleanup temp directory
if (Directory.Exists(_tempDirectory))
{
try
{
Directory.Delete(_tempDirectory, recursive: true);
}
catch
{
// Ignore cleanup errors
}
}
}
}