public void GivenActivityTypeOtherThanMessage_WhenBuildIsInvoked_ThenEventTelemetryIsBeingCreated(
            string activityType,
            string expectedTelemetryName,
            InstrumentationSettings settings,
            IFixture fixture)
        {
            // Arrange
            var activity = new Activity
            {
                Type      = activityType,
                ChannelId = fixture.Create <string>(),
                Timestamp = DateTimeOffset.MinValue
            };
            var       builder = new EventTelemetryBuilder(activity, settings);
            const int expectedNumberOfTelemetryProperties = 3;

            // Act
            var eventTelemetry = builder.Build();

            // Assert
            eventTelemetry.Name.Should().Be(expectedTelemetryName);
            eventTelemetry.Properties.Count.Should().Be(expectedNumberOfTelemetryProperties);
            eventTelemetry.Properties[BotConstants.TypeProperty].Should().Be(activity.Type);
            eventTelemetry.Properties[BotConstants.TimestampProperty].Should().Be(activity.Timestamp.Value.AsIso8601());
            eventTelemetry.Properties[BotConstants.ChannelProperty].Should().Be(activity.ChannelId);
        }
        public BotFrameworkApplicationInsightsInstrumentation(InstrumentationSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (settings.InstrumentationKeys == null || settings.InstrumentationKeys.Count == 0)
            {
                throw new ArgumentException("Settings must contain at least one instrumentation key");
            }
            _settings = settings;

            //init clients
            _telemetryClients = new List <TelemetryClient>();
            _settings.InstrumentationKeys.ForEach(key =>
            {
                _telemetryClients.Add(new TelemetryClient(new TelemetryConfiguration(key)));
            });

            // Register activity logger via autofac DI.
            Conversation.UpdateContainer(builder =>
            {
                builder.RegisterType <DialogActivityLogger>().As <IActivityLogger>().InstancePerLifetimeScope();
                builder.RegisterInstance <IBotFrameworkInstrumentation>(this).As <IBotFrameworkInstrumentation>()
                .SingleInstance();
            });
        }
Esempio n. 3
0
        public async void GIVENTurnContext_WHENUpdateActivityInvoked_THENEventTelemetryIsBeingSent(
            InstrumentationSettings settings,
            ITurnContext turnContext,
            IFixture fixture)
        {
            // Arrange
            var instrumentation = new BotInstrumentationMiddleware(this.telemetryClient, settings);
            var activity        = new Activity
            {
                Type      = ActivityTypes.ConversationUpdate,
                ChannelId = fixture.Create <string>(),
            };

            Mock.Get(turnContext)
            .Setup(c => c.OnUpdateActivity(It.IsAny <UpdateActivityHandler>()))
            .Callback <UpdateActivityHandler>(h => h(null, activity, () =>
                                                     Task.FromResult((ResourceResponse)null)));
            const int    expectedNumberOfTelemetryProperties = 2;
            const string expectedTelemetryName = EventTypes.ConversationUpdate;

            // Act
            await instrumentation.OnTurnAsync(turnContext, null)
            .ConfigureAwait(false);

            // Assert
            this.mockTelemetryChannel.Verify(
                tc => tc.Send(It.Is <EventTelemetry>(t =>
                                                     t.Name == expectedTelemetryName &&
                                                     t.Properties.Count == expectedNumberOfTelemetryProperties &&
                                                     t.Properties[BotConstants.TypeProperty] == activity.Type &&
                                                     t.Properties[BotConstants.ChannelProperty] == activity.ChannelId)),
                Times.Once);
        }
        public void GIVENActivityTypeOtherThanMessage_WHENBuildIsInvoked_THENEventTelemetryIsBeingCreated(
            string activityType,
            string expectedTelemetryName,
            InstrumentationSettings settings,
            IFixture fixture)
        {
            // Arrange
            var activity = new Activity
            {
                Type             = activityType,
                ChannelId        = fixture.Create <string>(),
                TimeStampIso8601 = DateTime.MinValue.ToString(CultureInfo.CurrentCulture),
            };
            var       builder = new EventTelemetryBuilder(activity, settings);
            const int expectedNumberOfTelemetryProperties = 3;

            // Act
            var eventTelemetry = builder.Build();

            // Assert
            eventTelemetry.Name.Should().Be(expectedTelemetryName);
            eventTelemetry.Properties.Count.Should().Be(expectedNumberOfTelemetryProperties);
            eventTelemetry.Properties[BotConstants.TypeProperty].Should().Be(activity.Type);
            eventTelemetry.Properties[BotConstants.TimestampProperty].Should().Be(activity.TimeStampIso8601);
            eventTelemetry.Properties[BotConstants.ChannelProperty].Should().Be(activity.ChannelId);
        }
        public void GivenMessageTypeActivityAndReplyToId_WhenBuildIsInvoked_ThenEventTelemetryIsBeingCreated(
            InstrumentationSettings settings,
            IFixture fixture)
        {
            // Arrange
            var activity = new Activity
            {
                Type         = ActivityTypes.Message,
                ChannelId    = fixture.Create <string>(),
                ReplyToId    = fixture.Create <string>(),
                Text         = fixture.Create <string>(),
                Conversation = new ConversationAccount {
                    Id = fixture.Create <string>()
                }
            };
            var          builder = new EventTelemetryBuilder(activity, settings);
            const int    expectedNumberOfTelemetryProperties = 4;
            const string expectedTelemetryName = EventTypes.MessageSent;

            // Act
            var eventTelemetry = builder.Build();

            // Assert
            eventTelemetry.Name.Should().Be(expectedTelemetryName);
            eventTelemetry.Properties.Count.Should().Be(expectedNumberOfTelemetryProperties);
            eventTelemetry.Properties[BotConstants.TypeProperty].Should().Be(activity.Type);
            eventTelemetry.Properties[BotConstants.TextProperty].Should().Be(activity.Text);
            eventTelemetry.Properties[BotConstants.ConversationIdProperty].Should().Be(activity.Conversation.Id);
            eventTelemetry.Properties[BotConstants.ChannelProperty].Should().Be(activity.ChannelId);
        }
Esempio n. 6
0
 public SentimentInstrumentationMiddleware(
     TelemetryClient telemetryClient,
     ISentimentClient sentimentClient,
     InstrumentationSettings instrumentationSettings)
 {
     this.sentimentClient          = sentimentClient ?? throw new ArgumentNullException(nameof(sentimentClient));
     this.sentimentInstrumentation = new SentimentInstrumentation(this.sentimentClient, telemetryClient, instrumentationSettings);
 }
Esempio n. 7
0
        public void GIVENEmptySettings_WHENCustomInstrumentationIsConstructed_THENExceptionIsBeingThrown()
        {
            // Arrange
            const InstrumentationSettings emptySettings = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new CustomInstrumentation(this.telemetryClient, emptySettings));
        }
Esempio n. 8
0
        public void GivenEmptySettings_WhenQnAInstrumentationIsConstructed_ThenExceptionIsBeingThrown()
        {
            // Arrange
            const InstrumentationSettings emptySettings = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new QnAInstrumentation(this.telemetryClient, emptySettings));
        }
        public void GIVENEmptySettings_WHENEventTelemetryBuilderIsConstructed_THENExceptionIsBeingThrown(
            IActivityAdapter activity)
        {
            // Arrange
            const InstrumentationSettings emptySettings = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new EventTelemetryBuilder(activity, emptySettings));
        }
Esempio n. 10
0
 public SentimentInstrumentationMiddleware(
     TelemetryClient telemetryClient,
     ITextAnalyticsClient textAnalyticsClient,
     InstrumentationSettings instrumentationSettings)
     : this(
         telemetryClient,
         new SentimentClient(textAnalyticsClient),
         instrumentationSettings)
 {
 }
Esempio n. 11
0
        public void GivenEmptyInstrumentationSettingsAndAnySentimentClientSettings_WhenSentimentInstrumentationMiddlewareSettingsIsConstructed_ThenExceptionIsBeingThrown(
            SentimentClientSettings sentimentClientSettings)
        {
            // Arrange
            const InstrumentationSettings emptyInstrumentationSettings = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new SentimentInstrumentationMiddlewareSettings(emptyInstrumentationSettings, sentimentClientSettings));
        }
        public void GIVENEmptyActivity_WHENTrackCustomEventIsInvoked_THENExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            const IActivityAdapter emptyActivity = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => emptyActivity.TrackCustomEvent(this.telemetryClient, settings));
        }
        public void GivenAnyTelemetryClientAnySettingsAndEmptySentimentClient_WhenSentimentInstrumentationMiddlewareIsConstructed_ThenExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            const ISentimentClient emptySentimentClient = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new SentimentInstrumentationMiddleware(this.telemetryClient, emptySentimentClient, settings));
        }
Esempio n. 14
0
        public void GivenEmptyTelemetryClient_WhenQnAInstrumentationIsConstructed_ThenExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            const TelemetryClient emptyTelemetryClient = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new QnAInstrumentation(emptyTelemetryClient, settings));
        }
        public void GivenEmptyActivity_WhenEventTelemetryBuilderIsConstructed_ThenExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            const IActivity emptyActivity = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new EventTelemetryBuilder(emptyActivity, settings));
        }
        public void GIVENAnyInstrumentationSettingsAndEmptySentimentClientSettings__WHENSentimentInstrumentationMiddlewareSettingsIsConstructed__THENExceptionIsBeingThrown(
            InstrumentationSettings instrumentationSettings)
        {
            // Arrange
            const SentimentClientSettings emptySentimentClientSettings = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new SentimentInstrumentationMiddlewareSettings(instrumentationSettings, emptySentimentClientSettings));
        }
Esempio n. 17
0
        public void GIVENEmptyTelemetryClient_WHENCustomInstrumentationIsConstructed_THENExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            const TelemetryClient emptyTelemetryClient = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new CustomInstrumentation(emptyTelemetryClient, settings));
        }
Esempio n. 18
0
        public void GIVENEmptySentimentClient_WHENSentimentInstrumentationIsConstructed_THENExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            const ISentimentClient emptySentimentClient = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new SentimentInstrumentation(settings, this.telemetryClient, emptySentimentClient));
        }
        public void GIVENAnyTelemetryClientEmptySettingsAndAnySentimentClient_WHENSentimentInstrumentationMiddlewareIsConstructed_THENExceptionIsBeingThrown(
            ISentimentClient sentimentClient)
        {
            // Arrange
            const InstrumentationSettings emptySettings = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new SentimentInstrumentationMiddleware(this.telemetryClient, sentimentClient, emptySettings));
        }
        public void GIVENEmptyTelemetryClientAnySettingsAndAnyTextAnalyticsClient_WHENSentimentInstrumentationMiddlewareIsConstructed_THENExceptionIsBeingThrown(
            InstrumentationSettings settings,
            ITextAnalyticsClient textAnalyticsClient)
        {
            // Arrange
            const TelemetryClient emptyTelemetryClient = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new SentimentInstrumentationMiddleware(emptyTelemetryClient, textAnalyticsClient, settings));
        }
Esempio n. 21
0
        public void GivenEmptyActivity_WhenTrackCustomEventIsInvoked_ThenExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            var             instrumentation = new CustomInstrumentation(this.telemetryClient, settings);
            const IActivity emptyActivity   = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => instrumentation.TrackCustomEvent(emptyActivity));
        }
        public void GIVENEmptySettings_WHENActivityInstrumentationIsConstructed_THENExceptionIsBeingThrown(
            TelemetryClient emptyTelemetryClient)
        {
            // Arrange
            const InstrumentationSettings emptySettings = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  new ActivityInstrumentation(emptyTelemetryClient, emptySettings));
        }
Esempio n. 23
0
        public void GivenEmptyQueryResult_WhenTrackEventIsInvoked_ThenExceptionIsBeingThrown(
            IMessageActivity activity,
            InstrumentationSettings settings)
        {
            // Arrange
            var instrumentation = new QnAInstrumentation(this.telemetryClient, settings);
            const QueryResult emptyQueryResult = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => instrumentation.TrackEvent(activity, emptyQueryResult));
        }
        public async void GIVENEmptyActivity_WHENTrackMessageSentimentIsInvoked_THENExceptionIsBeingThrown(
            ISentimentClient sentimentClient,
            InstrumentationSettings settings)
        {
            // Arrange
            const IActivityAdapter emptyActivity = null;

            // Act
            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(() => emptyActivity.TrackMessageSentiment(this.telemetryClient, settings, sentimentClient))
            .ConfigureAwait(false);
        }
Esempio n. 25
0
        public void GIVENEmptyActivity_WHENTrackEventIsInvoked_THENExceptionIsBeingThrown(
            QueryResult queryResult,
            InstrumentationSettings settings)
        {
            // Arrange
            var instrumentation = new QnAInstrumentation(this.telemetryClient, settings);
            const IMessageActivity emptyActivity = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => instrumentation.TrackEvent(emptyActivity, queryResult));
        }
        public void GivenEmptyActivity_WhenTrackIntentIsInvoked_ThenExceptionIsBeingThrown(
            RecognizerResult luisResult,
            InstrumentationSettings settings)
        {
            // Arrange
            var instrumentation = new IntentInstrumentation(this.telemetryClient, settings);
            const IMessageActivity emptyActivity = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => instrumentation.TrackIntent(emptyActivity, luisResult));
        }
        public void GIVENEmptyActivity_WHENTrackActivityIsInvoked_THENExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            var             instrumentation = new ActivityInstrumentation(this.telemetryClient, settings);
            const IActivity emptyActivity   = null;

            // Act
            // Assert
            Assert.ThrowsAsync <ArgumentNullException>(() => instrumentation.TrackActivity(emptyActivity))
            .ConfigureAwait(false);
        }
        public void GIVENEmptyQueryResult_WHENTrackIntentIsInvoked_THENExceptionIsBeingThrown(
            IMessageActivity activity,
            InstrumentationSettings settings)
        {
            // Arrange
            var instrumentation = new IntentInstrumentation(this.telemetryClient, settings);
            const LuisResult emptyLuisResult = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => instrumentation.TrackIntent(activity, emptyLuisResult));
        }
Esempio n. 29
0
        public async void GIVENEmptyTurnContext_WHENOnTurnAsyncIsInvoked_THENExceptionIsBeingThrown(
            InstrumentationSettings settings)
        {
            // Arrange
            var instrumentation = new BotInstrumentationMiddleware(this.telemetryClient, settings);
            const ITurnContext emptyTurnContext = null;
            NextDelegate       nextDelegate     = Task.FromCanceled;

            // Act
            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(() => instrumentation.OnTurnAsync(emptyTurnContext, nextDelegate))
            .ConfigureAwait(false);
        }
        public void GIVENSentimentInstrumentationMiddleware_WHENDisposeIsInvoked_THENOtherResourcesAreBeingDisposedAsWell(
            InstrumentationSettings settings,
            ISentimentClient sentimentClient)
        {
            // Arrange
            var instrumentation = new SentimentInstrumentationMiddleware(this.telemetryClient, sentimentClient, settings);

            // Act
            instrumentation.Dispose();

            // Assert
            Mock.Get(sentimentClient).Verify(sc => sc.Dispose(), Times.Once);
        }