public void TestUpdateConnectionState()
        {
            var exist = new Dictionary <string, BinaryData>
            {
                { "aaa", BinaryData.FromObjectAsJson("aaa") },
                { "bbb", BinaryData.FromObjectAsJson("bbb") }
            };
            var connectionContext = new WebPubSubConnectionContext(eventType: WebPubSubEventType.System, null, null, null, connectionStates: exist);

            var response = new ConnectEventResponse
            {
                UserId = "aaa"
            };

            response.SetState("test", BinaryData.FromObjectAsJson("ddd"));
            response.SetState("bbb", BinaryData.FromObjectAsJson("bbb1"));
            var updated = connectionContext.UpdateStates(response.ConnectionStates);

            // new
            Assert.AreEqual("ddd", updated["test"].ToObjectFromJson <string>());
            // no change
            Assert.AreEqual("aaa", updated["aaa"].ToObjectFromJson <string>());
            // update
            Assert.AreEqual("bbb1", updated["bbb"].ToObjectFromJson <string>());

            response.ClearStates();
            updated = connectionContext.UpdateStates(response.ConnectionStates);

            // After clear is null.
            Assert.IsNull(updated);
        }
Exemple #2
0
            public override ValueTask <ConnectEventResponse> OnConnectAsync(ConnectEventRequest request, CancellationToken cancellationToken)
            {
                var response = new ConnectEventResponse
                {
                    UserId = request.ConnectionContext.UserId
                };

                return(new ValueTask <ConnectEventResponse>(response));
            }