public async Task CustomStateTest() { var testName = "CustomStateTest"; var activities = TranscriptUtilities.GetActivitiesFromFile(ClassName, testName); var storage = new MemoryStorage(); var customState = new CustomState(storage); var testProperty = customState.CreateProperty <CustomStateObject>("Test"); var adapter = new TestAdapter(TestAdapter.CreateConversation(testName)) .Use(new AutoSaveStateMiddleware(customState)); var flow = new TestFlow(adapter, async(context, cancellationToken) => { if (context.Activity.Type == ActivityTypes.Message) { var(command, value) = GetCommandValue(context); switch (command) { case "delete": await testProperty.DeleteAsync(context); break; case "set": { var data = await testProperty.GetAsync(context, () => new CustomStateObject()); data.Value = value; await testProperty.SetAsync(context, data); } break; case "read": { var data = await testProperty.GetAsync(context, () => new CustomStateObject()); await context.SendActivityAsync($"value:{data.Value}"); } break; default: await context.SendActivityAsync("bot message"); break; } } }); await flow.Test(activities).StartTestAsync(); }
public async Task CustomStateTest() { var activities = TranscriptUtilities.GetFromTestContext(TestContext); var storage = new MemoryStorage(); var customState = new CustomState(storage); var testProperty = customState.CreateProperty <CustomStateObject>("Test", () => new CustomStateObject()); TestAdapter adapter = new TestAdapter() .Use(customState); var flow = new TestFlow(adapter, async(context) => { if (context.Activity.Type == ActivityTypes.Message) { var(command, value) = GetCommandValue(context); switch (command) { case "delete": await testProperty.DeleteAsync(context); break; case "set": { var data = await testProperty.GetAsync(context); data.Value = value; await testProperty.SetAsync(context, data); } break; case "read": { var data = await testProperty.GetAsync(context); await context.SendActivityAsync($"value:{data.Value}"); } break; default: await context.SendActivityAsync("bot message"); break; } } }); await flow.Test(activities).StartTestAsync(); }