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); }
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()); }
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); }
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); }