Esempio n. 1
0
        public async Task AgePrompt_Validator()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <TestState>(new MemoryStorage()));

            await new TestFlow(adapter, async(context) =>
            {
                var state        = ConversationState <TestState> .Get(context);
                var numberPrompt = new AgePrompt(Culture.English, async(ctx, result) => result.Value > 10);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await numberPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var result = await numberPrompt.Recognize(context);
                    if (result == null)
                    {
                        context.Reply("null");
                    }
                    else
                    {
                        context.Reply($"{result.Value} {result.Unit}");
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send(" it is 1 year old")
            .AssertReply("null")
            .Send(" it is 15 year old")
            .AssertReply("15 Year")
            .StartTest();
        }
Esempio n. 2
0
        public async Task AgePrompt_Validator()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <TestState>(new MemoryStorage()));

            await new TestFlow(adapter, async(context) =>
            {
                var state        = ConversationState <TestState> .Get(context);
                var numberPrompt = new AgePrompt(Culture.English, async(ctx, result) =>
                {
                    if (result.Value <= 10)
                    {
                        result.Status = PromptStatus.TooSmall;
                    }
                });
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await numberPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var numberResult = await numberPrompt.Recognize(context);
                    if (numberResult.Succeeded())
                    {
                        await context.SendActivity($"{numberResult.Value} {numberResult.Unit}");
                    }
                    else
                    {
                        await context.SendActivity(numberResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send(" it is 1 year old")
            .AssertReply(PromptStatus.TooSmall.ToString())
            .Send(" it is 15 year old")
            .AssertReply("15 Year")
            .StartTest();
        }
        public async Task AgePrompt_Test()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <TestState>(new MemoryStorage()));

            await new TestFlow(adapter, async(context) =>
            {
                var state      = ConversationState <TestState> .Get(context);
                var testPrompt = new AgePrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await testPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var ageResult = await testPrompt.Recognize(context);
                    if (ageResult.Succeeded())
                    {
                        Assert.IsTrue(ageResult.Value != float.NaN);
                        Assert.IsNotNull(ageResult.Text);
                        Assert.IsNotNull(ageResult.Unit);
                        Assert.IsInstanceOfType(ageResult.Value, typeof(float));
                        context.Reply($"{ageResult.Value} {ageResult.Unit}");
                    }
                    else
                    {
                        context.Reply(ageResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send("test test test")
            .AssertReply(RecognitionStatus.NotRecognized.ToString())
            .Send("I am 30 years old")
            .AssertReply("30 Year")
            .StartTest();
        }