public async Task RivescriptDialog_StateFromBotToRivescript() { string name = Guid.NewGuid().ToString(); string fileName = CreateTempFile( @"! version = 2.0 +hello bot -Test <get name>"); var conversationState = new ConversationState(new MemoryStorage()); var bot = new TestBot(conversationState, fileName); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(conversationState)) .Use(new InjectState(async(context) => { var dict = await bot.RivescriptDialog.StateProperty.GetAsync(context, () => new RivescriptState()); dict["name"] = name; }) ); await new TestFlow(adapter, (turnContext, cancellationToken) => bot.OnTurnAsync(turnContext, cancellationToken)) .Send("Hello bot") .AssertReply("Test " + name) .StartTestAsync(); }
public async Task RivescriptDialog_StateFromRivescriptToBot() { //Note: The dictionary coming back from the C# Rivescript implementation // eats the "-" in a GUID. This means if we send in "abcde-12345" we get // back "abcde12345". This behavior is confirmed to be scoped to the // Rivescript implementation, and not caused by the BotBuilder Middleware. // To work around this, this test - which is just testing the BotBuilder // code - doesn't use any "-". string uglyGuid = Guid.NewGuid().ToString("N"); bool validationRan = false; string fileName = CreateTempFile( @"! version = 2.0 + value is * - <set test=<star>>value is <get test>"); var conversationState = new ConversationState(new MemoryStorage()); var bot = new TestBot(conversationState, fileName); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(conversationState)) .Use(new ValidateState(async(context) => { var dict = await bot.RivescriptDialog.StateProperty.GetAsync(context, () => new RivescriptState()); Assert.IsTrue( dict["test"] == uglyGuid, $"Incorrect value. Expected '{uglyGuid}', found '{dict["test"]}'"); validationRan = true; }) ); await new TestFlow(adapter, (turnContext, cancellationToken) => bot.OnTurnAsync(turnContext, cancellationToken)) .Send("value is " + uglyGuid) .AssertReply("value is " + uglyGuid) .StartTestAsync(); // Make sure the state validator actually ran. Assert.IsTrue(validationRan, "The State Validator did not run"); }
public async Task RivescriptDialog_HelloBot() { // RiveScript Sample file, taken from their // tutorial at: https://www.rivescript.com/docs/tutorial string fileName = CreateTempFile(script); var conversationState = new ConversationState(new MemoryStorage()); var bot = new TestBot(conversationState, fileName); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(conversationState)); await new TestFlow(adapter, (turnContext, cancellationToken) => bot.OnTurnAsync(turnContext, cancellationToken)) .Send("hello bot") .AssertReply("Hello, human!") .Send("my name is giskard") .AssertReply("Nice to meet you, giskard!") .Send("xyzpdq") .AssertReply("woo!") .Send("cool") .AssertReply("yes it is") .Send("hot") .AssertReply("steamy!") .StartTestAsync(); }