diff --git a/examples/InMemoryUnitTest/SampleEventConsumerTests.cs b/examples/InMemoryUnitTest/SampleEventConsumerTests.cs index 6145aa83..2d3eb5f3 100644 --- a/examples/InMemoryUnitTest/SampleEventConsumerTests.cs +++ b/examples/InMemoryUnitTest/SampleEventConsumerTests.cs @@ -38,8 +38,6 @@ public async Task ConsumerWorksAsync() // Get the publisher and publish the event var publisher = provider.GetRequiredService(); - var id = Guid.NewGuid().ToString(); - var processedOn = DateTimeOffset.UtcNow; await publisher.PublishAsync(new SampleEvent { Make = "TESLA", diff --git a/src/Tingle.EventBus/EventBus.cs b/src/Tingle.EventBus/EventBus.cs index dd383322..23a7db14 100644 --- a/src/Tingle.EventBus/EventBus.cs +++ b/src/Tingle.EventBus/EventBus.cs @@ -84,6 +84,11 @@ public async Task PublishAsync(EventContext @event, CancellationToken cancellationToken = default) where TEvent : class { + if (scheduled != null && scheduled <= DateTimeOffset.UtcNow) + { + throw new ArgumentException("Scheduled time cannot be in the past."); + } + // Instrumentation using var activity = EventBusActivitySource.StartActivity(ActivityNames.Publish, ActivityKind.Producer); activity?.AddTag(ActivityTagNames.EventBusEventType, typeof(TEvent).FullName); @@ -128,6 +133,11 @@ public async Task> PublishAsync(IList CancellationToken cancellationToken = default) where TEvent : class { + if (scheduled != null && scheduled <= DateTimeOffset.UtcNow) + { + throw new ArgumentException("Scheduled time cannot be in the past."); + } + // Instrumentation using var activity = EventBusActivitySource.StartActivity(ActivityNames.Publish, ActivityKind.Producer); activity?.AddTag(ActivityTagNames.EventBusEventType, typeof(TEvent).FullName);