Пример #1
0
        public async Task TrackActivity_NonIncomingMessage_DoesNotTrackMessageSentiment()
        {
            // Arrange
            var sentimentHttpMock = TestUtils.CreateSentimentHttpMock(50);
            var instrumentation   = new BotFrameworkApplicationInsightsInstrumentation
                                    (
                new InstrumentationSettings
            {
                InstrumentationKeys = new List <string>(new[] { "instrumentation key" }),
                SentimentManager    = new SentimentManager("text analytics api key", "", "", sentimentHttpMock.Object)
            }
                                    );

            // Act
            await instrumentation.TrackActivity(CreateActivity("some text", ActivityTypes.EndOfConversation));

            // Assert if sentiment analysis endpoint was never called
            sentimentHttpMock.Verify(
                x =>
                x.PostAsync
                (
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <Dictionary <string, string> >(),
                    It.IsAny <byte[]>()
                ),
                Times.Never());
        }
Пример #2
0
        public async Task TrackActivity_IncomingMessage_TracksMessageSentiment()
        {
            // Arrange
            const string textAnalyticsApiKey         = "text analytics api key";
            const string cognitiveServiceApiEndpoint = "cognitive service api endpoint";
            const string messageText = "message text";

            var sentimentHttpMock = TestUtils.CreateSentimentHttpMock(50);
            var instrumentation   = new BotFrameworkApplicationInsightsInstrumentation
                                    (
                new InstrumentationSettings
            {
                InstrumentationKeys = new List <string>(new[] { "instrumentation key" }),
                SentimentManager    = new SentimentManager(textAnalyticsApiKey, "",
                                                           cognitiveServiceApiEndpoint, sentimentHttpMock.Object)
            }
                                    );

            // Act
            await instrumentation.TrackActivity(CreateActivity(messageText, ActivityTypes.Message));

            // Assert if sentiment analysis endpoint was called with correct params
            sentimentHttpMock.Verify(
                x =>
                x.PostAsync
                (
                    It.Is <string>(s => s == cognitiveServiceApiEndpoint),
                    It.IsAny <string>(),
                    It.Is <Dictionary <string, string> >(d => d.ContainsValue(textAnalyticsApiKey)),
                    It.Is <byte[]>(
                        b => JsonConvert.DeserializeObject <BatchInput>(Encoding.UTF8.GetString(b)).Documents[0]
                        .Text == messageText)
                ),
                Times.Once());
        }
Пример #3
0
 public async Task TrackActivity()
 {
     await _defaultInstrumentation.TrackActivity(_activity, null, _customProperties);
 }