public async Task ShouldCreateGameAndSendNotificationsWhenGameWasStarted() { // Arrange string myUserId = Guid.NewGuid().ToString(); string[] friendUserIds = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; string gameTitle = "My Game"; var notificationServiceMock = new Mock <INotificationService>(); var manager = new GameRepository(); var searchUsersQuery = SetupHelpers.SetupUserRepository(friendUserIds.Concat(new[] { myUserId })); var command = new StartGameCommand(myUserId, gameTitle, friendUserIds); var handler = new StartGameCommandHandler(manager, searchUsersQuery, new Mock <IActivityRepository>().Object, notificationServiceMock.Object, new Mock <ITranslationService>().Object); // Act StartGameResultDTO result = await handler.Handle(command, CancellationToken.None); // Assert var game = manager.Get(result.GameId); Assert.Equal(result.GameId, game.Id); Assert.NotNull(result); Assert.NotEqual(default(Guid), result.GameId); notificationServiceMock.Verify(s => s.SendSignalRMessageAsync( It.Is <IReadOnlyList <string> >(u => AreEqual(u, friendUserIds)), Shared.Constants.SignalR.NotificationHubName, HubMethodNames.GameStarted, It.Is <GameStartedMessage>(m => m.GameId == result.GameId && m.Title == gameTitle && AreEqual <string>(friendUserIds, m.UserIds))), Times.Once); notificationServiceMock.Verify(s => s.SendWebPushMessage(It.IsAny <IEnumerable <PushInfo> >(), It.Is <WebPushNotificationMessage>(m => m.data.url.Contains(game.Id.ToString()))), Times.Once); }
private static StartGameCommandHandler SetupStartGameCommandHandler( IEnumerable <string> testUserIds, out GameRepository gameManager, out Mock <INotificationService> notificationServiceMock, out Mock <IActivityRepository> activityRepositoryMock) { gameManager = new GameRepository(); gameManager.DefaultGameDuration = TimeSpan.FromSeconds(1); notificationServiceMock = new Mock <INotificationService>(); var searchUsersQuery = SetupHelpers.SetupUserRepository(testUserIds); activityRepositoryMock = new Mock <IActivityRepository>(); activityRepositoryMock .Setup(a => a.AddActivityAsync(It.IsAny <ActivityEntity>())) .ReturnsAsync((ActivityEntity _a) => _a); var startGameCommand = new StartGameCommandHandler( gameManager, searchUsersQuery, activityRepositoryMock.Object, notificationServiceMock.Object, new Mock <ITranslationService>().Object); return(startGameCommand); }