 test: Split Unit and Integration tests into separate projects (#1290)
* Squashed commit of test rewrite changes
fix missing priority speaker flag
rewrite the TestChannelPermissionModify test
add test for GuildPermission modify
separate unit and integration tests, start writing channel and guild permission tests
copy over the color tests
copy over the emote tests
copy the token utils tests
make the mocked entities sealed classes
copy the TypeReaderTests class
properly dispose the CommandService in the TypeReaderTests
start writing tests for EmbedBuilder and related classes
test that properties throw ArgumentException when invalid
add tests for the embed length property
add withFooter tests
finish adding tests to EmbedBuilder
fix bug in value validation of EmbedFieldBuilder
hey, these tests actually found a bug!
add tests for the MentionUtils class
add tests for the Format util class
remove all of the old tests
add analyzer tests (copied from old tests)
add tests for the SnowflakeUtils class
add integration tests
these get around the issue of state persisting between tests by creating and deleting a guild for each set of tests. these shouldn't be run excessively because of the rate limits, but should be fine every now and then
remove unnecessary launchSettings.json
update outdated string
don't create a new guild each time, as that can result in errors
this can happen if a bot creates too many guilds without properly deleting them
add some tests that show that guild can be modified
await async assert
add more measures that created channels are deleted when done
remove "Test" prefix from test method names
I think that this prefix when already displayed under a class with a suffix of "Tests" is redundant
Remove mention of old test project
fix an issue from forgetting to await Assert.ThrowsAsync
explicitly disable parallelization on integration tests
add test for GuildPermission modify
separate unit and integration tests, start writing channel and guild permission tests
copy over the color tests
copy over the emote tests
make the mocked entities sealed classes
properly dispose the CommandService in the TypeReaderTests
fix bug in value validation of EmbedFieldBuilder
hey, these tests actually found a bug!
add tests for the MentionUtils class
add tests for the Format util class
remove all of the old tests
add analyzer tests (copied from old tests)
add tests for the SnowflakeUtils class
add integration tests
these get around the issue of state persisting between tests by creating and deleting a guild for each set of tests. these shouldn't be run excessively because of the rate limits, but should be fine every now and then
remove unnecessary launchSettings.json
update outdated string
don't create a new guild each time, as that can result in errors
this can happen if a bot creates too many guilds without properly deleting them
add more measures that created channels are deleted when done
remove "Test" prefix from test method names
I think that this prefix when already displayed under a class with a suffix of "Tests" is redundant
Remove mention of old test project
fix an issue from forgetting to await Assert.ThrowsAsync
explicitly disable parallelization on integration tests
update the azure CI build script
separate execution of test projects so that if one fails the other will not pass
one of the unit tests failed, but the analzyer tests passed
fix test that would break in different timezones
enable the integration tests (only on dev branch)
* Squashed commit of test rewrite changes
fix missing priority speaker flag
rewrite the TestChannelPermissionModify test
add test for GuildPermission modify
separate unit and integration tests, start writing channel and guild permission tests
copy over the color tests
copy over the emote tests
copy the token utils tests
make the mocked entities sealed classes
copy the TypeReaderTests class
properly dispose the CommandService in the TypeReaderTests
start writing tests for EmbedBuilder and related classes
test that properties throw ArgumentException when invalid
add tests for the embed length property
add withFooter tests
finish adding tests to EmbedBuilder
fix bug in value validation of EmbedFieldBuilder
hey, these tests actually found a bug!
add tests for the MentionUtils class
add tests for the Format util class
remove all of the old tests
add analyzer tests (copied from old tests)
add tests for the SnowflakeUtils class
add integration tests
these get around the issue of state persisting between tests by creating and deleting a guild for each set of tests. these shouldn't be run excessively because of the rate limits, but should be fine every now and then
remove unnecessary launchSettings.json
update outdated string
don't create a new guild each time, as that can result in errors
this can happen if a bot creates too many guilds without properly deleting them
add some tests that show that guild can be modified
await async assert
add more measures that created channels are deleted when done
remove "Test" prefix from test method names
I think that this prefix when already displayed under a class with a suffix of "Tests" is redundant
Remove mention of old test project
fix an issue from forgetting to await Assert.ThrowsAsync
explicitly disable parallelization on integration tests
add test for GuildPermission modify
separate unit and integration tests, start writing channel and guild permission tests
copy over the color tests
copy over the emote tests
make the mocked entities sealed classes
properly dispose the CommandService in the TypeReaderTests
fix bug in value validation of EmbedFieldBuilder
hey, these tests actually found a bug!
add tests for the MentionUtils class
add tests for the Format util class
remove all of the old tests
add analyzer tests (copied from old tests)
add tests for the SnowflakeUtils class
add integration tests
these get around the issue of state persisting between tests by creating and deleting a guild for each set of tests. these shouldn't be run excessively because of the rate limits, but should be fine every now and then
remove unnecessary launchSettings.json
update outdated string
don't create a new guild each time, as that can result in errors
this can happen if a bot creates too many guilds without properly deleting them
add more measures that created channels are deleted when done
remove "Test" prefix from test method names
I think that this prefix when already displayed under a class with a suffix of "Tests" is redundant
Remove mention of old test project
fix an issue from forgetting to await Assert.ThrowsAsync
explicitly disable parallelization on integration tests
update the azure CI build script
separate execution of test projects so that if one fails the other will not pass
one of the unit tests failed, but the analzyer tests passed
fix test that would break in different timezones
enable the integration tests (only on dev branch)
* Update mocked channels for changed SendFileAsync signature
* comment out the integration tests from the build script
no bot token is provided to this script, and use of integration tests in CI is questionable here
* force rebuild because Azure linux build broke
6 years ago |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- using System;
- using System.Collections.Generic;
- using Xunit;
-
- namespace Discord
- {
- /// <summary>
- /// Tests the behavior of the <see cref="Discord.ChannelPermissions"/> type and related functions.
- /// </summary>
- public class ChannelPermissionsTests
- {
- /// <summary>
- /// Tests the default value of the <see cref="Discord.ChannelPermissions"/> constructor.
- /// </summary>
- [Fact]
- public void DefaultConstructor()
- {
- var permission = new ChannelPermissions();
- Assert.Equal((ulong)0, permission.RawValue);
- Assert.Equal(ChannelPermissions.None.RawValue, permission.RawValue);
- }
-
- /// <summary>
- /// Tests the behavior of the <see cref="Discord.ChannelPermission"/> raw value constructor.
- /// </summary>
- [Fact]
- public void RawValueConstructor()
- {
- // returns all of the values that will be tested
- // a Theory cannot be used here, because these values are not all constants
- IEnumerable<ulong> GetTestValues()
- {
- yield return 0;
- yield return ChannelPermissions.Category.RawValue;
- yield return ChannelPermissions.DM.RawValue;
- yield return ChannelPermissions.Group.RawValue;
- yield return ChannelPermissions.None.RawValue;
- yield return ChannelPermissions.Text.RawValue;
- yield return ChannelPermissions.Voice.RawValue;
- };
-
- foreach (var rawValue in GetTestValues())
- {
- var p = new ChannelPermissions(rawValue);
- Assert.Equal(rawValue, p.RawValue);
- }
- }
-
- /// <summary>
- /// Tests the behavior of the <see cref="Discord.ChannelPermissions"/> constructor for each
- /// of it's flags.
- /// </summary>
- [Fact]
- public void FlagsConstructor()
- {
- // util method for asserting that the constructor sets the given flag
- void AssertFlag(Func<ChannelPermissions> cstr, ChannelPermission flag)
- {
- var p = cstr();
- // ensure that this flag is set to true
- Assert.True(p.Has(flag));
- // ensure that only this flag is set
- Assert.Equal((ulong)flag, p.RawValue);
- }
-
- AssertFlag(() => new ChannelPermissions(createInstantInvite: true), ChannelPermission.CreateInstantInvite);
- AssertFlag(() => new ChannelPermissions(manageChannel: true), ChannelPermission.ManageChannels);
- AssertFlag(() => new ChannelPermissions(addReactions: true), ChannelPermission.AddReactions);
- AssertFlag(() => new ChannelPermissions(viewChannel: true), ChannelPermission.ViewChannel);
- AssertFlag(() => new ChannelPermissions(sendMessages: true), ChannelPermission.SendMessages);
- AssertFlag(() => new ChannelPermissions(sendTTSMessages: true), ChannelPermission.SendTTSMessages);
- AssertFlag(() => new ChannelPermissions(manageMessages: true), ChannelPermission.ManageMessages);
- AssertFlag(() => new ChannelPermissions(embedLinks: true), ChannelPermission.EmbedLinks);
- AssertFlag(() => new ChannelPermissions(attachFiles: true), ChannelPermission.AttachFiles);
- AssertFlag(() => new ChannelPermissions(readMessageHistory: true), ChannelPermission.ReadMessageHistory);
- AssertFlag(() => new ChannelPermissions(mentionEveryone: true), ChannelPermission.MentionEveryone);
- AssertFlag(() => new ChannelPermissions(useExternalEmojis: true), ChannelPermission.UseExternalEmojis);
- AssertFlag(() => new ChannelPermissions(connect: true), ChannelPermission.Connect);
- AssertFlag(() => new ChannelPermissions(speak: true), ChannelPermission.Speak);
- AssertFlag(() => new ChannelPermissions(muteMembers: true), ChannelPermission.MuteMembers);
- AssertFlag(() => new ChannelPermissions(deafenMembers: true), ChannelPermission.DeafenMembers);
- AssertFlag(() => new ChannelPermissions(moveMembers: true), ChannelPermission.MoveMembers);
- AssertFlag(() => new ChannelPermissions(useVoiceActivation: true), ChannelPermission.UseVAD);
- AssertFlag(() => new ChannelPermissions(prioritySpeaker: true), ChannelPermission.PrioritySpeaker);
- AssertFlag(() => new ChannelPermissions(manageRoles: true), ChannelPermission.ManageRoles);
- AssertFlag(() => new ChannelPermissions(manageWebhooks: true), ChannelPermission.ManageWebhooks);
- }
-
- /// <summary>
- /// Tests the behavior of <see cref="Discord.ChannelPermissions.Modify(bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?)"/>
- /// with each of the parameters.
- /// </summary>
- [Fact]
- public void Modify()
- {
- // asserts that a channel permission flag value can be checked
- // and that modify can set and unset each flag
- // and that ToList performs as expected
- void AssertUtil(ChannelPermission permission,
- Func<ChannelPermissions, bool> has,
- Func<ChannelPermissions, bool, ChannelPermissions> modify)
- {
- var perm = new ChannelPermissions();
- // ensure permission initially false
- // use both the function and Has to ensure that the GetPermission
- // function is working
- Assert.False(has(perm));
- Assert.False(perm.Has(permission));
-
- // enable it, and ensure that it gets set
- perm = modify(perm, true);
- Assert.True(has(perm));
- Assert.True(perm.Has(permission));
-
- // check ToList behavior
- var list = perm.ToList();
- Assert.Contains(permission, list);
- Assert.Single(list);
-
- // set it false again
- perm = modify(perm, false);
- Assert.False(has(perm));
- Assert.False(perm.Has(permission));
-
- // ensure that no perms are set now
- Assert.Equal(ChannelPermissions.None.RawValue, perm.RawValue);
- }
-
- AssertUtil(ChannelPermission.CreateInstantInvite, x => x.CreateInstantInvite, (p, enable) => p.Modify(createInstantInvite: enable));
- AssertUtil(ChannelPermission.ManageChannels, x => x.ManageChannel, (p, enable) => p.Modify(manageChannel: enable));
- AssertUtil(ChannelPermission.AddReactions, x => x.AddReactions, (p, enable) => p.Modify(addReactions: enable));
- AssertUtil(ChannelPermission.ViewChannel, x => x.ViewChannel, (p, enable) => p.Modify(viewChannel: enable));
- AssertUtil(ChannelPermission.SendMessages, x => x.SendMessages, (p, enable) => p.Modify(sendMessages: enable));
- AssertUtil(ChannelPermission.SendTTSMessages, x => x.SendTTSMessages, (p, enable) => p.Modify(sendTTSMessages: enable));
- AssertUtil(ChannelPermission.ManageMessages, x => x.ManageMessages, (p, enable) => p.Modify(manageMessages: enable));
- AssertUtil(ChannelPermission.EmbedLinks, x => x.EmbedLinks, (p, enable) => p.Modify(embedLinks: enable));
- AssertUtil(ChannelPermission.AttachFiles, x => x.AttachFiles, (p, enable) => p.Modify(attachFiles: enable));
- AssertUtil(ChannelPermission.ReadMessageHistory, x => x.ReadMessageHistory, (p, enable) => p.Modify(readMessageHistory: enable));
- AssertUtil(ChannelPermission.MentionEveryone, x => x.MentionEveryone, (p, enable) => p.Modify(mentionEveryone: enable));
- AssertUtil(ChannelPermission.UseExternalEmojis, x => x.UseExternalEmojis, (p, enable) => p.Modify(useExternalEmojis: enable));
- AssertUtil(ChannelPermission.Connect, x => x.Connect, (p, enable) => p.Modify(connect: enable));
- AssertUtil(ChannelPermission.Speak, x => x.Speak, (p, enable) => p.Modify(speak: enable));
- AssertUtil(ChannelPermission.MuteMembers, x => x.MuteMembers, (p, enable) => p.Modify(muteMembers: enable));
- AssertUtil(ChannelPermission.DeafenMembers, x => x.DeafenMembers, (p, enable) => p.Modify(deafenMembers: enable));
- AssertUtil(ChannelPermission.MoveMembers, x => x.MoveMembers, (p, enable) => p.Modify(moveMembers: enable));
- AssertUtil(ChannelPermission.UseVAD, x => x.UseVAD, (p, enable) => p.Modify(useVoiceActivation: enable));
- AssertUtil(ChannelPermission.ManageRoles, x => x.ManageRoles, (p, enable) => p.Modify(manageRoles: enable));
- AssertUtil(ChannelPermission.ManageWebhooks, x => x.ManageWebhooks, (p, enable) => p.Modify(manageWebhooks: enable));
- AssertUtil(ChannelPermission.PrioritySpeaker, x => x.PrioritySpeaker, (p, enable) => p.Modify(prioritySpeaker: enable));
- }
-
- /// <summary>
- /// Tests that <see cref="ChannelPermissions.All(IChannel)"/> for a null channel will throw an <see cref="ArgumentException"/>.
- /// </summary>
- [Fact]
- public void ChannelTypeResolution_Null()
- {
- Assert.Throws<ArgumentException>(() =>
- {
- ChannelPermissions.All(null);
- });
- }
-
- /// <summary>
- /// Tests that <see cref="ChannelPermissions.All(IChannel)"/> for an <see cref="ITextChannel"/> will return a value
- /// equivalent to <see cref="ChannelPermissions.Text"/>.
- /// </summary>
- [Fact]
- public void ChannelTypeResolution_Text()
- {
- Assert.Equal(ChannelPermissions.Text.RawValue, ChannelPermissions.All(new MockedTextChannel()).RawValue);
- }
-
- /// <summary>
- /// Tests that <see cref="ChannelPermissions.All(IChannel)"/> for an <see cref="IVoiceChannel"/> will return a value
- /// equivalent to <see cref="ChannelPermissions.Voice"/>.
- /// </summary>
- [Fact]
- public void ChannelTypeResolution_Voice()
- {
- Assert.Equal(ChannelPermissions.Voice.RawValue, ChannelPermissions.All(new MockedVoiceChannel()).RawValue);
- }
-
- /// <summary>
- /// Tests that <see cref="ChannelPermissions.All(IChannel)"/> for an <see cref="ICategoryChannel"/> will return a value
- /// equivalent to <see cref="ChannelPermissions.Category"/>.
- /// </summary>
- [Fact]
- public void ChannelTypeResolution_Category()
- {
- Assert.Equal(ChannelPermissions.Category.RawValue, ChannelPermissions.All(new MockedCategoryChannel()).RawValue);
- }
-
- /// <summary>
- /// Tests that <see cref="ChannelPermissions.All(IChannel)"/> for an <see cref="IDMChannel"/> will return a value
- /// equivalent to <see cref="ChannelPermissions.DM"/>.
- /// </summary>
- [Fact]
- public void ChannelTypeResolution_DM()
- {
- Assert.Equal(ChannelPermissions.DM.RawValue, ChannelPermissions.All(new MockedDMChannel()).RawValue);
- }
-
- /// <summary>
- /// Tests that <see cref="ChannelPermissions.All(IChannel)"/> for an <see cref="IGroupChannel"/> will return a value
- /// equivalent to <see cref="ChannelPermissions.Group"/>.
- /// </summary>
- [Fact]
- public void ChannelTypeResolution_Group()
- {
- Assert.Equal(ChannelPermissions.Group.RawValue, ChannelPermissions.All(new MockedGroupChannel()).RawValue);
- }
-
- /// <summary>
- /// Tests that <see cref="ChannelPermissions.All(IChannel)"/> for an invalid channel will throw an <see cref="ArgumentException"/>.
- /// </summary>
- [Fact]
- public void ChannelTypeResolution_Invalid()
- {
- Assert.Throws<ArgumentException>(() => ChannelPermissions.All(new MockedInvalidChannel()));
- }
- }
- }
|