Пример #1
0
        /// <summary>
        /// Compare response with given expected input. Test fails if it does not match. If it does match and
        /// finished=true, the current integration test will pass.
        /// </summary>
        /// <param name="response">PullString Response object</param>
        /// <param name="expected">A BehaviorOutput object representing the expected value</param>
        public static void BehaviorShouldMatch(BehaviorOutput expected, Response response)
        {
            var behaviors = response.Outputs.Where(o => o.Type.Equals(EOutputType.Behavior)).ToArray();

            Assert.IsTrue(behaviors.Length > 0, "No behaviors found in response.");

            foreach (var b in behaviors)
            {
                var behavior = (BehaviorOutput)b;
                if (behavior.Behavior.Equals(expected.Behavior))
                {
                    if (expected.Parameters != null)
                    {
                        foreach (var kv in expected.Parameters)
                        {
                            Assert.IsTrue(behavior.Parameters.ContainsKey(kv.Key), "Behavior paramters not found.");
                            var param = behavior.Parameters[kv.Key];

                            Assert.IsFalse(!kv.Value.StringValue.Equals(param.StringValue) ||
                                           kv.Value.BoolValue != param.BoolValue ||
                                           (decimal)kv.Value.NumericValue != (decimal)param.NumericValue ||
                                           (kv.Value.ListValue != null && !kv.Value.ListValue.SequenceEqual(param.ListValue)) ||
                                           (kv.Value.DictionaryValue != null && !kv.Value.DictionaryValue.SequenceEqual(param.DictionaryValue)),
                                           "Behavior paramters did not match.");
                        }
                    }
                    // if you made this far, success
                    return;
                }
            }

            Assert.IsTrue(false, "Matching behavior not found.");
        }
Пример #2
0
        protected override void Run(Response response, int step)
        {
            switch (step)
            {
            case 0:
                conversation.SendEvent("simple_event", null);
                break;

            case 1:
                var expected = new BehaviorOutput()
                {
                    Behavior   = "simple_action",
                    Parameters = null
                };

                Dictionary <string, object> parameters = new Dictionary <string, object> {
                    { "name", "green" }
                };
                TestUtils.BehaviorShouldMatch(expected, response);
                conversation.SendEvent("event_with_param", parameters);
                break;

            case 2:
                var expected2 = new BehaviorOutput()
                {
                    Behavior   = "action_with_param",
                    Parameters = new Dictionary <string, ParameterValue> {
                        { "name", new ParameterValue("Green") }
                    }
                };
                Dictionary <string, object> parameters2 = new Dictionary <string, object> {
                    { "name", "red" }
                };
                TestUtils.TextShouldMatch(response, new[] { "Green Event Called" });
                TestUtils.BehaviorShouldMatch(expected2, response);
                conversation.SendEvent("event_with_param", parameters2);
                break;

            case 3:
                var expected3 = new BehaviorOutput()
                {
                    Behavior   = "action_with_param",
                    Parameters = new Dictionary <string, ParameterValue> {
                        { "name", new ParameterValue("Red") }
                    }
                };
                TestUtils.TextShouldMatch(response, new[] { "Red Event Called" });
                TestUtils.BehaviorShouldMatch(expected3, response);
                IsTestFinished = true;
                break;

            default:
                TestUtils.ShouldntBeHere();
                break;
            }
        }