using JdeScoping.DataAccess.Interfaces; using JdeScoping.DataSync.Etl.Sources; using NSubstitute; using Shouldly; namespace JdeScoping.DataSync.Tests.Etl.Sources; public class DbQuerySourceTests { [Theory] [InlineData("jde")] [InlineData("cms")] [InlineData("lotfinder")] public void Constructor_ValidConnectionType_Succeeds(string connectionType) { var factory = Substitute.For(); var source = new DbQuerySource(factory, connectionType, "SELECT 1"); source.SourceName.ShouldBe($"DbQuery:{connectionType}"); } [Theory] [InlineData("JDE")] [InlineData("CMS")] [InlineData("LotFinder")] [InlineData("LOTFINDER")] public void Constructor_ConnectionType_IsCaseInsensitive(string connectionType) { var factory = Substitute.For(); var source = new DbQuerySource(factory, connectionType, "SELECT 1"); source.SourceName.ShouldBe($"DbQuery:{connectionType.ToLowerInvariant()}"); } [Fact] public void Constructor_InvalidConnectionType_Throws() { var factory = Substitute.For(); Should.Throw(() => new DbQuerySource(factory, "invalid", "SELECT 1")); } [Fact] public void Constructor_NullConnectionType_Throws() { var factory = Substitute.For(); Should.Throw(() => new DbQuerySource(factory, null!, "SELECT 1")); } [Fact] public void Constructor_NullQuery_Throws() { var factory = Substitute.For(); Should.Throw(() => new DbQuerySource(factory, "jde", null!)); } [Fact] public void Constructor_NullFactory_ThrowsArgumentNullException() { Assert.Throws(() => new DbQuerySource(null!, "jde", "SELECT 1")); } [Fact] public void Constructor_WithParameters_Succeeds() { var factory = Substitute.For(); var parameters = new Dictionary { { "MinDate", DateTime.Now }, { "Status", 1 } }; var source = new DbQuerySource(factory, "lotfinder", "SELECT * FROM T WHERE Date > @MinDate AND Status = @Status", parameters); source.SourceName.ShouldBe("DbQuery:lotfinder"); } [Fact] public void Constructor_WithCustomTimeout_Succeeds() { var factory = Substitute.For(); var source = new DbQuerySource(factory, "jde", "SELECT 1", commandTimeout: 7200); source.SourceName.ShouldBe("DbQuery:jde"); } }