Exemplo n.º 1
0
        public void HandleNotificationAsync_GuildAvailableNotification_NoChannelsAreTextChannel_CompletesImmediately(params Type[] channelTypes)
        {
            var autoMocker = new AutoMocker();

            var uut = autoMocker.CreateInstance <ChannelTrackingBehavior>();

            var mockChannels = channelTypes
                               .Select(x => typeof(Mock <>).MakeGenericType(x).GetConstructor(Array.Empty <Type>()).Invoke(Array.Empty <object>()) as Mock)
                               .ToArray();

            var mockGuild = new Mock <ISocketGuild>();

            mockGuild
            .Setup(x => x.Channels)
            .Returns(mockChannels
                     .Select(x => x.Object as ISocketGuildChannel)
                     .ToArray());

            var notification = new GuildAvailableNotification(mockGuild.Object);

            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                uut.HandleNotificationAsync(notification, cancellationTokenSource.Token)
                .IsCompletedSuccessfully.ShouldBeTrue();

                autoMocker.GetMock <IChannelService>()
                .Invocations.ShouldBeEmpty();
            }
        }
        public void Constructor_Always_PropertiesAreGiven()
        {
            var mockGuild = new Mock <ISocketGuild>();

            var uut = new GuildAvailableNotification(mockGuild.Object);

            uut.Guild.ShouldBeSameAs(mockGuild.Object);
        }
        public static TestCaseData BuildTestCaseData_HandleNotificationAsync_GuildAvailableNotification(
            ulong selfUserId)
        {
            var mockGuildUser = new Mock <ISocketGuildUser>();

            var mockGuild = new Mock <ISocketGuild>();

            mockGuild
            .Setup(x => x.GetUser(It.IsAny <ulong>()))
            .Returns(mockGuildUser.Object);

            var notification = new GuildAvailableNotification(
                mockGuild.Object);

            return(new TestCaseData(selfUserId, mockGuild, mockGuildUser, notification));
        }
Exemplo n.º 4
0
        public async Task HandleNotificationAsync_GuildAvailableNotification_Always_InvokesAutoConfigureGuildAsync()
        {
            var autoMocker = new AutoMocker();

            var uut = autoMocker.CreateInstance <AuthorizationAutoConfigBehavior>();

            var guild = autoMocker.Get <ISocketGuild>();

            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                var notification = new GuildAvailableNotification(guild);

                await uut.HandleNotificationAsync(notification, cancellationTokenSource.Token);

                autoMocker.GetMock <IAuthorizationService>()
                .ShouldHaveReceived(x => x.AutoConfigureGuildAsync(guild, cancellationTokenSource.Token));
            }
        }
        public static TestCaseData BuildTestCaseData_HandleNotificationAsync_GuildAvailableNotification(
            int guildMemberCount,
            string guildName)
        {
            var mockGuild = new Mock <ISocketGuild>();

            mockGuild
            .Setup(x => x.MemberCount)
            .Returns(guildMemberCount);
            mockGuild
            .Setup(x => x.Name)
            .Returns(guildName);

            var notification = new GuildAvailableNotification(
                mockGuild.Object);

            return(new TestCaseData(notification));
        }
Exemplo n.º 6
0
        public async Task HandleNotificationAsync_GuildAvailableNotification_AnyChannelIsTextChannel_TracksTextChannels(params Type[] channelTypes)
        {
            var autoMocker = new AutoMocker();

            var uut = autoMocker.CreateInstance <ChannelTrackingBehavior>();

            var mockChannels = channelTypes
                               .Select(x => typeof(Mock <>).MakeGenericType(x).GetConstructor(Array.Empty <Type>()).Invoke(Array.Empty <object>()) as Mock)
                               .ToArray();

            var mockGuild = new Mock <ISocketGuild>();

            mockGuild
            .Setup(x => x.Channels)
            .Returns(mockChannels
                     .Select(x => x.Object as ISocketGuildChannel)
                     .ToArray());

            var notification = new GuildAvailableNotification(mockGuild.Object);

            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                await uut.HandleNotificationAsync(notification, cancellationTokenSource.Token);

                var mockChannelService = autoMocker.GetMock <IChannelService>();

                var textChannels = mockChannels
                                   .Select(x => x.Object)
                                   .OfType <ISocketTextChannel>()
                                   .ToArray();

                foreach (var textChannel in textChannels)
                {
                    mockChannelService.ShouldHaveReceived(x => x.TrackChannelAsync(textChannel, cancellationTokenSource.Token));
                }

                mockChannelService
                .Invocations
                .Where(x => x.Method.Name == nameof(IChannelService.TrackChannelAsync))
                .Select(x => x.Arguments[0])
                .ShouldBe(textChannels, ignoreOrder: true);
            }
        }