Skip to content

Commit

Permalink
Added a simple test
Browse files Browse the repository at this point in the history
Signed-off-by: Whit Waldo <[email protected]>
  • Loading branch information
WhitWaldo committed Dec 3, 2024
1 parent b2ab6ea commit d48a85e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ internal async Task WriteMessageToChannelAsync(TopicMessage message)
await topicMessagesChannel.Writer.WriteAsync(message);
}

//Exposed for testing purposes only
internal async Task WriteAcknowledgementToChannelAsync(TopicAcknowledgement acknowledgement)
{
await acknowledgementsChannel.Writer.WriteAsync(acknowledgement);
}

private static void HandleTaskCompletion(Task task, object? state)
//Exposed for testing purposes only
internal static void HandleTaskCompletion(Task task, object? state)
{
if (task.Exception != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,16 @@ public async Task DisposeAsync_ShouldCompleteChannels()
Assert.True(receiver.TopicMessagesChannelCompletion.IsCompleted);
Assert.True(receiver.AcknowledgementsChannelCompletion.IsCompleted);
}

[Fact]
public void HandleTaskCompletion_ShouldThrowException_WhenTaskHasException()
{
var task = Task.FromException(new InvalidOperationException("Test exception"));

var exception = Assert.Throws<AggregateException>(() =>
PublishSubscribeReceiver.HandleTaskCompletion(task, null));

Assert.IsType<InvalidOperationException>(exception.InnerException);
Assert.Equal("Test exception", exception.InnerException.Message);
}
}

0 comments on commit d48a85e

Please sign in to comment.