コード例 #1
0
        public static async Task CreatesLabeledUtterancesWithEntities()
        {
            var text        = Guid.NewGuid().ToString();
            var intent      = Guid.NewGuid().ToString();
            var entityType  = Guid.NewGuid().ToString();
            var entityValue = Guid.NewGuid().ToString();
            var slots       = new Dictionary <string, string>
            {
                { entityType, entityValue },
            };

            var mockClient = new Mock <ILexTestClient>();

            mockClient.Setup(lex => lex.PostTextAsync(
                                 It.Is <PostTextRequest>(request => request.InputText == text),
                                 It.IsAny <CancellationToken>()))
            .Returns(() => Task.FromResult(new PostTextResponse {
                Slots = slots
            }));

            using (var lex = new LexNLUTestClient(string.Empty, string.Empty, new LexSettings(), mockClient.Object))
            {
                var response = await lex.TestAsync(text).ConfigureAwait(false);

                response.Entities[0].EntityType.Should().Be(entityType);
                response.Entities[0].EntityValue.Value <string>().Should().BeEquivalentTo(entityValue);
            }
        }
コード例 #2
0
        public static void ThrowsArgumentNull()
        {
            var nullBotName   = new Action(() => new LexNLUTestClient(null, string.Empty, default(ILexTestClient)));
            var nullBotAlias  = new Action(() => new LexNLUTestClient(string.Empty, null, default(ILexTestClient)));
            var nullLexClient = new Action(() => new LexNLUTestClient(string.Empty, string.Empty, default(ILexTestClient)));

            nullBotName.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("botName");
            nullBotAlias.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("botAlias");
            nullLexClient.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("lexClient");

            using (var lex = new LexNLUTestClient(string.Empty, string.Empty, new Mock <ILexTestClient>().Object))
            {
                var nullSpeechFile    = new Func <Task>(() => lex.TestSpeechAsync(null));
                var nullTestUtterance = new Func <Task>(() => lex.TestAsync(default(JToken)));
                nullSpeechFile.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("speechFile");
                nullTestUtterance.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("query");
            }
        }
コード例 #3
0
        public static async Task CreatesLabeledUtterances()
        {
            var text       = Guid.NewGuid().ToString();
            var intent     = Guid.NewGuid().ToString();
            var mockClient = new Mock <ILexTestClient>();

            mockClient.Setup(lex => lex.PostTextAsync(
                                 It.Is <PostTextRequest>(request => request.InputText == text),
                                 It.IsAny <CancellationToken>()))
            .Returns(() => Task.FromResult(new PostTextResponse {
                IntentName = intent
            }));

            using (var lex = new LexNLUTestClient(string.Empty, string.Empty, new LexSettings(), mockClient.Object))
            {
                var response = await lex.TestAsync(text).ConfigureAwait(false);

                response.Text.Should().Be(text);
                response.Intent.Should().Be(intent);
                response.Entities.Should().BeEmpty();
            }
        }
コード例 #4
0
 public static Task <LabeledUtterance> TestAsync(this LexNLUTestClient client, string utterance)
 {
     return(client.TestAsync(new JObject {
         { "text", utterance }
     }));
 }