public async Task TemperaturePrompt_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 TemperaturePrompt(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 10 degrees")
            .AssertReply("null")
            .Send(" it is 43 degrees")
            .AssertReply("43 Degree")
            .StartTest();
        }
Esempio n. 2
0
        public async Task TemperaturePrompt_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 TemperaturePrompt(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 tempResult = await numberPrompt.Recognize(context);
                    if (tempResult.Succeeded())
                    {
                        await context.SendActivity($"{tempResult.Value} {tempResult.Unit}");
                    }
                    else
                    {
                        await context.SendActivity(tempResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send(" it is 10 degrees")
            .AssertReply(PromptStatus.TooSmall.ToString())
            .Send(" it is 43 degrees")
            .AssertReply("43 Degree")
            .StartTest();
        }
        public async Task TemperaturePrompt_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 TemperaturePrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await testPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var tempResult = await testPrompt.Recognize(context);
                    if (tempResult.Succeeded())
                    {
                        Assert.IsTrue(tempResult.Value != float.NaN);
                        Assert.IsNotNull(tempResult.Text);
                        Assert.IsNotNull(tempResult.Unit);
                        Assert.IsInstanceOfType(tempResult.Value, typeof(float));
                        context.Reply($"{tempResult.Value} {tempResult.Unit}");
                    }
                    else
                    {
                        context.Reply(tempResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send("test test test")
            .AssertReply(RecognitionStatus.NotRecognized.ToString())
            .Send(" it is 43 degrees")
            .AssertReply("43 Degree")
            .StartTest();
        }