c59a3160d0
Add CreateGiwConnectionAsync to IDbConnectionFactory and DbConnectionFactory for connecting to the GIW Oracle database. This connection is needed for the StatusCode data sync pipeline. - Reuses existing CreateOracleConnectionAsync helper with "GIW" data source - Follows same pattern as JDE, JDEStage, and CMS connections - Includes 4 unit tests covering missing/empty/invalid connection strings
84 lines
2.9 KiB
C#
84 lines
2.9 KiB
C#
using JdeScoping.DataAccess.Exceptions;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSubstitute;
|
|
using Shouldly;
|
|
using Xunit;
|
|
|
|
namespace JdeScoping.DataAccess.Tests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for DbConnectionFactory GIW connection support.
|
|
/// </summary>
|
|
public class DbConnectionFactoryGiwTests
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ILogger<DbConnectionFactory> _logger;
|
|
|
|
public DbConnectionFactoryGiwTests()
|
|
{
|
|
_configuration = Substitute.For<IConfiguration>();
|
|
_logger = Substitute.For<ILogger<DbConnectionFactory>>();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateGiwConnectionAsync_MissingConnectionString_ThrowsConnectionException()
|
|
{
|
|
// Arrange
|
|
_configuration.GetConnectionString("GIW").Returns((string?)null);
|
|
var factory = new DbConnectionFactory(_configuration, _logger);
|
|
|
|
// Act & Assert
|
|
var ex = await Should.ThrowAsync<ConnectionException>(
|
|
async () => await factory.CreateGiwConnectionAsync());
|
|
|
|
ex.DataSource.ShouldBe("GIW");
|
|
ex.Message.ShouldContain("Connection string not found");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateGiwConnectionAsync_EmptyConnectionString_ThrowsConnectionException()
|
|
{
|
|
// Arrange
|
|
_configuration.GetConnectionString("GIW").Returns(string.Empty);
|
|
var factory = new DbConnectionFactory(_configuration, _logger);
|
|
|
|
// Act & Assert
|
|
var ex = await Should.ThrowAsync<ConnectionException>(
|
|
async () => await factory.CreateGiwConnectionAsync());
|
|
|
|
ex.DataSource.ShouldBe("GIW");
|
|
ex.Message.ShouldContain("Connection string not found");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateGiwConnectionAsync_InvalidConnectionString_ThrowsConnectionException()
|
|
{
|
|
// Arrange
|
|
_configuration.GetConnectionString("GIW").Returns("Invalid oracle connection");
|
|
var factory = new DbConnectionFactory(_configuration, _logger);
|
|
|
|
// Act & Assert
|
|
var ex = await Should.ThrowAsync<ConnectionException>(
|
|
async () => await factory.CreateGiwConnectionAsync());
|
|
|
|
ex.DataSource.ShouldBe("GIW");
|
|
ex.Message.ShouldContain("Failed to open connection");
|
|
ex.InnerException.ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateGiwConnectionAsync_CancellationRequested_ThrowsOperationCanceledException()
|
|
{
|
|
// Arrange
|
|
_configuration.GetConnectionString("GIW").Returns("User Id=test;Password=test;Data Source=test");
|
|
var factory = new DbConnectionFactory(_configuration, _logger);
|
|
using var cts = new CancellationTokenSource();
|
|
cts.Cancel();
|
|
|
|
// Act & Assert
|
|
await Should.ThrowAsync<OperationCanceledException>(
|
|
async () => await factory.CreateGiwConnectionAsync(cts.Token));
|
|
}
|
|
}
|