예제 #1
0
        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);
        }