Пример #1
0
        public static TestCaseData BuildTestCaseData_HandleNotificationAsync_ReadyNotification(
            IReadOnlyCollection <IReadOnlyCollection <ulong> > roleIdsByGuild)
        {
            var guilds = roleIdsByGuild
                         .Select(roleIds =>
            {
                var roles = roleIds
                            .Select(roleId =>
                {
                    var mockRole = new Mock <ISocketRole>();
                    mockRole
                    .Setup(x => x.Id)
                    .Returns(roleId);

                    return(mockRole.Object);
                })
                            .ToArray();

                var mockGuild = new Mock <ISocketGuild>();
                mockGuild
                .Setup(x => x.Roles)
                .Returns(roles);

                return(mockGuild.Object);
            })
                         .ToArray();

            var notification = new ReadyNotification();

            return(new TestCaseData(guilds, notification));
        }
Пример #2
0
 public async Task HandleNotificationAsync(
     ReadyNotification notification,
     CancellationToken cancellationToken)
 {
     foreach (var role in _discordSocketClient.Guilds.SelectMany(guild => guild.Roles))
     {
         await _roleService.TrackRoleAsync(role, cancellationToken);
     }
 }
Пример #3
0
    private IUnityTask OnReadyNotification(ReadyNotification message, IPEndPoint address)
    {
        if (!IsPlayerConnected(address))
        {
            return(EmptyTask);
        }

        if (_playersReady.Add(address) && _playersReady.Count == 2)
        {
            _playersReady.Clear();
            _clientsReadyTask.SetReady();
            _clientsReadyTask = null;
        }

        return(EmptyTask);
    }
Пример #4
0
        public async Task HandleNotificationAsync_ReadyNotification_Always_TracksGuildsRoles(
            IReadOnlyCollection <ISocketGuild> guilds,
            ReadyNotification notification)
        {
            using var testContext = new TestContext(
                      guilds);

            var uut = testContext.BuildUut();

            await uut.HandleNotificationAsync(
                notification,
                testContext.CancellationToken);

            var roles = guilds.SelectMany(x => x.Roles)
                        .ToArray();

            foreach (var role in roles)
            {
                testContext.MockRoleService.ShouldHaveReceived(x => x
                                                               .TrackRoleAsync(role, testContext.CancellationToken));
            }
            testContext.MockRoleService.ShouldHaveReceived(x => x
                                                           .TrackRoleAsync(It.IsAny <IRole>(), It.IsAny <CancellationToken>()), Times.Exactly(roles.Length));
        }