public async Task SimpleMemoryScopesTest() { await CreateDialogContext(async (dc, ct) => { var dsm = dc.State as DialogStateManager; foreach (var memoryScope in dsm.Configuration.MemoryScopes.Where(ms => !(ms is ThisMemoryScope || ms is DialogMemoryScope || ms is ClassMemoryScope || ms is DialogClassMemoryScope))) { var memory = memoryScope.GetMemory(dc); Assert.IsNotNull(memory, "should get memory without any set"); ObjectPath.SetPathValue(memory, "test", 15); memory = memoryScope.GetMemory(dc); Assert.AreEqual(15, ObjectPath.GetPathValue <int>(memory, "test"), "Should roundtrip memory"); ObjectPath.SetPathValue(memory, "test", 25); memory = memoryScope.GetMemory(dc); Assert.AreEqual(25, ObjectPath.GetPathValue <int>(memory, "test"), "Should roundtrip memory2"); memory = memoryScope.GetMemory(dc); ObjectPath.SetPathValue(memory, "source", "destination"); ObjectPath.SetPathValue(memory, "{source}", 24); Assert.AreEqual(24, ObjectPath.GetPathValue <int>(memory, "{source}"), "Roundtrip computed path"); ObjectPath.RemovePathValue(memory, "{source}"); Assert.AreEqual(false, ObjectPath.TryGetPathValue <int>(memory, "{source}", out var _), "Removed computed path"); ObjectPath.RemovePathValue(memory, "source"); Assert.AreEqual(false, ObjectPath.TryGetPathValue <int>(memory, "{source}", out var _), "No computed path"); } }).StartTestAsync(); }
public async Task SimpleMemoryScopesTest() { await CreateDialogContext(async (dc, ct) => { var dsm = dc.State as DialogStateManager; foreach (var memoryScope in dsm.Configuration.MemoryScopes.Where(ms => !(ms is ThisMemoryScope || ms is DialogMemoryScope || ms is ClassMemoryScope || ms is DialogClassMemoryScope || ms is DialogContextMemoryScope))) { var memory = memoryScope.GetMemory(dc); Assert.NotNull(memory); ObjectPath.SetPathValue(memory, "test", 15); memory = memoryScope.GetMemory(dc); Assert.Equal(15, ObjectPath.GetPathValue <int>(memory, "test")); ObjectPath.SetPathValue(memory, "test", 25); memory = memoryScope.GetMemory(dc); Assert.Equal(25, ObjectPath.GetPathValue <int>(memory, "test")); memory = memoryScope.GetMemory(dc); ObjectPath.SetPathValue(memory, "source", "destination"); ObjectPath.SetPathValue(memory, "{source}", 24); Assert.Equal(24, ObjectPath.GetPathValue <int>(memory, "{source}")); ObjectPath.RemovePathValue(memory, "{source}"); Assert.False(ObjectPath.TryGetPathValue <int>(memory, "{source}", out var _)); ObjectPath.RemovePathValue(memory, "source"); Assert.False(ObjectPath.TryGetPathValue <int>(memory, "{source}", out var _)); } }).StartTestAsync(); }
public void RemovePathValue() { var test = new Dictionary <string, object>(); ObjectPath.SetPathValue(test, "x.y.z", 15); ObjectPath.SetPathValue(test, "x.p", "hello"); ObjectPath.SetPathValue(test, "foo", new { Bar = 15, Blat = "yo" }); ObjectPath.SetPathValue(test, "x.a[1]", "yabba"); ObjectPath.SetPathValue(test, "x.a[0]", "dabba"); ObjectPath.RemovePathValue(test, "x.y.z"); try { ObjectPath.GetPathValue <int>(test, "x.y.z"); throw new XunitException("should have throw exception"); } catch { } Assert.Null(ObjectPath.GetPathValue <string>(test, "x.y.z", null)); Assert.Equal(99, ObjectPath.GetPathValue <int>(test, "x.y.z", 99)); Assert.False(ObjectPath.TryGetPathValue <string>(test, "x.y.z", out var value)); ObjectPath.RemovePathValue(test, "x.a[1]"); Assert.False(ObjectPath.TryGetPathValue <string>(test, "x.a[1]", out string value2)); Assert.True(ObjectPath.TryGetPathValue <string>(test, "x.a[0]", out value2)); Assert.Equal("dabba", value2); }
public void SimpleMemoryScopesTest() { var dc = new DialogContext(new DialogSet(), new TurnContext(new TestAdapter(), new Schema.Activity()), (DialogState) new DialogState()); var dsm = new DialogStateManager(dc); foreach (var memoryScope in DialogStateManager.MemoryScopes.Where(ms => !(ms is ThisMemoryScope || ms is DialogMemoryScope || ms is ClassMemoryScope))) { var memory = memoryScope.GetMemory(dc); Assert.IsNotNull(memory, "should get memory without any set"); ObjectPath.SetPathValue(memory, "test", 15); memory = memoryScope.GetMemory(dc); Assert.AreEqual(15, ObjectPath.GetPathValue <int>(memory, "test"), "Should roundtrip memory"); ObjectPath.SetPathValue(memory, "test", 25); memory = memoryScope.GetMemory(dc); Assert.AreEqual(25, ObjectPath.GetPathValue <int>(memory, "test"), "Should roundtrip memory2"); memory = memoryScope.GetMemory(dc); ObjectPath.SetPathValue(memory, "source", "destination"); ObjectPath.SetPathValue(memory, "{source}", 24); Assert.AreEqual(24, ObjectPath.GetPathValue <int>(memory, "{source}"), "Roundtrip computed path"); ObjectPath.RemovePathValue(memory, "{source}"); Assert.AreEqual(false, ObjectPath.TryGetPathValue <int>(memory, "{source}", out var _), "Removed computed path"); ObjectPath.RemovePathValue(memory, "source"); Assert.AreEqual(false, ObjectPath.TryGetPathValue <int>(memory, "{source}", out var _), "No computed path"); } }