public async Task PhoneNumberPrompt_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 PhoneNumberPrompt(Culture.English, async(ctx, result) => result.Value.StartsWith("123"));
                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}");
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send("888-123-4567")
            .AssertReply("null")
            .Send("123-123-4567")
            .AssertReply("123-123-4567")
            .StartTest();
        }
Exemplo n.º 2
0
        public async Task PhoneNumberPrompt_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 PhoneNumberPrompt(Culture.English, async(ctx, result) =>
                {
                    if (!result.Value.StartsWith("123"))
                    {
                        result.Status = PromptStatus.OutOfRange;
                    }
                });
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await numberPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var phoneResult = await numberPrompt.Recognize(context);
                    if (phoneResult.Succeeded())
                    {
                        await context.SendActivity($"{phoneResult.Value}");
                    }
                    else
                    {
                        await context.SendActivity(phoneResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send("888-123-4567")
            .AssertReply(PromptStatus.OutOfRange.ToString())
            .Send("123-123-4567")
            .AssertReply("123-123-4567")
            .StartTest();
        }
Exemplo n.º 3
0
        public async Task PhoneNumberPrompt_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 PhoneNumberPrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await testPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var phoneResult = await testPrompt.Recognize(context);
                    if (phoneResult.Succeeded())
                    {
                        Assert.IsNotNull(phoneResult.Text);
                        Assert.IsNotNull(phoneResult.Value);
                        await context.SendActivity($"{phoneResult.Value}");
                    }
                    else
                    {
                        await context.SendActivity(phoneResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send("test test test")
            .AssertReply(PromptStatus.NotRecognized.ToString())
            .Send("123 123123sdfsdf 123 1asdf23123 123 ")
            .AssertReply(PromptStatus.NotRecognized.ToString())
            .Send("123-456-7890")
            .AssertReply("123-456-7890")
            .StartTest();
        }