示例#1
0
        protected override async Task OnSignInInvokeAsync(ITurnContext <IInvokeActivity> turnContext, CancellationToken cancellationToken)
        {
            await _conversationState.LoadAsync(turnContext, true, cancellationToken);

            await _userState.LoadAsync(turnContext, true, cancellationToken);

            await _dialog.RunAsync(turnContext, _conversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken);
        }
示例#2
0
        public async Task State_MultipleLoads()
        {
            // Arrange
            var dictionary = new Dictionary <string, JObject>();
            var userState  = new UserState(new MemoryStorage(dictionary));
            var context    = TestUtilities.CreateEmptyContext();

            // Act
            var propertyA = userState.CreateProperty <string>("propertyA");
            await userState.LoadAsync(context);

            await userState.LoadAsync(context);
        }
示例#3
0
        public async Task LoadSetSave()
        {
            // Arrange
            var dictionary = new Dictionary <string, JObject>();
            var userState  = new UserState(new MemoryStorage(dictionary));
            var context    = TestUtilities.CreateEmptyContext();

            // Act
            var propertyA = userState.CreateProperty <string>("property-a");
            var propertyB = userState.CreateProperty <string>("property-b");

            await userState.LoadAsync(context);

            await propertyA.SetAsync(context, "hello");

            await propertyB.SetAsync(context, "world");

            await userState.SaveChangesAsync(context);

            // Assert
            var obj = dictionary["EmptyContext/users/[email protected]"];

            Assert.AreEqual("hello", obj["property-a"]);
            Assert.AreEqual("world", obj["property-b"]);
        }
示例#4
0
        public async Task State_MultipleSave()
        {
            // Arrange
            var dictionary = new Dictionary <string, JObject>();
            var userState  = new UserState(new MemoryStorage(dictionary));
            var context    = TestUtilities.CreateEmptyContext();

            // Act
            var propertyA = userState.CreateProperty <string>("property-a");
            var propertyB = userState.CreateProperty <string>("property-b");

            await userState.LoadAsync(context);

            await propertyA.SetAsync(context, "hello");

            await propertyB.SetAsync(context, "world");

            await userState.SaveChangesAsync(context);

            await propertyA.SetAsync(context, "hello2");

            await userState.SaveChangesAsync(context);

            var valueA = await propertyA.GetAsync(context);

            Assert.AreEqual("hello2", valueA);
        }
示例#5
0
        protected override async Task OnSignInInvokeAsync(ITurnContext <IInvokeActivity> turnContext, CancellationToken cancellationToken)
        {
            await _conversationState.LoadAsync(turnContext, true, cancellationToken);

            await _userState.LoadAsync(turnContext, true, cancellationToken);

            try
            {
                await _dialog.RunAsync(turnContext, _conversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken);
            }
            catch
            {
                // TODO: remove try/catch once the service is no longer throwing for 'consent required' during ExchangeTokenAsync.
                await turnContext.SendActivityAsync(new Activity { Value = new InvokeResponse()
                                                                   {
                                                                       Status = (int)HttpStatusCode.Conflict
                                                                   }, Type = ActivityTypesEx.InvokeResponse }, cancellationToken).ConfigureAwait(false);
            }
        }