예제 #1
0
        public async Task ShouldThrowExceptionOnRenameIntentTestWhenExistsIntentWithSameName()
        {
            var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
            var intent = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");

            var intentChanged = await client.GetIntentByNameAsync("IntentTestChanged", _appId, "1.0");

            string intentChangedId = null;

            if (intent == null)
            {
                await client.AddIntentAsync("IntentTest", _appId, "1.0");

                intent = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");
            }
            if (intentChanged == null)
            {
                intentChangedId = await client.AddIntentAsync("IntentTestChanged", _appId, "1.0");
            }

            var ex = await Assert.ThrowsExceptionAsync <Exception>(() =>
                                                                   client.RenameIntentAsync(intent.Id, "IntentTestChanged", _appId, "1.0"));

            Assert.AreEqual(ex.Message, "The application already contains an intent classifier with the same name");
        }
        public async Task ShouldThrowExceptionOnRenameIntentTestWhenExistsIntentWithSameName()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                var intent = await client.GetIntentByNameAsync(IntentName, appId, appVersion);

                var intentChanged = await client.GetIntentByNameAsync(IntentNameChanged, appId, appVersion);

                string intentChangedId = null;

                if (intent == null)
                {
                    await client.AddIntentAsync(IntentName, appId, appVersion);

                    intent = await client.GetIntentByNameAsync(IntentName, appId, appVersion);
                }
                if (intentChanged == null)
                {
                    intentChangedId = await client.AddIntentAsync(IntentNameChanged, appId, appVersion);
                }

                var ex = await Assert.ThrowsExceptionAsync <Exception>(() =>
                                                                       client.RenameIntentAsync(intent.Id, IntentNameChanged, appId, appVersion));

                Assert.AreEqual(ex.Message, "BadArgument - The models: { IntentTestChanged } already exist in the specified application version.");
            }
        }
        public async Task ShouldDeleteIntentAndUtterancesTest()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                if (await client.GetIntentByNameAsync(IntentName, appId, appVersion) == null)
                {
                    await client.AddIntentAsync(IntentName, appId, appVersion);
                }

                // Add example for the intent
                var exampleAdded = await client.AddExampleAsync(appId, appVersion, new Example()
                {
                    IntentName = IntentName,
                    Text       = "This is sample utterance"
                });

                if (!string.IsNullOrEmpty(exampleAdded?.UtteranceText))
                {
                    var intent = await client.GetIntentByNameAsync(IntentName, appId, appVersion);

                    await client.DeleteIntentAsync(intent.Id, appId, appVersion, true);

                    // TODO : once the get exampleById available, get the exmaple and assert for null
                    intent = await client.GetIntentByIdAsync(intent.Id, appId, appVersion);

                    Assert.IsNull(intent);
                }
            }
        }
        public async Task ShouldRenameIntentTest()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                var intent = await client.GetIntentByNameAsync(IntentName, appId, appVersion);

                var intentChanged = await client.GetIntentByNameAsync(IntentNameChanged, appId, appVersion);

                if (intent == null)
                {
                    await client.AddIntentAsync(IntentName, appId, appVersion);

                    intent = await client.GetIntentByNameAsync(IntentName, appId, appVersion);
                }

                if (intentChanged != null)
                {
                    await client.DeleteIntentAsync(intentChanged.Id, appId, appVersion);
                }

                await client.RenameIntentAsync(intent.Id, IntentNameChanged, appId, appVersion);

                intent = await client.GetIntentByIdAsync(intent.Id, appId, appVersion);

                Assert.AreEqual(IntentNameChanged, intent.Name);
            }
        }
        public async Task ShouldAddExample()
        {
            var    client       = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
            string intentTestId = null;
            var    intentTest   = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");

            if (intentTest != null)
            {
                intentTestId = intentTest.Id;
            }
            else
            {
                intentTestId = await client.AddIntentAsync("IntentTest", _appId, "1.0");
            }

            var example = new Example
            {
                Text       = "Hello World!",
                IntentName = "IntentTest"
            };

            var utterance = await client.AddExampleAsync(_appId, "1.0", example);

            Assert.IsNotNull(utterance);
        }
예제 #6
0
        public async Task ShoulAddBatchExample()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                if (await client.GetIntentByNameAsync(IntentName, appId, appVersion) == null)
                {
                    await client.AddIntentAsync(IntentName, appId, appVersion);
                }

                List <Example> examples = new List <Example>();
                examples.Add(new Example
                {
                    Text       = "Hello World!",
                    IntentName = IntentName
                });

                examples.Add(new Example
                {
                    Text       = "This is a test Utterance",
                    IntentName = IntentName
                });

                var addExamples = await client.AddBatchExampleAsync(appId, appVersion, examples.ToArray());

                Assert.AreEqual <int>(2, addExamples.Length);
            }
        }
        public async Task ShouldSendPublishRequest()
        {
            IEnumerable <Training> trainingList;

            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                await client.AddIntentAsync("IntentTest", appId, appVersion);

                await client.AddExampleAsync(appId, appVersion, new Example
                {
                    Text       = "Hello World!",
                    IntentName = "IntentTest"
                });

                await client.TrainAsync(appId, appVersion);

                do
                {
                    trainingList = await client.GetTrainingStatusListAsync(appId, appVersion);
                }while (!trainingList.All(x => x.Details.Status.Equals("Success")));

                var publish = await client.PublishAsync(appId, appVersion, false, "westus");

                Assert.IsNotNull(publish);
            }
        }
예제 #8
0
        public async Task ShouldAddExample()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                string intentTestId = null;
                var    intentTest   = await client.GetIntentByNameAsync(IntentName, appId, appVersion);

                if (intentTest != null)
                {
                    intentTestId = intentTest.Id;
                }
                else
                {
                    intentTestId = await client.AddIntentAsync(IntentName, appId, appVersion);
                }

                var example = new Example
                {
                    Text       = "Hello World!",
                    IntentName = IntentName
                };

                var utterance = await client.AddExampleAsync(appId, appVersion, example);

                Assert.IsNotNull(utterance);
            }
        }
예제 #9
0
        public async Task ShouldRenameIntentTest()
        {
            var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
            var intent = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");

            var intentChanged = await client.GetIntentByNameAsync("IntentTestChanged", _appId, "1.0");

            if (intent == null)
            {
                await client.AddIntentAsync("IntentTest", _appId, "1.0");

                intent = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");
            }

            if (intentChanged != null)
            {
                await client.DeleteIntentAsync(intentChanged.Id, _appId, "1.0");
            }

            await client.RenameIntentAsync(intent.Id, "IntentTestChanged", _appId, "1.0");

            intent = await client.GetIntentByIdAsync(intent.Id, _appId, "1.0");

            Assert.AreEqual("IntentTestChanged", intent.Name);
        }
예제 #10
0
        public async Task ShouldAddLabelledExample()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                // Add simple entity name if not already exists
                if (await client.GetEntityByNameAsync("name", appId, appVersion) == null)
                {
                    await client.AddEntityAsync("name", appId, appVersion);
                }

                if (await client.GetIntentByNameAsync(IntentName, appId, appVersion) == null)
                {
                    await client.AddIntentAsync(IntentName, appId, appVersion);
                }

                var labeledExample = new Example()
                {
                    Text         = "Who is Test User!",
                    IntentName   = IntentName,
                    EntityLabels = new List <EntityLabel>
                    {
                        new EntityLabel
                        {
                            EntityName     = "name",
                            StartCharIndex = 7,
                            EndCharIndex   = 15
                        }
                    }
                };

                var utterance = await client.AddExampleAsync(appId, appVersion, labeledExample);

                Assert.IsNotNull(utterance);
            }
        }
        public async Task ShouldThrowExceptionOnIntentNewIntentTestWhenAlreadyExists()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                var intentTest = await client.GetIntentByNameAsync(IntentName, appId, appVersion);

                if (intentTest == null)
                {
                    await client.AddIntentAsync(IntentName, appId, appVersion);
                }

                var ex = await Assert.ThrowsExceptionAsync <Exception>(() =>
                                                                       client.AddIntentAsync(IntentName, appId, appVersion));

                Assert.AreEqual(ex.Message, "BadArgument - The models: { IntentTest } already exist in the specified application version.");
            }
        }
예제 #12
0
        public async Task ShouldThrowExceptionOnIntentNewIntentTestWhenAlreadyExists()
        {
            var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
            var ex     = await Assert.ThrowsExceptionAsync <Exception>(() =>
                                                                       client.AddIntentAsync("IntentTest", _appId, "1.0"));

            Assert.AreEqual(ex.Message, "An intent classifier with the same name already exists");
        }
예제 #13
0
        public async Task ShoulAddBatchLbeledExample()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                // Add simple entity name if not already exists
                if (await client.GetEntityByNameAsync("name", appId, appVersion) == null)
                {
                    await client.AddEntityAsync("name", appId, appVersion);
                }

                // Add simple intent name if not already exists
                if (await client.GetIntentByNameAsync(IntentName, appId, appVersion) == null)
                {
                    await client.AddIntentAsync(IntentName, appId, appVersion);
                }

                List <Example> examples = new List <Example>();
                examples.Add(new Example()
                {
                    Text         = "Who is Bill?",
                    IntentName   = IntentName,
                    EntityLabels = new List <EntityLabel>
                    {
                        new EntityLabel
                        {
                            EntityName     = "name",
                            StartCharIndex = 7,
                            EndCharIndex   = 10
                        }
                    }
                });

                examples.Add(new Example()
                {
                    Text         = "Who is Christopher?",
                    IntentName   = IntentName,
                    EntityLabels = new List <EntityLabel>
                    {
                        new EntityLabel
                        {
                            EntityName     = "name",
                            StartCharIndex = 7,
                            EndCharIndex   = 17
                        }
                    }
                });

                var addExamples = await client.AddBatchExampleAsync(appId, appVersion, examples.ToArray());

                Assert.AreEqual <bool>(false, addExamples[0].HasError);
                Assert.AreEqual <bool>(false, addExamples[1].HasError);
            }
        }
예제 #14
0
        public async Task ShouldGetIntentByName()
        {
            var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);

            if (await client.GetIntentByNameAsync("IntentTest", _appId, "1.0") == null)
            {
                await client.AddIntentAsync("IntentTest", _appId, "1.0");
            }

            var intent = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");

            Assert.IsNotNull(intent);
        }
        public async Task ShouldGetIntentByName()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                if (await client.GetIntentByNameAsync(IntentName, appId, appVersion) == null)
                {
                    await client.AddIntentAsync(IntentName, appId, appVersion);
                }

                var intent = await client.GetIntentByNameAsync(IntentName, appId, appVersion);

                Assert.IsNotNull(intent);
            }
        }
예제 #16
0
        public async Task ShouldAddNewIntentTest()
        {
            var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);

            var intentTest = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");

            if (intentTest != null)
            {
                await client.DeleteIntentAsync(intentTest.Id, _appId, "1.0");
            }

            var newId = await client.AddIntentAsync("IntentTest", _appId, "1.0");

            Assert.IsNotNull(newId);
        }
        public async Task ShouldAddNewIntentTest()
        {
            using (var client = new LuisProgClient(SubscriptionKey, Region))
            {
                var intentTest = await client.GetIntentByNameAsync(IntentName, appId, appVersion);

                if (intentTest != null)
                {
                    await client.DeleteIntentAsync(intentTest.Id, appId, appVersion);
                }

                var newId = await client.AddIntentAsync(IntentName, appId, appVersion);

                Assert.IsNotNull(newId);
            }
        }
        public async Task ShouldSendPublishRequest()
        {
            IEnumerable <Training> trainingList;
            var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
            await client.AddIntentAsync("IntentTest", _appId, "1.0");

            await client.AddExampleAsync(_appId, "1.0", new Example
            {
                Text       = "Hello World!",
                IntentName = "IntentTest"
            });

            await client.TrainAsync(_appId, "1.0");

            do
            {
                trainingList = await client.GetTrainingStatusListAsync(_appId, "1.0");
            }while (!trainingList.All(x => x.Details.Status.Equals("Success")));

            var publish = await client.PublishAsync(_appId, "1.0", false, "westus");

            Assert.IsNotNull(publish);
        }