-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eee4a5
commit f9c5114
Showing
2 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/Transports/AWS/Wolverine.AmazonSqs.Tests/receive_raw_json.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,89 @@ | ||
using System.Net; | ||
using Amazon.Runtime; | ||
using Amazon.SQS; | ||
using JasperFx.Core; | ||
using Microsoft.Extensions.Hosting; | ||
using Newtonsoft.Json; | ||
using Shouldly; | ||
using Wolverine.Tracking; | ||
|
||
namespace Wolverine.AmazonSqs.Tests | ||
{ | ||
public class receive_raw_json : IAsyncLifetime | ||
{ | ||
private IHost _host; | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
_host = await Host.CreateDefaultBuilder() | ||
.UseWolverine(opts => | ||
{ | ||
opts | ||
.UseAmazonSqsTransportLocally() | ||
.ConfigureListeners(listeners => | ||
{ | ||
listeners.ReceiveNativeJsonMessage(typeof(MyNativeJsonMessage)); | ||
}) | ||
.AutoProvision() | ||
.AutoPurgeOnStartup(); | ||
|
||
opts.ListenToSqsQueue("receive_native_json"); | ||
}) | ||
.StartAsync(); | ||
} | ||
|
||
[Fact] | ||
public async Task receive_native_json_message() | ||
{ | ||
Guid id = Guid.NewGuid(); | ||
|
||
var session = await _host.TrackActivity(2.Minutes()) | ||
.ExecuteAndWaitAsync(_ => SendRawJsonMessage(id, 1.Minutes())); | ||
|
||
session.Received.SingleMessage<MyNativeJsonMessage>().Id.ShouldBe(id); | ||
} | ||
|
||
private static async Task SendRawJsonMessage(Guid id, TimeSpan timeout) | ||
{ | ||
var credentials = new BasicAWSCredentials("ignore", "ignore"); | ||
var cfg = new AmazonSQSConfig | ||
{ | ||
ServiceURL = "http://localhost:4566", | ||
}; | ||
|
||
// create local sqs client | ||
IAmazonSQS sqs = new AmazonSQSClient(credentials, cfg); | ||
|
||
string queueUrl = (await sqs.GetQueueUrlAsync("receive_native_json")).QueueUrl; | ||
|
||
var message = new MyNativeJsonMessage { Id = id }; | ||
string messageBody = JsonConvert.SerializeObject(message); | ||
|
||
// send native message | ||
var sendMessageResponse = await sqs.SendMessageAsync(queueUrl, messageBody); | ||
|
||
((int)sendMessageResponse.HttpStatusCode).ShouldBeGreaterThanOrEqualTo(200, customMessage: "Ensure Success StatusCode"); | ||
((int)sendMessageResponse.HttpStatusCode).ShouldBeLessThan(300, customMessage: "Ensure Success StatusCode"); | ||
|
||
await Task.Delay(timeout); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return _host.StopAsync(); | ||
} | ||
} | ||
|
||
public class MyNativeJsonMessage | ||
{ | ||
public Guid Id { get; set; } = Guid.NewGuid(); | ||
} | ||
|
||
public static class MyNativeJsonMessageHandler | ||
{ | ||
public static void Handle(MyNativeJsonMessage message) | ||
{ | ||
// nothing | ||
} | ||
} | ||
} |
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