public async Task PublishAsync_should_throw_ArgumentNullException_when_message_null() { var channelFactory = NSubstitute.Substitute.For <IChannelFactory>(); var sut = new InMemoryPublisher(channelFactory); await Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.PublishAsync(null)); }
public async Task StartAsync_CreateSpanWithoutReference_NewSpanIsCreated() { var consumer = new InMemoryConsumer <string>(); var publisher = new InMemoryPublisher <string>(); using var host = GetReverseStringService(consumer, publisher); await host.StartAsync(); await ConsumeMessage(consumer, "test"); Assert.Single(publisher.Events); var ctx = publisher.Events.First().GetActivityContext(); Assert.NotEqual(default, ctx.TraceId);
public async Task PublishAsync_should_write_message_to_proper_channel() { var message = DummyMessage.New(); var channelFactory = NSubstitute.Substitute.For <IChannelFactory>(); var writer = NSubstitute.Substitute.For <ChannelWriter <DummyMessage> >(); channelFactory.GetWriter <DummyMessage>() .Returns(writer); var sut = new InMemoryPublisher(channelFactory); await sut.PublishAsync(message); await writer.Received(1) .WriteAsync(message, Arg.Any <CancellationToken>()); }
StartAsync_SetupAndStartReverseStringServiceAndPublishMessageIntoServiceQueue_MessageInDestinationQueueIsReversed() { var consumer = new InMemoryConsumer <string>(); var publisher = new InMemoryPublisher <string>(); using var host = GetReverseStringService(consumer, publisher); var message = "12345"; await host.StartAsync(); await ConsumeMessage(consumer, message); var actual = Encoding.UTF8.GetString(publisher.Events.First().TypedData); Assert.Equal("54321", actual); await host.StopAsync(); }
public async Task StartAsync_CreateCustomExtension_ExtensionIsPassedThrough() { var consumer = new InMemoryConsumer <string>(); var publisher = new InMemoryPublisher <string>(); using var host = GetReverseStringService(consumer, publisher); await host.StartAsync(); var motorCloudEvent = MotorCloudEvent.CreateTestCloudEvent(Array.Empty <byte>()); motorCloudEvent.SetSomeCustomExtension(DateTimeOffset.MaxValue); await consumer.AddMessage(motorCloudEvent); var receivedCloudEvent = publisher.Events.First(); Assert.Equal(DateTimeOffset.MaxValue, receivedCloudEvent.GetSomeCustomExtension()); await host.StopAsync(); }
public async Task StartAsync_CreateSpanAsReference_ContextIsReferenced() { var consumer = new InMemoryConsumer <string>(); var publisher = new InMemoryPublisher <string>(); using var host = GetReverseStringService(consumer, publisher); await host.StartAsync(); var randomActivity = CreateRandomActivity(); var motorCloudEvent = MotorCloudEvent.CreateTestCloudEvent(Array.Empty <byte>()); motorCloudEvent.SetActivity(randomActivity); await consumer.AddMessage(motorCloudEvent); var ctx = publisher.Events.First().GetActivityContext(); Assert.Equal(randomActivity.Context.TraceId, ctx.TraceId); Assert.NotEqual(randomActivity.Context.SpanId, ctx.SpanId); await host.StopAsync(); }
public static void AddInMemory <T>(this IPublisherBuilder <T> builder, InMemoryPublisher <T> publisher) where T : class { builder.AddPublisher <InMemoryPublisher <T> >(_ => publisher); }