示例#1
0
        public void OnSync_1ClientPresentTwice_DifferentConnections()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IRealtimeChannel>   channel = new Mock <IRealtimeChannel>();
            var target = new Presence(manager.Object, channel.Object, "testClient");

            // Act
            manager.Raise(c => c.MessageReceived += null, new ProtocolMessage(ProtocolMessage.MessageAction.Sync)
            {
                Presence = new PresenceMessage[]
                {
                    new PresenceMessage(PresenceMessage.ActionType.Present, "client1")
                    {
                        ConnectionId = "conn123"
                    },
                    new PresenceMessage(PresenceMessage.ActionType.Present, "client1")
                    {
                        ConnectionId = "connAnn332"
                    }
                }
            });

            // Assert
            PresenceMessage[] presence = target.Get();
            Assert.NotNull(presence);
            Assert.Equal <int>(2, presence.Length);
            Assert.Equal <string>("client1", presence[0].ClientId);
            Assert.Equal <string>("conn123", presence[0].ConnectionId);
            Assert.Equal <PresenceMessage.ActionType>(PresenceMessage.ActionType.Present, presence[0].Action);
            Assert.Equal <string>("client1", presence[1].ClientId);
            Assert.Equal <string>("connAnn332", presence[1].ConnectionId);
            Assert.Equal <PresenceMessage.ActionType>(PresenceMessage.ActionType.Present, presence[1].Action);
        }
示例#2
0
        public void Presence_Get_ReturnsEmptyArray()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IRealtimeChannel>   channel = new Mock <IRealtimeChannel>();
            var target = new Presence(manager.Object, channel.Object, "testClient");

            // Assert
            Assert.NotNull(target.Get());
        }
示例#3
0
        public void OnPresence_Absent_PresenceMapIsUpdated()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IRealtimeChannel>   channel = new Mock <IRealtimeChannel>();
            var target = new Presence(manager.Object, channel.Object, "testClient");

            // Act
            manager.Raise(c => c.MessageReceived += null, new ProtocolMessage(ProtocolMessage.MessageAction.Presence)
            {
                Presence = new PresenceMessage[] { new PresenceMessage(PresenceMessage.ActionType.Absent, "client1") }
            });

            // Assert
            PresenceMessage[] presence = target.Get();
            Assert.NotNull(presence);
            Assert.Equal <int>(0, presence.Length);
        }
示例#4
0
        public void OnPresence_Update_TwiceWithTheSameClientId_NoError()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IRealtimeChannel>   channel = new Mock <IRealtimeChannel>();
            var target = new Presence(manager.Object, channel.Object, "testClient");

            // Act
            manager.Raise(c => c.MessageReceived += null, new ProtocolMessage(ProtocolMessage.MessageAction.Presence)
            {
                Presence = new PresenceMessage[]
                {
                    new PresenceMessage(PresenceMessage.ActionType.Update, "client1"),
                    new PresenceMessage(PresenceMessage.ActionType.Update, "client1"),
                }
            });

            // Assert
            PresenceMessage[] presence = target.Get();
            Assert.NotNull(presence);
            Assert.Equal <int>(1, presence.Length);
            Assert.Equal <string>("client1", presence[0].ClientId);
            Assert.Equal <PresenceMessage.ActionType>(PresenceMessage.ActionType.Update, presence[0].Action);
        }