Exemple #1
0
        public static async Task CreatesLabeledUtterances()
        {
            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 MockLexClient();

            mockClient.Get <PostTextResponse>().IntentName = intent;
            using (var lex = new LexNLUService(string.Empty, string.Empty, new LexSettings(), mockClient))
            {
                var response = await lex.TestAsync(text).ConfigureAwait(false);

                response.Text.Should().Be(text);
                response.Intent.Should().Be(intent);
                response.Entities.Should().BeEmpty();

                mockClient.Get <PostTextResponse>().Slots = slots;
                response = await lex.TestAsync(text).ConfigureAwait(false);

                response.Entities[0].EntityType.Should().Be(entityType);
                response.Entities[0].EntityValue.Should().Be(entityValue);
            }
        }
Exemple #2
0
        public static void ThrowsArgumentNull()
        {
            var nullBotName     = new Action(() => new LexNLUService(null, string.Empty, null, default(ILexClient)));
            var nullBotAlias    = new Action(() => new LexNLUService(string.Empty, null, null, default(ILexClient)));
            var nullLexSettings = new Action(() => new LexNLUService(string.Empty, string.Empty, null, default(ILexClient)));
            var nullLexClient   = new Action(() => new LexNLUService(string.Empty, string.Empty, new LexSettings(), default(ILexClient)));

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

            using (var service = new LexNLUService(string.Empty, string.Empty, new LexSettings(), new MockLexClient()))
            {
                var nullUtterances    = new Func <Task>(() => service.TrainAsync(null));
                var nullUtteranceItem = new Func <Task>(() => service.TrainAsync(new LabeledUtterance[] { null }));
                var nullSpeechFile    = new Func <Task>(() => service.TestSpeechAsync(null));
                var nullTestUtterance = new Func <Task>(() => service.TestAsync(null));
                nullUtterances.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("utterances");
                nullUtteranceItem.Should().Throw <ArgumentException>().And.ParamName.Should().Be("utterances");
                nullSpeechFile.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("speechFile");
                nullTestUtterance.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("utterance");
            }
        }