Skip to content

Commit

Permalink
Updated interface to include Async events. (#353)
Browse files Browse the repository at this point in the history
* Updated interface to include Async events.

* Updated Mocks

* Formatting fix

* More adjustments
  • Loading branch information
sspates authored Jan 24, 2024
1 parent 6b22255 commit 470e9df
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/NATS.Client.Core/INatsConnection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
using System.Diagnostics.CodeAnalysis;

namespace NATS.Client.Core;

public interface INatsConnection : IAsyncDisposable
{
event AsyncEventHandler<NatsEventArgs>? ConnectionDisconnected;

event AsyncEventHandler<NatsEventArgs>? ConnectionOpened;

event AsyncEventHandler<NatsEventArgs>? ReconnectFailed;

event AsyncEventHandler<NatsMessageDroppedEventArgs>? MessageDropped;

INatsServerInfo? ServerInfo { get; }

NatsOpts Opts { get; }
Expand Down
4 changes: 0 additions & 4 deletions tests/NATS.Client.Core.Tests/NatsConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,6 @@ public void InterfaceShouldHaveSamePublicPropertiesEventsAndMethodAsClass()
{
var name = classInfo.Name;

// TODO: enable this check when we have events pulled up to the interface
if (Regex.IsMatch(name, @"add_|remove_"))
continue;

interfaceMethods.Select(m => m.Name).Should().Contain(name);
}
}
Expand Down
29 changes: 26 additions & 3 deletions tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NATS.Client.Core.Tests;
using NATS.Client.JetStream.Models;

namespace NATS.Client.JetStream.Tests;

Expand Down Expand Up @@ -83,6 +82,14 @@ public void Create_Context_WithMockConnection_Test()

public class MockConnection : INatsConnection
{
public event AsyncEventHandler<NatsEventArgs>? ConnectionDisconnected;

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

Check warning on line 85 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionDisconnected' is never used

public event AsyncEventHandler<NatsEventArgs>? ConnectionOpened;

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

Check warning on line 87 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ConnectionOpened' is never used

public event AsyncEventHandler<NatsEventArgs>? ReconnectFailed;

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

Check warning on line 89 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.ReconnectFailed' is never used

public event AsyncEventHandler<NatsMessageDroppedEventArgs>? MessageDropped;

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

Check warning on line 91 in tests/NATS.Client.JetStream.Tests/NatsJsContextFactoryTest.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

The event 'NatsJSContextFactoryTest.MockConnection.MessageDropped' is never used

public INatsServerInfo? ServerInfo { get; } = null;

public NatsOpts Opts { get; } = new();
Expand All @@ -103,10 +110,26 @@ public class MockConnection : INatsConnection

public string NewInbox() => throw new NotImplementedException();

public ValueTask<NatsMsg<TReply>> RequestAsync<TRequest, TReply>(string subject, TRequest? data, NatsHeaders? headers = default, INatsSerialize<TRequest>? requestSerializer = default, INatsDeserialize<TReply>? replySerializer = default, NatsPubOpts? requestOpts = default, NatsSubOpts? replyOpts = default, CancellationToken cancellationToken = default)
public ValueTask<NatsMsg<TReply>> RequestAsync<TRequest, TReply>(
string subject,
TRequest? data,
NatsHeaders? headers = default,
INatsSerialize<TRequest>? requestSerializer = default,
INatsDeserialize<TReply>? replySerializer = default,
NatsPubOpts? requestOpts = default,
NatsSubOpts? replyOpts = default,
CancellationToken cancellationToken = default)
=> throw new NotImplementedException();

public IAsyncEnumerable<NatsMsg<TReply>> RequestManyAsync<TRequest, TReply>(string subject, TRequest? data, NatsHeaders? headers = default, INatsSerialize<TRequest>? requestSerializer = default, INatsDeserialize<TReply>? replySerializer = default, NatsPubOpts? requestOpts = default, NatsSubOpts? replyOpts = default, CancellationToken cancellationToken = default)
public IAsyncEnumerable<NatsMsg<TReply>> RequestManyAsync<TRequest, TReply>(
string subject,
TRequest? data,
NatsHeaders? headers = default,
INatsSerialize<TRequest>? requestSerializer = default,
INatsDeserialize<TReply>? replySerializer = default,
NatsPubOpts? requestOpts = default,
NatsSubOpts? replyOpts = default,
CancellationToken cancellationToken = default)
=> throw new NotImplementedException();

public ValueTask ConnectAsync() => throw new NotImplementedException();
Expand Down

0 comments on commit 470e9df

Please sign in to comment.