From 11bca814dd1b5449eeeda05d62dafd487a4ccade Mon Sep 17 00:00:00 2001 From: Mogens Heller Grabe Date: Sun, 13 Oct 2024 10:18:43 +0200 Subject: [PATCH] add the simplest handler in the world example --- ...heMostInterestingHandlerInTheWorldWorks.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Rebus.Tests/Examples/TheMostInterestingHandlerInTheWorldWorks.cs diff --git a/Rebus.Tests/Examples/TheMostInterestingHandlerInTheWorldWorks.cs b/Rebus.Tests/Examples/TheMostInterestingHandlerInTheWorldWorks.cs new file mode 100644 index 000000000..22238716a --- /dev/null +++ b/Rebus.Tests/Examples/TheMostInterestingHandlerInTheWorldWorks.cs @@ -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 + { + public Task Handle(MyMessage message) + { + Console.WriteLine("Receive my message"); + return Task.CompletedTask; + } + } +} \ No newline at end of file