コード例 #1
0
        public async Task Should_not_fail_if_properties_are_already_defined()
        {
            // Arrange.
            var messageId          = Guid.NewGuid();
            var conversationId     = Guid.NewGuid();
            var correlationId      = Guid.NewGuid();
            var requestId          = Guid.NewGuid();
            var inputAddress       = new Uri("http://masstransit-project.com/");
            var destinationAddress = new Uri("sb://my-organization.servicebus.windows.net/MyNamespace/MyMessage");

            var mockReceiveContext = new Mock <ReceiveContext>();

            mockReceiveContext.Setup(c => c.InputAddress).Returns(inputAddress);

            var mockSendContext = new Mock <SendContext <PingMessage> >();

            mockSendContext.Setup(c => c.Headers).Returns(_mockHeaders.Object);
            mockSendContext.Setup(c => c.MessageId).Returns(messageId);
            mockSendContext.Setup(c => c.ConversationId).Returns(conversationId);
            mockSendContext.Setup(c => c.CorrelationId).Returns(correlationId);
            mockSendContext.Setup(c => c.RequestId).Returns(requestId);
            mockSendContext.Setup(c => c.DestinationAddress).Returns(destinationAddress);

            var sendContextProxy = new SendContextProxy <PingMessage>(mockSendContext.Object, new PingMessage());

            var capturedTelemetry = default(DependencyTelemetry);

            var filter = new ApplicationInsightsSendFilter <PingMessage>(new TelemetryClient(), "", "", (holder, context) => capturedTelemetry = holder.Telemetry);

            await filter.Send(sendContextProxy, new Mock <IPipe <SendContext <PingMessage> > >().Object);

            var configuration = TelemetryConfiguration.CreateDefault();

            configuration.TelemetryInitializers.Add(new CopyPropertiesTelemetryInitializer(capturedTelemetry));

            var telemetryClient = new TelemetryClient(configuration);

            filter = new ApplicationInsightsSendFilter <PingMessage>(telemetryClient, "", "", (h, c) => {});

            // Act, Assert
            Assert.That(async() => await filter.Send(sendContextProxy, new Mock <IPipe <SendContext <PingMessage> > >().Object), Throws.Nothing);
        }
コード例 #2
0
        public async Task Should_add_the_expected_properties_to_the_dependency_telemetry()
        {
            // Arrange.
            var messageId          = Guid.NewGuid();
            var conversationId     = Guid.NewGuid();
            var correlationId      = Guid.NewGuid();
            var requestId          = Guid.NewGuid();
            var inputAddress       = new Uri("http://masstransit-project.com/");
            var destinationAddress = new Uri("sb://my-organization.servicebus.windows.net/MyNamespace/MyMessage");

            var mockReceiveContext = new Mock <ReceiveContext>();

            mockReceiveContext.Setup(c => c.InputAddress).Returns(inputAddress);

            var mockSendContext = new Mock <SendContext <PingMessage> >();

            mockSendContext.Setup(c => c.Headers).Returns(_mockHeaders.Object);
            mockSendContext.Setup(c => c.MessageId).Returns(messageId);
            mockSendContext.Setup(c => c.ConversationId).Returns(conversationId);
            mockSendContext.Setup(c => c.CorrelationId).Returns(correlationId);
            mockSendContext.Setup(c => c.RequestId).Returns(requestId);
            mockSendContext.Setup(c => c.DestinationAddress).Returns(destinationAddress);

            var sendContextProxy = new SendContextProxy <PingMessage>(mockSendContext.Object, new PingMessage());

            var capturedTelemetry = default(DependencyTelemetry);

            var filter = new ApplicationInsightsSendFilter <PingMessage>(new TelemetryClient(), "", "", (holder, context) => capturedTelemetry = holder.Telemetry);

            // Act.
            await filter.Send(sendContextProxy, new Mock <IPipe <SendContext <PingMessage> > >().Object);

            // Assert.
            Assert.IsNotNull(capturedTelemetry);
            Assert.AreEqual(capturedTelemetry.Properties["MessageId"], messageId.ToString());
            Assert.AreEqual(capturedTelemetry.Properties["MessageType"], TypeMetadataCache <PingMessage> .ShortName);
            Assert.AreEqual(capturedTelemetry.Properties["ConversationId"], conversationId.ToString());
            Assert.AreEqual(capturedTelemetry.Properties["CorrelationId"], correlationId.ToString());
            Assert.AreEqual(capturedTelemetry.Properties["DestinationAddress"], destinationAddress.ToString());
            Assert.AreEqual(capturedTelemetry.Properties["RequestId"], requestId.ToString());
        }