示例#1
0
        public async Task Telemetry_ConvertParms()
        {
            // Arrange
            // Note this is NOT a real LUIS application ID nor a real LUIS subscription-key
            // theses are GUIDs edited to look right to the parsing and validation code.
            var endpoint        = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360&subscription-key=048ec46dc58e495482b0c447cfdbd291&q=";
            var clientHandler   = new EmptyLuisResponseClientHandler();
            var luisApp         = new LuisApplication(endpoint);
            var telemetryClient = new Mock <IBotTelemetryClient>();
            var adapter         = new NullAdapter();
            var activity        = new Activity
            {
                Type         = ActivityTypes.Message,
                Text         = "please book from May 5 to June 6",
                Recipient    = new ChannelAccount(),        // to no where
                From         = new ChannelAccount(),        // from no one
                Conversation = new ConversationAccount(),   // on no conversation
            };

            var turnContext = new TurnContext(adapter, activity);

            var options = new LuisRecognizerOptionsV2(luisApp)
            {
                TelemetryClient        = telemetryClient.Object,
                LogPersonalInformation = false,
            };
            var recognizer = new LuisRecognizer(options, clientHandler);

            // Act
            var additionalProperties = new Dictionary <string, string>
            {
                { "test", "testvalue" },
                { "foo", "foovalue" },
            };
            var additionalMetrics = new Dictionary <string, double>
            {
                { "moo", 3.14159 },
                { "luis", 1.0001 },
            };

            var result = await recognizer.RecognizeAsync <TelemetryConvertResult>(turnContext, additionalProperties, additionalMetrics, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(telemetryClient.Invocations.Count, 1);
            Assert.AreEqual(telemetryClient.Invocations[0].Arguments[0].ToString(), "LuisResult");
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("test"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["test"] == "testvalue");
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("foo"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["foo"] == "foovalue");
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("applicationId"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intent"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intentScore"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("fromId"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("entities"));
            Assert.IsTrue(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2]).ContainsKey("moo"));
            Assert.AreEqual(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2])["moo"], 3.14159);
            Assert.IsTrue(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2]).ContainsKey("luis"));
            Assert.AreEqual(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2])["luis"], 1.0001);
        }
示例#2
0
        public void UserAgentContainsProductVersion()
        {
            var application = new LuisApplication
            {
                EndpointKey   = "this-is-not-a-key",
                ApplicationId = "this-is-not-an-application-id",
                Endpoint      = "https://westus.api.cognitive.microsoft.com"
            };

            var clientHandler = new EmptyLuisResponseClientHandler();

            var recognizer = new LuisRecognizer(application, clientHandler: clientHandler);

            var adapter  = new NullAdapter();
            var activity = new Activity
            {
                Type         = ActivityTypes.Message,
                Text         = "please book from May 5 to June 6",
                Recipient    = new ChannelAccount(),        // to no where
                From         = new ChannelAccount(),        // from no one
                Conversation = new ConversationAccount()    // on no conversation
            };

            var turnContext = new TurnContext(adapter, activity);

            var recognizerResult = recognizer.RecognizeAsync(turnContext, CancellationToken.None).Result;

            var userAgent = clientHandler.UserAgent;

            // Verify we didn't unintentionally stamp on the user-agent from the client.
            Assert.IsTrue(userAgent.Contains("Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.LUISRuntimeClient"));

            // And that we added the bot.builder package details.
            Assert.IsTrue(userAgent.Contains("Microsoft.Bot.Builder.AI.Luis/4"));
        }
示例#3
0
        public async Task Telemetry_OverrideFillAsync()
        {
            // Arrange
            // Note this is NOT a real LUIS application ID nor a real LUIS subscription-key
            // theses are GUIDs edited to look right to the parsing and validation code.
            var endpoint        = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360&subscription-key=048ec46dc58e495482b0c447cfdbd291&q=";
            var clientHandler   = new EmptyLuisResponseClientHandler();
            var luisApp         = new LuisApplication(endpoint);
            var telemetryClient = new Mock <IBotTelemetryClient>();
            var adapter         = new NullAdapter();
            var activity        = new Activity
            {
                Type         = ActivityTypes.Message,
                Text         = "please book from May 5 to June 6",
                Recipient    = new ChannelAccount(),        // to no where
                From         = new ChannelAccount(),        // from no one
                Conversation = new ConversationAccount(),   // on no conversation
            };

            var turnContext = new TurnContext(adapter, activity);

            var options = new LuisPredictionOptions
            {
                TelemetryClient        = telemetryClient.Object,
                LogPersonalInformation = false,
            };
            var recognizer = new OverrideFillRecognizer(luisApp, options, false, false, clientHandler);

            var additionalProperties = new Dictionary <string, string>
            {
                { "test", "testvalue" },
                { "foo", "foovalue" },
            };
            var additionalMetrics = new Dictionary <string, double>
            {
                { "moo", 3.14159 },
                { "boo", 2.11 },
            };

            var result = await recognizer.RecognizeAsync(turnContext, additionalProperties, additionalMetrics).ConfigureAwait(false);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(2, telemetryClient.Invocations.Count);
            Assert.Equal("LuisResult", telemetryClient.Invocations[0].Arguments[0].ToString());
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("MyImportantProperty"));
            Assert.Equal("myImportantValue", ((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["MyImportantProperty"]);
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("test"));
            Assert.Equal("testvalue", ((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["test"]);
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("foo"));
            Assert.Equal("foovalue", ((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["foo"]);
            Assert.True(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2]).ContainsKey("moo"));
            Assert.Equal(3.14159, ((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2])["moo"]);
            Assert.True(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2]).ContainsKey("boo"));
            Assert.Equal(2.11, ((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2])["boo"]);
            Assert.Equal("MySecondEvent", telemetryClient.Invocations[1].Arguments[0].ToString());
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[1].Arguments[1]).ContainsKey("MyImportantProperty2"));
            Assert.Equal("myImportantValue2", ((Dictionary <string, string>)telemetryClient.Invocations[1].Arguments[1])["MyImportantProperty2"]);
        }
示例#4
0
        public async Task Telemetry_PiiLoggedAsync()
        {
            // Arrange
            // Note this is NOT a real LUIS application ID nor a real LUIS subscription-key
            // theses are GUIDs edited to look right to the parsing and validation code.
            var endpoint        = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/b31aeaf3-3511-495b-a07f-571fc873214b?verbose=true&timezoneOffset=-360&subscription-key=048ec46dc58e495482b0c447cfdbd291&q=";
            var clientHandler   = new EmptyLuisResponseClientHandler();
            var luisApp         = new LuisApplication(endpoint);
            var telemetryClient = new Mock <IBotTelemetryClient>();
            var adapter         = new NullAdapter();
            var activity        = new Activity
            {
                Type         = ActivityTypes.Message,
                Text         = "please book from May 5 to June 6",
                Recipient    = new ChannelAccount(),        // to no where
                From         = new ChannelAccount(),        // from no one
                Conversation = new ConversationAccount(),   // on no conversation
            };

            var turnContext = new TurnContext(adapter, activity);

            var opts = new LuisRecognizerOptionsV2(luisApp)
            {
                TelemetryClient        = telemetryClient.Object,
                LogPersonalInformation = true,
            };
            var recognizer = new LuisRecognizer(opts, clientHandler);

            // Act
            var result = await recognizer.RecognizeAsync(turnContext, null).ConfigureAwait(false);

            // Assert
            Assert.NotNull(result);
            Assert.Single(telemetryClient.Invocations);
            Assert.Equal("LuisResult", telemetryClient.Invocations[0].Arguments[0].ToString());
            Assert.Equal(8, ((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).Count);
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("applicationId"));
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intent"));
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intentScore"));
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intent2"));
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intentScore2"));
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("fromId"));
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("entities"));
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("question"));
        }
示例#5
0
        public void UserAgentContainsProductVersion()
        {
            var application = new LuisApplication
            {
                EndpointKey   = "this-is-not-a-key",
                ApplicationId = "this-is-not-an-application-id",
                Endpoint      = "https://westus.api.cognitive.microsoft.com",
            };

            var clientHandler = new EmptyLuisResponseClientHandler();

            var recognizer = new LuisRecognizer(new LuisRecognizerOptionsV2(application), clientHandler: clientHandler);

            var adapter  = new NullAdapter();
            var activity = new Activity
            {
                Type         = ActivityTypes.Message,
                Text         = "please book from May 5 to June 6",
                Recipient    = new ChannelAccount(),        // to no where
                From         = new ChannelAccount(),        // from no one
                Conversation = new ConversationAccount(),   // on no conversation
            };

            var turnContext = new TurnContext(adapter, activity);

            var recognizerResult = recognizer.RecognizeAsync(turnContext, CancellationToken.None).Result;

            Assert.NotNull(recognizerResult);

            var userAgent = clientHandler.UserAgent;

            // Verify we didn't unintentionally stamp on the user-agent from the client.
            Assert.Contains("Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.LUISRuntimeClient", userAgent);

            // And that we added the bot.builder package details.
            var majorVersion = typeof(ConnectorClient).GetTypeInfo().Assembly.GetName().Version.Major;

            Assert.Contains($"microsoft.bot.builder.ai.luis/{majorVersion}", userAgent.ToLower());
        }
 public LuisRecognizerTests()
 {
     _luisApp = new LuisApplication(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "https://someluisendpoint");
     _mockHttpClientHandler = new EmptyLuisResponseClientHandler();
 }