Skip to content

Commit

Permalink
Able to handle variables named "@event" in codegen. Closes GH-298
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy D. Miller authored and Jeremy D. Miller committed Apr 11, 2023
1 parent 5c84776 commit 939dc2d
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/Http/Wolverine.Http.Tests/Bugs/bug_298_variable_named_event.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Shouldly;
using WolverineWebApi.Bugs;

namespace Wolverine.Http.Tests.Bugs;

public class bug_298_variable_named_event : IntegrationContext
{
public bug_298_variable_named_event(AppFixture fixture) : base(fixture)
{
}

[Fact]
public async Task do_not_blow_up()
{
var (tracked, result) = await TrackedHttpCall(x =>
{
x.Post.Json(new TelegramUpdated("foo")).ToUrl("/convert-book");
});

tracked.Executed.SingleMessage<TelegramUpdated>()
.Name.ShouldBe("foo");
}
}
27 changes: 27 additions & 0 deletions src/Http/WolverineWebApi/Bugs/ConvertBookEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics;
using Wolverine;
using Wolverine.Http;

namespace WolverineWebApi.Bugs;

public class ConvertBookEndpoint
{
[WolverinePost("/convert-book")]
public static async Task Post(
TelegramUpdated @event,
IMessageBus bus,
CancellationToken token)
{
await bus.InvokeAsync(@event, token);
}
}

public record TelegramUpdated(string Name);

public static class TelegramUpdatedHandler
{
public static void Handle(TelegramUpdated updated)
{
Debug.WriteLine("Got TelegramUpdated with name " + updated.Name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// <auto-generated/>
#pragma warning disable
using Microsoft.AspNetCore.Routing;
using System;
using System.Linq;
using Wolverine.Http;
using Wolverine.Runtime;

namespace Internal.Generated.WolverineHandlers
{
// START: POST_convert_book
public class POST_convert_book : Wolverine.Http.HttpHandler
{
private readonly Wolverine.Http.WolverineHttpOptions _options;
private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime;

public POST_convert_book(Wolverine.Http.WolverineHttpOptions options, Wolverine.Runtime.IWolverineRuntime wolverineRuntime) : base(options)
{
_options = options;
_wolverineRuntime = wolverineRuntime;
}



public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext)
{
var (@event, jsonContinue) = await ReadJsonAsync<WolverineWebApi.Bugs.TelegramUpdated>(httpContext);
if (jsonContinue == Wolverine.HandlerContinuation.Stop) return;
var messageContext = new Wolverine.Runtime.MessageContext(_wolverineRuntime);
await WolverineWebApi.Bugs.ConvertBookEndpoint.Post(@event, ((Wolverine.IMessageBus)messageContext), httpContext.RequestAborted).ConfigureAwait(false);
}

}

// END: POST_convert_book


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// <auto-generated/>
#pragma warning disable

namespace Internal.Generated.WolverineHandlers
{
// START: TelegramUpdatedHandler96651444
public class TelegramUpdatedHandler96651444 : Wolverine.Runtime.Handlers.MessageHandler
{


public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation)
{
var telegramUpdated = (WolverineWebApi.Bugs.TelegramUpdated)context.Envelope.Message;
WolverineWebApi.Bugs.TelegramUpdatedHandler.Handle(telegramUpdated);
return System.Threading.Tasks.Task.CompletedTask;
}

}

// END: TelegramUpdatedHandler96651444


}

4 changes: 2 additions & 2 deletions src/Wolverine/Wolverine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="7.0.0" />
<PackageReference Include="System.ComponentModel" Version="4.3.0" />
<PackageReference Include="JasperFx.CodeGeneration.Commands" Version="2.3.0" />
<PackageReference Include="JasperFx.RuntimeCompiler" Version="2.3.0" />
<PackageReference Include="JasperFx.CodeGeneration.Commands" Version="2.3.1" />
<PackageReference Include="JasperFx.RuntimeCompiler" Version="2.3.1" />
<PackageReference Include="JasperFx.Core" Version="1.2.0" />
</ItemGroup>

Expand Down

0 comments on commit 939dc2d

Please sign in to comment.