1

I'm trying to test a dialog which has userState. The userState creates a userProfile and this has to go step to step. I tried to pass userState into my Dialog's constructor and this works when I use cosmos db for my storage. However when I'm testing I have trouble to set up my cosmos db into userState. In Startup.cs this is normally done for me, but I'm not totally sure I understand it. I've tried to use a MemoryStorage but this doesn't carry my info step to step.

I pass it into my dialog constructor like this:

public class MyDialog: ComponentDialog
{
    private UserState _userState;
    public MyDialog(UserState userState)
           : base(nameof(MyDialog))`
     {
         _userState = userState;
          ...

I have two steps that I need state to be saved through

private async Task<DialogTurnResult> SecondStep(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {

            var userStateAccessors = _userState.CreateProperty<UserProfile>(nameof(UserProfile));
            var userProfile= await userStateAccessors.GetAsync(stepContext.Context, () => new UserProfile());
            UserProfile.Name = (string)stepContext.Result;
            ...

And then this also needs to be used in another step:

private async Task<DialogTurnResult> ThirdStep(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var userStateAccessors = _userState.CreateProperty<UserProfile>(nameof(UserProfile));
            var userProfile= await userStateAccessors.GetAsync(stepContext.Context, () => new UserProfile());
            ...

In my test dialog I have:

UserState userState;
        [TestMethod]
        public async Task Test_MyDialog()
        {
            userState = new UserState(new MemoryStorage());
            var myDialog = new MyDialog (userState);
            ...

But as I said before this doesn't carry through from my SecondStep to ThirdStep. This carries through ifI'm just running my bot normally, but doesn't with a test and I think it's due to MemoryStorage. Is this problem possible to solve using MemoryStorage? If not, what should I use or how can I use cosmos storage within the testing environment? Thank you.

1
  • So you want to use CosmosDbStorage instead of MemoryStorage in your test dialog ? Sep 24, 2019 at 6:45

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.