private EventTelemetry BuildEventTelemetry(IActivity activity)
        {
            var activityAdapter = new ActivityAdapter(activity);
            var builder         = new EventTelemetryBuilder(activityAdapter, this.settings);

            return(builder.Build());
        }
        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);
        }
        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);
        }
コード例 #5
0
        private void TrackIntent(IActivity activity, IDictionary <string, string> properties)
        {
            var builder        = new EventTelemetryBuilder(activity, this.settings, properties);
            var eventTelemetry = builder.Build();

            eventTelemetry.Name = EventTypes.Intent;

            this.telemetryClient.TrackEvent(eventTelemetry);
        }
コード例 #6
0
        public void TrackCustomEvent(
            IActivity activity,
            string eventName = EventTypes.CustomEvent,
            IDictionary <string, string> properties = null)
        {
            BotAssert.ActivityNotNull(activity);

            var builder        = new EventTelemetryBuilder(activity, this.settings, properties);
            var eventTelemetry = builder.Build();

            eventTelemetry.Name = string.IsNullOrWhiteSpace(eventName) ? EventTypes.CustomEvent : eventName;
            this.telemetryClient.TrackEvent(eventTelemetry);
        }
        public void GIVENAdditionalProperties_WHENBuildIsInvoked_THENEventTelemetryWithPropertiesIsBeingCreated(
            IActivityAdapter activity,
            InstrumentationSettings settings,
            IDictionary <string, string> properties)
        {
            // Arrange
            var builder = new EventTelemetryBuilder(activity, settings, properties);

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

            // Assert
            eventTelemetry.Properties.Should().HaveCountGreaterOrEqualTo(properties.Count);
            eventTelemetry.Properties.Should().Contain(properties);
        }
コード例 #8
0
        public static void TrackCustomEvent(this IActivityAdapter activity, TelemetryClient telemetryClient, InstrumentationSettings settings, string eventName = EventTypes.CustomEvent, IDictionary <string, string> properties = null)
        {
            if (telemetryClient is null)
            {
                throw new ArgumentNullException(nameof(telemetryClient));
            }

            var builder        = new EventTelemetryBuilder(activity, settings, properties);
            var eventTelemetry = builder.Build();

            eventTelemetry.Name = string.IsNullOrWhiteSpace(eventName)
                ? EventTypes.CustomEvent
                : eventName;

            telemetryClient.TrackEvent(eventTelemetry);
        }
コード例 #9
0
        public async Task TrackMessageSentiment(IMessageActivity activity)
        {
            BotAssert.ActivityNotNull(activity);

            var score = await this.sentimentClient.GetSentiment(activity)
                        .ConfigureAwait(false);

            var properties = new Dictionary <string, string>
            {
                { SentimentConstants.Score, score.Value.ToString(CultureInfo.InvariantCulture) }
            };

            var builder        = new EventTelemetryBuilder(activity, this.settings, properties);
            var eventTelemetry = builder.Build();

            eventTelemetry.Name = EventTypes.MessageSentiment;
            this.telemetryClient.TrackEvent(eventTelemetry);
        }
コード例 #10
0
        public void GIVENAdditionalPropertyToReplaceOriginalOne_WHENBuildIsInvoked_THENEventTelemetryWithReplacedPropertyIsBeingCreated(
            IActivityAdapter activity,
            InstrumentationSettings settings,
            string additionalPropertyValue)
        {
            // Arrange
            var additionalProperties = new Dictionary <string, string> {
                { BotConstants.TypeProperty, additionalPropertyValue }
            };
            var builder = new EventTelemetryBuilder(activity, settings, additionalProperties);

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

            // Assert
            activity.Type.Should().NotBe(additionalPropertyValue);
            eventTelemetry.Properties.Should().Contain(additionalProperties);
        }
コード例 #11
0
        public void TrackEvent(IMessageActivity activity, QueryResult queryResult)
        {
            BotAssert.ActivityNotNull(activity);
            if (queryResult == null)
            {
                throw new ArgumentNullException(nameof(queryResult));
            }

            var properties = new Dictionary <string, string>
            {
                { QnAConstants.UserQuery, activity.Text },
                { QnAConstants.KnowledgeBaseQuestion, string.Join(QuestionsSeparator, queryResult.Questions) },
                { QnAConstants.KnowledgeBaseAnswer, queryResult.Answer },
                { QnAConstants.Score, queryResult.Score.ToString(CultureInfo.InvariantCulture) }
            };

            var builder        = new EventTelemetryBuilder(activity, this.settings, properties);
            var eventTelemetry = builder.Build();

            eventTelemetry.Name = EventTypes.QnaEvent;
            this.telemetryClient.TrackEvent(eventTelemetry);
        }
コード例 #12
0
        GIVENMessageTypeActivityAndNoOmitUsernameSetting_WHENBuildIsInvoked_THENEventTelemetryIsBeingCreated(
            IFixture fixture)
        {
            // Arrange
            var settings = new InstrumentationSettings {
                OmitUsernameFromTelemetry = false
            };
            var messageActivity = new MessageActivity {
                Text = fixture.Create <string>()
            };
            var channelAccount = new ChannelAccount
            {
                Id   = fixture.Create <string>(),
                Name = fixture.Create <string>(),
            };
            var activity = new Activity
            {
                Type            = ActivityTypes.Message,
                ChannelId       = fixture.Create <string>(),
                MessageActivity = messageActivity,
                ChannelAccount  = channelAccount,
            };
            var          builder = new EventTelemetryBuilder(activity, settings);
            const int    expectedNumberOfTelemetryProperties = 6;
            const string expectedTelemetryName = EventTypes.MessageReceived;

            // 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.MessageActivity.Text);
            eventTelemetry.Properties[BotConstants.UserIdProperty].Should().Be(activity.ChannelAccount.Id);
            eventTelemetry.Properties[BotConstants.UserNameProperty].Should().Be(activity.ChannelAccount.Name);
            eventTelemetry.Properties[BotConstants.ChannelProperty].Should().Be(activity.ChannelId);
        }
コード例 #13
0
        public void GIVENMessageTypeActivityAndReplyToId_WHENBuildIsInvoked_THENEventTelemetryIsBeingCreated(
            InstrumentationSettings settings,
            IFixture fixture)
        {
            // Arrange
            var messageActivity = new MessageActivity {
                Text = fixture.Create <string>()
            };
            var channelAccount = new ChannelAccount
            {
                Id   = fixture.Create <string>(),
                Name = fixture.Create <string>(),
            };
            var activity = new Activity
            {
                Type             = ActivityTypes.Message,
                ChannelId        = fixture.Create <string>(),
                ReplyToId        = fixture.Create <string>(),
                MessageActivity  = messageActivity,
                TimeStampIso8601 = DateTime.Now.ToString(CultureInfo.CurrentCulture),
                ChannelAccount   = channelAccount,
            };
            var          builder = new EventTelemetryBuilder(activity, settings);
            const int    expectedNumberOfTelemetryProperties = 5;
            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.MessageActivity.Text);
            eventTelemetry.Properties[BotConstants.ChannelProperty].Should().Be(activity.ChannelId);
            eventTelemetry.Properties[BotConstants.TimestampProperty].Should().Be(activity.TimeStampIso8601);
        }
コード例 #14
0
        public void GivenMessageTypeActivityAndNoOmitUsernameSetting_WhenBuildIsInvoked_ThenEventTelemetryIsBeingCreated(
            IFixture fixture)
        {
            // Arrange
            var settings = new InstrumentationSettings {
                OmitUsernameFromTelemetry = false
            };
            var activity = new Activity
            {
                Type         = ActivityTypes.Message,
                ChannelId    = fixture.Create <string>(),
                Text         = fixture.Create <string>(),
                Conversation = new ConversationAccount {
                    Id = fixture.Create <string>()
                },
                From = new ChannelAccount {
                    Id = fixture.Create <string>()
                }
            };
            var          builder = new EventTelemetryBuilder(activity, settings);
            const int    expectedNumberOfTelemetryProperties = 6;
            const string expectedTelemetryName = EventTypes.MessageReceived;

            // 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.UserIdProperty].Should().Be(activity.From.Id);
            eventTelemetry.Properties[BotConstants.UserNameProperty].Should().Be(activity.From.Name);
            eventTelemetry.Properties[BotConstants.ConversationIdProperty].Should().Be(activity.Conversation.Id);
            eventTelemetry.Properties[BotConstants.ChannelProperty].Should().Be(activity.ChannelId);
        }