Skip to content

Commit

Permalink
add the simplest handler in the world example
Browse files Browse the repository at this point in the history
  • Loading branch information
mookid8000 committed Oct 13, 2024
1 parent e80aa2e commit 11bca81
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Rebus.Tests/Examples/TheMostInterestingHandlerInTheWorldWorks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using Rebus.Activation;
using Rebus.Config;
using Rebus.Handlers;
using Rebus.Tests.Contracts;
using Rebus.Tests.Contracts.Utilities;
using Rebus.Transport.InMem;

namespace Rebus.Tests.Examples;

[TestFixture]
public class TheMostInterestingHandlerInTheWorldWorks : FixtureBase
{
[Test]
public async Task OfCourseHandlerCanBeSimpleLikeThis()
{
var logs = new ListLoggerFactory();

using var activator = new BuiltinHandlerActivator();

activator.Register(() => new TheMostInterestingHandlerInTheWorld());

var bus = Configure.With(activator)
.Logging(l => l.Use(logs))
.Transport(t => t.UseInMemoryTransport(new(), "whatever"))
.Start();

await bus.SendLocal(new MyMessage());

// wait a short while
await Task.Delay(TimeSpan.FromSeconds(1));

Assert.That(logs.Select(line => line.Text), Does.Not.Contain("InvalidOperationException"));
}

record MyMessage;

class TheMostInterestingHandlerInTheWorld : IHandleMessages<MyMessage>
{
public Task Handle(MyMessage message)
{
Console.WriteLine("Receive my message");
return Task.CompletedTask;
}
}
}

0 comments on commit 11bca81

Please sign in to comment.