4b3c900d52
Add support for "giw" connection type in DbQuerySource to enable the StatusCode pipeline to query from the GIW Oracle database.
96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
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<IDbConnectionFactory>();
|
|
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<IDbConnectionFactory>();
|
|
var source = new DbQuerySource(factory, connectionType, "SELECT 1");
|
|
source.SourceName.ShouldBe($"DbQuery:{connectionType.ToLowerInvariant()}");
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_InvalidConnectionType_Throws()
|
|
{
|
|
var factory = Substitute.For<IDbConnectionFactory>();
|
|
Should.Throw<ArgumentException>(() =>
|
|
new DbQuerySource(factory, "invalid", "SELECT 1"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_NullConnectionType_Throws()
|
|
{
|
|
var factory = Substitute.For<IDbConnectionFactory>();
|
|
Should.Throw<ArgumentNullException>(() =>
|
|
new DbQuerySource(factory, null!, "SELECT 1"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_NullQuery_Throws()
|
|
{
|
|
var factory = Substitute.For<IDbConnectionFactory>();
|
|
Should.Throw<ArgumentNullException>(() =>
|
|
new DbQuerySource(factory, "jde", null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_NullFactory_ThrowsArgumentNullException()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(() => new DbQuerySource(null!, "jde", "SELECT 1"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_WithParameters_Succeeds()
|
|
{
|
|
var factory = Substitute.For<IDbConnectionFactory>();
|
|
var parameters = new Dictionary<string, object>
|
|
{
|
|
{ "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<IDbConnectionFactory>();
|
|
var source = new DbQuerySource(factory, "jde", "SELECT 1", commandTimeout: 7200);
|
|
source.SourceName.ShouldBe("DbQuery:jde");
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_WithGiwConnectionType_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var connectionFactory = Substitute.For<IDbConnectionFactory>();
|
|
|
|
// Act & Assert - should not throw
|
|
var source = new DbQuerySource(connectionFactory, "giw", "SELECT 1", null);
|
|
source.SourceName.ShouldBe("DbQuery:giw");
|
|
}
|
|
}
|