-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for StorageBus MessageStateHandler
- Loading branch information
niklasarbin
committed
Apr 15, 2024
1 parent
b4f2ce1
commit 688061a
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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
57 changes: 57 additions & 0 deletions
57
...e/tests/KnightBus.Azure.Storage.Tests.Integration/StorageQueueMessageStateHandlerTests.cs
This file contains 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,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using KnightBus.Azure.Storage.Management; | ||
using KnightBus.Core; | ||
using KnightBus.Core.PreProcessors; | ||
using KnightBus.Newtonsoft; | ||
using KnightBus.Shared.Tests.Integration; | ||
using NUnit.Framework; | ||
|
||
namespace KnightBus.Azure.Storage.Tests.Integration; | ||
|
||
[TestFixture] | ||
public class StorageQueueMessageStateHandlerTests : MessageStateHandlerTests<TestCommand> | ||
{ | ||
private readonly StorageBusConfiguration _configuration = new("UseDevelopmentStorage=true"); | ||
public override async Task Setup() | ||
{ | ||
var queueManager = new StorageQueueManager(_configuration, Array.Empty<IMessagePreProcessor>()); | ||
|
||
var queues = await queueManager.List(CancellationToken.None); | ||
foreach (var queue in queues) | ||
{ | ||
await queueManager.Delete(queue.Name, CancellationToken.None); | ||
} | ||
} | ||
|
||
protected override async Task<List<TestCommand>> GetMessages(int count) | ||
{ | ||
var qc = new StorageQueueClient(_configuration, _configuration.MessageSerializer, Array.Empty<IMessagePreProcessor>(), AutoMessageMapper.GetQueueName<TestCommand>()); | ||
var messages = await qc.PeekMessagesAsync<TestCommand>(count); | ||
return messages.Select(m => (TestCommand)m.Message).ToList(); | ||
} | ||
|
||
protected override async Task<List<TestCommand>> GetDeadLetterMessages(int count) | ||
{ | ||
var qc = new StorageQueueClient(_configuration, _configuration.MessageSerializer, Array.Empty<IMessagePreProcessor>(), AutoMessageMapper.GetQueueName<TestCommand>()); | ||
var messages = await qc.PeekDeadLettersAsync<TestCommand>(count); | ||
return messages.Select(m => (TestCommand)m.Message).ToList(); | ||
} | ||
|
||
protected override async Task SendMessage(string message) | ||
{ | ||
var client = new StorageQueueClient(_configuration, new NewtonsoftSerializer(), Array.Empty<IMessagePreProcessor>(), AutoMessageMapper.GetQueueName<TestCommand>()); | ||
await client.CreateIfNotExistsAsync(); | ||
await client.SendAsync(new TestCommand { Message = message }, TimeSpan.Zero, CancellationToken.None); | ||
} | ||
|
||
protected override async Task<IMessageStateHandler<TestCommand>> GetMessageStateHandler() | ||
{ | ||
var client = new StorageQueueClient(_configuration, new NewtonsoftSerializer(), Array.Empty<IMessagePreProcessor>(), AutoMessageMapper.GetQueueName<TestCommand>()); | ||
var message = await client.GetMessagesAsync<TestCommand>(1, TimeSpan.FromSeconds(5)); | ||
return new StorageQueueMessageStateHandler<TestCommand>(client, message.First(), 5, null); | ||
} | ||
} |
This file contains 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