Skip to content

Commit

Permalink
added (failing) e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian.weber authored and jeremydmiller committed Sep 18, 2023
1 parent 1eee4a5 commit f9c5114
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
89 changes: 89 additions & 0 deletions src/Transports/AWS/Wolverine.AmazonSqs.Tests/receive_raw_json.cs
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
}
}
}
2 changes: 1 addition & 1 deletion src/Wolverine/Tracking/TrackedSessionConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Wolverine.Runtime;
using Wolverine.Runtime.RemoteInvocation;
Expand Down

0 comments on commit f9c5114

Please sign in to comment.