-
-
Notifications
You must be signed in to change notification settings - Fork 97
Fetch the connection string from the connection options #417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d604ad4
Fetch the connection string from the connection options
alexeyzimarev ba217ce
Add tests for SqlServer subscription connection string handling (#410)
alexeyzimarev 3e99ddb
Clean up things
alexeyzimarev 0f2ff83
Trying to make the tests work in CI
alexeyzimarev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
src/SqlServer/test/Eventuous.Tests.SqlServer/Subscriptions/ConnectionStringTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| using Eventuous.SqlServer.Projections; | ||
| using Eventuous.SqlServer.Subscriptions; | ||
| using Eventuous.Subscriptions; | ||
| using Eventuous.Subscriptions.Checkpoints; | ||
| using Eventuous.Subscriptions.Filters; | ||
| using Microsoft.Data.SqlClient; | ||
| using System.Data; | ||
|
|
||
| namespace Eventuous.Tests.SqlServer.Subscriptions; | ||
|
|
||
| /// <summary> | ||
| /// Tests for SqlServerSubscriptionBase connection string handling. | ||
| /// These tests verify the fix for issue #410 where connection strings were not properly resolved. | ||
| /// </summary> | ||
| public class ConnectionStringTests { | ||
| readonly ICheckpointStore _checkpointStore = new NoOpCheckpointStore(); | ||
| readonly ConsumePipe _consumePipe = new(); | ||
| readonly ILoggerFactory _loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); | ||
|
|
||
| [Test] | ||
| public async Task Should_Use_ConnectionOptions_ConnectionString_When_Provided() { | ||
| // Arrange | ||
| const string expectedConnectionString = "Server=localhost;Database=Test1;Trusted_Connection=true;"; | ||
| const string optionsConnectionString = "Server=localhost;Database=Test2;Trusted_Connection=true;"; | ||
|
|
||
| var options = new TestSubscriptionOptions { | ||
| SubscriptionId = "test-subscription-1", | ||
| ConnectionString = optionsConnectionString | ||
| }; | ||
|
|
||
| var connectionOptions = new SqlServerConnectionOptions(expectedConnectionString, "dbo"); | ||
|
|
||
| // Act & Assert - The constructor should not throw an exception | ||
| var subscription = new TestSubscription(options, _checkpointStore, _consumePipe, _loggerFactory, connectionOptions); | ||
|
|
||
| await Assert.That(subscription.IsInitialized).IsTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_Use_Options_ConnectionString_When_ConnectionOptions_Is_Null() { | ||
| // Arrange | ||
| const string expectedConnectionString = "Server=localhost;Database=Test;Trusted_Connection=true;"; | ||
|
|
||
| var options = new TestSubscriptionOptions { | ||
| SubscriptionId = "test-subscription-2", | ||
| ConnectionString = expectedConnectionString | ||
| }; | ||
|
|
||
| // Act & Assert - The constructor should not throw an exception | ||
| var subscription = new TestSubscription(options, _checkpointStore, _consumePipe, _loggerFactory, null); | ||
|
|
||
| await Assert.That(subscription.IsInitialized).IsTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_Use_Options_ConnectionString_When_ConnectionOptions_ConnectionString_Is_Null() { | ||
| // Arrange | ||
| const string expectedConnectionString = "Server=localhost;Database=Test;Trusted_Connection=true;"; | ||
|
|
||
| var options = new TestSubscriptionOptions { | ||
| SubscriptionId = "test-subscription-3", | ||
| ConnectionString = expectedConnectionString | ||
| }; | ||
|
|
||
| var connectionOptions = new SqlServerConnectionOptions(null!, "dbo"); | ||
|
|
||
| // Act & Assert - The constructor should not throw an exception | ||
| var subscription = new TestSubscription(options, _checkpointStore, _consumePipe, _loggerFactory, connectionOptions); | ||
|
|
||
| await Assert.That(subscription.IsInitialized).IsTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_Throw_When_Both_Connection_Strings_Are_Null_Or_Empty() { | ||
| // Arrange | ||
| var options = new TestSubscriptionOptions { | ||
| SubscriptionId = "test-subscription-4", | ||
| ConnectionString = null | ||
| }; | ||
|
|
||
| var connectionOptions = new SqlServerConnectionOptions(null!, "dbo"); | ||
|
|
||
| // Act & Assert | ||
| await Assert.That(() => new TestSubscription(options, _checkpointStore, _consumePipe, _loggerFactory, connectionOptions)).Throws<ArgumentException>(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_Throw_When_Both_Connection_Strings_Are_Empty() { | ||
| // Arrange | ||
| var options = new TestSubscriptionOptions { | ||
| SubscriptionId = "test-subscription-5", | ||
| ConnectionString = "" | ||
| }; | ||
|
|
||
| var connectionOptions = new SqlServerConnectionOptions("", "dbo"); | ||
|
|
||
| // Act & Assert | ||
| await Assert.That(() => new TestSubscription(options, _checkpointStore, _consumePipe, _loggerFactory, connectionOptions)).Throws<ArgumentException>(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_Throw_When_Options_Connection_String_Is_Null_And_No_ConnectionOptions() { | ||
| // Arrange | ||
| var options = new TestSubscriptionOptions { | ||
| SubscriptionId = "test-subscription-6", | ||
| ConnectionString = null | ||
| }; | ||
|
|
||
| // Act & Assert | ||
| await Assert.That(() => new TestSubscription(options, _checkpointStore, _consumePipe, _loggerFactory, null)).Throws<ArgumentException>(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_Throw_When_Options_Connection_String_Is_Empty_And_No_ConnectionOptions() { | ||
| // Arrange | ||
| var options = new TestSubscriptionOptions { | ||
| SubscriptionId = "test-subscription-7", | ||
| ConnectionString = "" | ||
| }; | ||
|
|
||
| // Act & Assert | ||
| await Assert.That(() => new TestSubscription(options, _checkpointStore, _consumePipe, _loggerFactory, null)).Throws<ArgumentException>(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test implementation of SqlServerSubscriptionBase for testing connection string handling | ||
| /// </summary> | ||
| public class TestSubscription( | ||
| TestSubscriptionOptions options, | ||
| ICheckpointStore checkpointStore, | ||
| ConsumePipe consumePipe, | ||
| ILoggerFactory loggerFactory, | ||
| SqlServerConnectionOptions? connectionOptions | ||
| ) | ||
| : SqlServerSubscriptionBase<TestSubscriptionOptions>( | ||
| options, | ||
| checkpointStore, | ||
| consumePipe, | ||
| SubscriptionKind.All, | ||
| loggerFactory, | ||
| null, | ||
| null, | ||
| connectionOptions | ||
| ) { | ||
| public bool IsInitialized { get; } = true; | ||
|
|
||
| protected override SqlCommand PrepareCommand(SqlConnection connection, long start) { | ||
| var command = connection.CreateCommand(); | ||
| command.CommandType = CommandType.Text; | ||
| command.CommandText = "SELECT TOP 0 MessageId, MessageType, StreamPosition, GlobalPosition, JsonData, JsonMetadata, Created, StreamName FROM dbo.Messages WHERE GlobalPosition > @start"; | ||
| command.Parameters.Add("@start", SqlDbType.BigInt).Value = start; | ||
| return command; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test subscription options for testing connection string handling | ||
| /// </summary> | ||
| public record TestSubscriptionOptions : SqlServerSubscriptionBaseOptions; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.