Exemple #1
0
        public void TestEntitiesRetrieval()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            var array = new JArray();

            array.Add("test1");
            array.Add("test2");
            array.Add("test3");

            var array2 = new JArray();

            array2.Add("testx");
            array2.Add("testy");
            array2.Add("testz");

            var arrayarray = new JArray();

            arrayarray.Add(array2);
            arrayarray.Add(array);

            state.SetValue("turn.recognized.entities.single", array);
            state.SetValue("turn.recognized.entities.double", arrayarray);

            Assert.AreEqual("test1", state.GetValue <string>("@single"));
            Assert.AreEqual("testx", state.GetValue <string>("@double"));
            Assert.AreEqual("test1", state.GetValue <string>("turn.recognized.entities.single.First()"));
            Assert.AreEqual("testx", state.GetValue <string>("turn.recognized.entities.double.First()"));
        }
Exemple #2
0
        public void TestHashResolver()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            // test HASH
            state.SetValue($"turn.recognized.intents.test", "intent1");
            state.SetValue($"#test2", "intent2");

            Assert.AreEqual("intent1", state.GetValue <string>("turn.recognized.intents.test"));
            Assert.AreEqual("intent1", state.GetValue <string>("#test"));
            Assert.AreEqual("intent2", state.GetValue <string>("turn.recognized.intents.test2"));
            Assert.AreEqual("intent2", state.GetValue <string>("#test2"));
        }
Exemple #3
0
        [Ignore] // NOTE: This needs to be revisited
        public void TestComplexPathExpressions()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            // complex type paths
            state.SetValue("user.name", "joe");
            state.SetValue("conversation.stuff[user.name]", "test");
            var value = state.GetValue <string>("conversation.stuff.joe");

            Assert.AreEqual("test", value, "complex set should set");
            value = state.GetValue <string>("conversation.stuff[user.name]");
            Assert.AreEqual("test", value, "complex get should get");
        }
Exemple #4
0
        public void TestExpressionSet()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            state.SetValue($"turn.x.y.z", null);
            Assert.AreEqual(null, state.GetValue <object>("turn.x.y.z"));
        }
Exemple #5
0
        public void TestGetValueT()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            // complex type paths
            state.SetValue("UseR.fOo", foo);
            Assert.AreEqual(state.GetValue <Foo>("user.foo").SubName.Name, "bob");

            // complex type paths
            state.SetValue("ConVerSation.FOo", foo);
            Assert.AreEqual(state.GetValue <Foo>("conversation.foo").SubName.Name, "bob");

            // complex type paths
            state.SetValue("TurN.fOo", foo);
            Assert.AreEqual(state.GetValue <Foo>("turn.foo").SubName.Name, "bob");
        }
Exemple #6
0
        public void TestGetValue()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            // complex type paths
            state.SetValue("user.name.first", "joe");
            Assert.AreEqual("joe", state.GetValue <string>("user.name.first"));

            Assert.AreEqual(null, state.GetValue <string>("user.xxx"));
            Assert.AreEqual("default", state.GetValue <string>("user.xxx", () => "default"));

            foreach (var key in state.Keys)
            {
                Assert.AreEqual(state.GetValue <object>(key), state[key]);
            }
        }
Exemple #7
0
        public void TestComplexValuePaths()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            // complex type paths
            state.SetValue("UseR.fOo", foo);
            Assert.AreEqual("bob", state.GetValue <string>("user.foo.SuBname.name"));

            // complex type paths
            state.SetValue("ConVerSation.FOo", foo);
            Assert.AreEqual("bob", state.GetValue <string>("conversation.foo.SuBname.name"));

            // complex type paths
            state.SetValue("TurN.fOo", foo);
            Assert.AreEqual("bob", state.GetValue <string>("TuRN.foo.SuBname.name"));
        }
Exemple #8
0
        public void TestSimpleValues()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            // simple value types
            state.SetValue("UseR.nuM", 15);
            state.SetValue("uSeR.NuM", 25);
            Assert.AreEqual(25, state.GetValue <int>("user.num"));

            state.SetValue("UsEr.StR", "string1");
            state.SetValue("usER.STr", "string2");
            Assert.AreEqual("string2", state.GetValue <string>("USer.str"));

            // simple value types
            state.SetValue("ConVErsation.nuM", 15);
            state.SetValue("ConVErSation.NuM", 25);
            Assert.AreEqual(25, state.GetValue <int>("conversation.num"));

            state.SetValue("ConVErsation.StR", "string1");
            state.SetValue("CoNVerSation.STr", "string2");
            Assert.AreEqual("string2", state.GetValue <string>("conversation.str"));

            // simple value types
            state.SetValue("tUrn.nuM", 15);
            state.SetValue("turN.NuM", 25);
            Assert.AreEqual(25, state.GetValue <int>("turn.num"));

            state.SetValue("tuRn.StR", "string1");
            state.SetValue("TuRn.STr", "string2");
            Assert.AreEqual("string2", state.GetValue <string>("turn.str"));
        }
Exemple #9
0
        public void TestEntityResolvers()
        {
            var dialogs = new DialogSet();
            var dc      = new DialogContext(dialogs, new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState());
            DialogStateManager state = new DialogStateManager(dc);

            // test @ and @@
            var testEntities  = new string[] { "entity1", "entity2" };
            var testEntities2 = new string[] { "entity3", "entity4" };

            state.SetValue($"turn.recognized.entities.test", testEntities);
            state.SetValue($"@@test2", testEntities2);

            Assert.AreEqual(testEntities.First(), state.GetValue <string>("turn.recognized.entities.test[0]"));
            Assert.AreEqual(testEntities.First(), state.GetValue <string>("@test"));
            Assert.IsTrue(testEntities.SequenceEqual(state.GetValue <string[]>("turn.recognized.entities.test")));
            Assert.IsTrue(testEntities.SequenceEqual(state.GetValue <string[]>("@@test")));

            Assert.AreEqual(testEntities2.First(), state.GetValue <string>("turn.recognized.entities.test2[0]"));
            Assert.AreEqual(testEntities2.First(), state.GetValue <string>("@test2"));
            Assert.IsTrue(testEntities2.SequenceEqual(state.GetValue <string[]>("turn.recognized.entities.test2")));
            Assert.IsTrue(testEntities2.SequenceEqual(state.GetValue <string[]>("@@test2")));
        }