public async Task NewUserBeginsWatchingStream(bool ongoing) { string connectionId = Guid.NewGuid().ToString(); Mock <IHubCallerClients <ISpectatorClient> > mockClients = new Mock <IHubCallerClients <ISpectatorClient> >(); Mock <ISpectatorClient> mockCaller = new Mock <ISpectatorClient>(); mockClients.Setup(clients => clients.Caller).Returns(mockCaller.Object); Mock <IGroupManager> mockGroups = new Mock <IGroupManager>(); Mock <HubCallerContext> mockContext = new Mock <HubCallerContext>(); mockContext.Setup(context => context.UserIdentifier).Returns(watcher_id); mockContext.Setup(context => context.ConnectionId).Returns(connectionId); hub.Context = mockContext.Object; hub.Clients = mockClients.Object; hub.Groups = mockGroups.Object; if (ongoing) { await cache.SetStringAsync(SpectatorHub.GetStateId(streamer_id), JsonConvert.SerializeObject(state)); } await hub.StartWatchingUser(streamer_id); mockGroups.Verify(groups => groups.AddToGroupAsync(connectionId, SpectatorHub.GetGroupId(streamer_id), default)); mockCaller.Verify(clients => clients.UserBeganPlaying(streamer_id, It.Is <SpectatorState>(m => m.Equals(state))), ongoing ? Times.Once : Times.Never); }
public async Task NewUserBeginsWatchingStream(bool ongoing) { string connectionId = Guid.NewGuid().ToString(); Mock <IHubCallerClients <ISpectatorClient> > mockClients = new Mock <IHubCallerClients <ISpectatorClient> >(); Mock <ISpectatorClient> mockCaller = new Mock <ISpectatorClient>(); mockClients.Setup(clients => clients.Caller).Returns(mockCaller.Object); mockClients.Setup(clients => clients.All).Returns(mockCaller.Object); Mock <IGroupManager> mockGroups = new Mock <IGroupManager>(); Mock <HubCallerContext> streamerContext = new Mock <HubCallerContext>(); streamerContext.Setup(context => context.UserIdentifier).Returns(streamer_id.ToString()); Mock <HubCallerContext> watcherContext = new Mock <HubCallerContext>(); watcherContext.Setup(context => context.UserIdentifier).Returns(watcher_id.ToString()); watcherContext.Setup(context => context.ConnectionId).Returns(connectionId); hub.Clients = mockClients.Object; hub.Groups = mockGroups.Object; if (ongoing) { hub.Context = streamerContext.Object; await hub.BeginPlaySession(state); mockCaller.Verify(clients => clients.UserBeganPlaying(streamer_id, It.Is <SpectatorState>(m => m.Equals(state))), Times.Once); } hub.Context = watcherContext.Object; await hub.StartWatchingUser(streamer_id); mockGroups.Verify(groups => groups.AddToGroupAsync(connectionId, SpectatorHub.GetGroupId(streamer_id), default)); mockCaller.Verify(clients => clients.UserBeganPlaying(streamer_id, It.Is <SpectatorState>(m => m.Equals(state))), Times.Exactly(ongoing ? 2 : 0)); }