Exemplo n.º 1
0
        async Task RunLimitTests(CancellationToken cancellationToken)
        {
            await ApiAssert.ThrowsException <ConflictException>(() => chatClient.Create(new ChatBot
            {
                Name             = "asdf",
                ConnectionString = "asdf",
                Provider         = ChatProvider.Irc
            }, cancellationToken), ErrorCode.ChatBotMax);

            var bots = await chatClient.List(cancellationToken);

            var discordBot = bots.First(bot => bot.Provider.Value == ChatProvider.Discord);

            // We limited chat bots and channels to 1 and 2 respectively, try violating them
            discordBot.Channels.Add(
                new ChatChannel
            {
                IsAdminChannel    = true,
                IsUpdatesChannel  = false,
                IsWatchdogChannel = true,
                Tag = "butt",
                DiscordChannelId = discordBot.Channels.First().DiscordChannelId
            });

            await ApiAssert.ThrowsException <ApiConflictException>(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels);

            var oldChannels = discordBot.Channels;

            discordBot.Channels     = null;
            discordBot.ChannelLimit = 0;
            await ApiAssert.ThrowsException <ConflictException>(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels);

            discordBot.Channels     = oldChannels;
            discordBot.ChannelLimit = null;
            await ApiAssert.ThrowsException <ConflictException>(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels);

            var instance = metadata.CloneMetadata();

            instance.ChatBotLimit = 0;
            await ApiAssert.ThrowsException <ConflictException>(() => instanceClient.Update(instance, cancellationToken), ErrorCode.ChatBotMax);

            discordBot.ChannelLimit = 20;
            discordBot.Channels     = null;
            await chatClient.Update(discordBot, cancellationToken);
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 public Api.Models.Instance GetMetadata() => metadata.CloneMetadata();