test(configmanager): expand unit test coverage to 451 tests
Add comprehensive tests for services (ConnectionTestService, RuntimeConfigValidation), ViewModels (PipelineEditor, dialogs, transformers), and Avalonia headless UI tests for views and forms.
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
using JdeScoping.ConfigManager.Models;
|
||||
using JdeScoping.ConfigManager.Services;
|
||||
|
||||
namespace JdeScoping.ConfigManager.Tests.Services;
|
||||
|
||||
public class ConnectionTestServiceTests
|
||||
{
|
||||
private readonly ConnectionTestService _sut;
|
||||
|
||||
public ConnectionTestServiceTests()
|
||||
{
|
||||
_sut = new ConnectionTestService();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestConnectionAsync_Oracle_ReturnsNotImplemented()
|
||||
{
|
||||
// Arrange
|
||||
var connectionString = "Data Source=oracle;User Id=user;Password=pass;";
|
||||
|
||||
// Act
|
||||
var result = await _sut.TestConnectionAsync(connectionString, ConnectionProvider.Oracle);
|
||||
|
||||
// Assert
|
||||
result.Success.ShouldBeFalse();
|
||||
result.Message.ShouldContain("not implemented");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestConnectionAsync_Generic_ReturnsCannotTest()
|
||||
{
|
||||
// Arrange
|
||||
var connectionString = "SomeGenericConnectionString";
|
||||
|
||||
// Act
|
||||
var result = await _sut.TestConnectionAsync(connectionString, ConnectionProvider.Generic);
|
||||
|
||||
// Assert
|
||||
result.Success.ShouldBeFalse();
|
||||
result.Message.ShouldContain("Cannot test generic");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestConnectionAsync_UnknownProvider_ReturnsUnknownProviderError()
|
||||
{
|
||||
// Arrange
|
||||
var connectionString = "Data Source=test";
|
||||
var unknownProvider = (ConnectionProvider)999;
|
||||
|
||||
// Act
|
||||
var result = await _sut.TestConnectionAsync(connectionString, unknownProvider);
|
||||
|
||||
// Assert
|
||||
result.Success.ShouldBeFalse();
|
||||
result.Message.ShouldContain("Unknown provider");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestConnectionAsync_SqlServer_WithInvalidConnectionString_ReturnsFailure()
|
||||
{
|
||||
// Arrange - Use an obviously invalid connection string that will fail fast
|
||||
var connectionString = "Server=nonexistent-server-that-does-not-exist-12345;Database=TestDb;Integrated Security=true;Connect Timeout=1;";
|
||||
|
||||
// Act
|
||||
var result = await _sut.TestConnectionAsync(connectionString, ConnectionProvider.SqlServer);
|
||||
|
||||
// Assert
|
||||
result.Success.ShouldBeFalse();
|
||||
result.Message.ShouldNotBeNullOrEmpty();
|
||||
result.Duration.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestConnectionAsync_SqlServer_MeasuresDuration()
|
||||
{
|
||||
// Arrange - Use an invalid connection string that will fail but should still measure duration
|
||||
var connectionString = "Server=nonexistent-server-12345;Database=TestDb;Integrated Security=true;Connect Timeout=1;";
|
||||
|
||||
// Act
|
||||
var result = await _sut.TestConnectionAsync(connectionString, ConnectionProvider.SqlServer);
|
||||
|
||||
// Assert
|
||||
result.Duration.ShouldNotBeNull();
|
||||
result.Duration!.Value.ShouldBeGreaterThan(TimeSpan.Zero);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestConnectionAsync_SqlServer_WithCancellation_ReturnsCancelledResult()
|
||||
{
|
||||
// Arrange
|
||||
var connectionString = "Server=nonexistent-server-that-takes-forever-12345;Database=TestDb;Integrated Security=true;Connect Timeout=30;";
|
||||
using var cts = new CancellationTokenSource();
|
||||
cts.Cancel(); // Cancel immediately
|
||||
|
||||
// Act
|
||||
var result = await _sut.TestConnectionAsync(connectionString, ConnectionProvider.SqlServer, cts.Token);
|
||||
|
||||
// Assert
|
||||
result.Success.ShouldBeFalse();
|
||||
result.Message.ShouldContain("cancelled");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestConnectionAsync_SqlServer_WithMalformedConnectionString_ReturnsFailure()
|
||||
{
|
||||
// Arrange - Malformed connection string should be handled gracefully
|
||||
var connectionString = "not a valid connection string at all!!!";
|
||||
|
||||
// Act
|
||||
var result = await _sut.TestConnectionAsync(connectionString, ConnectionProvider.SqlServer);
|
||||
|
||||
// Assert
|
||||
result.Success.ShouldBeFalse();
|
||||
result.Message.ShouldNotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestConnectionAsync_SqlServer_WithEmptyConnectionString_ReturnsFailure()
|
||||
{
|
||||
// Arrange
|
||||
var connectionString = "";
|
||||
|
||||
// Act
|
||||
var result = await _sut.TestConnectionAsync(connectionString, ConnectionProvider.SqlServer);
|
||||
|
||||
// Assert
|
||||
result.Success.ShouldBeFalse();
|
||||
result.Message.ShouldNotBeNullOrEmpty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user