コード例 #1
0
            public async Task ShouldStartAndStopATraceWithMessageTraceHeader(
                RequestMessage message,
                [Frozen] IRequestMessageRelay relay,
                [Frozen] ITracingService tracing,
                [Target] DefaultRequestWorker worker,
                CancellationToken cancellationToken
                )
            {
                relay.Receive(Any <CancellationToken>()).Returns(new[] { message });
                await worker.Run(cancellationToken);

                Received.InOrder(() =>
                {
                    tracing.Received().StartTrace(Is(message.RequestDetails.TraceHeader));
                    tracing.Received().AddAnnotation(Is("event"), Is("rest-call"));
                    tracing.Received().EndTrace();
                });
            }
            public async Task ShouldStartAndStopATraceWithMessageAndEventAnnotations(
                string content,
                Snowflake userId,
                Snowflake channelId,
                Snowflake messageId,
                [Frozen, Substitute] ITracingService tracing,
                [Frozen, Substitute] IMessageEmitter emitter,
                [Frozen, Substitute] IUserService userService,
                [Target] MessageCreateEventController controller
                )
            {
                var cancellationToken = new CancellationToken(false);
                var author            = new User {
                    Id = userId
                };
                var message = new Message {
                    Id = messageId, Content = content, Author = author, ChannelId = channelId
                };
                var @event = new MessageCreateEvent {
                    Message = message
                };
                var remoteUserId = new UserId(Guid.NewGuid(), false, true);

                userService.IsUserRegistered(Any <User>(), Any <CancellationToken>()).Returns(true);
                userService.GetIdentityServiceUserId(Any <User>(), Any <CancellationToken>()).Returns(remoteUserId);

                await controller.Handle(@event, cancellationToken);

                Received.InOrder(() =>
                {
                    tracing.Received().StartTrace();
                    tracing.Received().AddAnnotation(Is("event"), Is("incoming-message"));
                    tracing.Received().AddAnnotation(Is("messageId"), Is(messageId.ToString()));
                    tracing.Received().EndTrace();
                });
            }