You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EmbedBuilderTests.cs 15 kB

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
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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. using System;
  2. using System.Collections.Generic;
  3. using Xunit;
  4. namespace Discord
  5. {
  6. /// <summary>
  7. /// Tests the <see cref="Discord.EmbedBuilder"/> class.
  8. /// </summary>
  9. public class EmbedBuilderTests
  10. {
  11. private const string name = "chrisj";
  12. private const string icon = "https://meowpuffygottem.fun/blob.png";
  13. private const string url = "https://meowpuffygottem.fun/";
  14. /// <summary>
  15. /// Tests the behavior of <see cref="EmbedBuilder.WithAuthor(string, string, string)"/>.
  16. /// </summary>
  17. [Fact]
  18. public void WithAuthor_Strings()
  19. {
  20. var builder = new EmbedBuilder();
  21. // null by default
  22. Assert.Null(builder.Author);
  23. builder = new EmbedBuilder()
  24. .WithAuthor(name, icon, url);
  25. Assert.NotNull(builder.Author);
  26. Assert.Equal(name, builder.Author.Name);
  27. Assert.Equal(icon, builder.Author.IconUrl);
  28. Assert.Equal(url, builder.Author.Url);
  29. }
  30. /// <summary>
  31. /// Tests the behavior of <see cref="EmbedBuilder.WithAuthor(EmbedAuthorBuilder)"/>
  32. /// </summary>
  33. [Fact]
  34. public void WithAuthor_AuthorBuilder()
  35. {
  36. var author = new EmbedAuthorBuilder()
  37. .WithIconUrl(icon)
  38. .WithName(name)
  39. .WithUrl(url);
  40. var builder = new EmbedBuilder()
  41. .WithAuthor(author);
  42. Assert.NotNull(builder.Author);
  43. Assert.Equal(name, builder.Author.Name);
  44. Assert.Equal(icon, builder.Author.IconUrl);
  45. Assert.Equal(url, builder.Author.Url);
  46. }
  47. /// <summary>
  48. /// Tests the behavior of <see cref="EmbedBuilder.WithAuthor(Action{EmbedAuthorBuilder})"/>
  49. /// </summary>
  50. [Fact]
  51. public void WithAuthor_ActionAuthorBuilder()
  52. {
  53. var builder = new EmbedBuilder()
  54. .WithAuthor((author) =>
  55. author.WithIconUrl(icon)
  56. .WithName(name)
  57. .WithUrl(url));
  58. Assert.NotNull(builder.Author);
  59. Assert.Equal(name, builder.Author.Name);
  60. Assert.Equal(icon, builder.Author.IconUrl);
  61. Assert.Equal(url, builder.Author.Url);
  62. }
  63. /// <summary>
  64. /// Tests the behavior of <see cref="EmbedAuthorBuilder"/>.
  65. /// </summary>
  66. [Fact]
  67. public void EmbedAuthorBuilder()
  68. {
  69. var builder = new EmbedAuthorBuilder()
  70. .WithIconUrl(icon)
  71. .WithName(name)
  72. .WithUrl(url);
  73. Assert.Equal(icon, builder.IconUrl);
  74. Assert.Equal(name, builder.Name);
  75. Assert.Equal(url, builder.Url);
  76. }
  77. /// <summary>
  78. /// Tests that invalid titles throw an <see cref="ArgumentException"/>.
  79. /// </summary>
  80. /// <param name="title">The embed title to set.</param>
  81. [Theory]
  82. // 257 chars
  83. [InlineData("jVyLChmA7aBZozXQuZ3VDEcwW6zOq0nteOVYBZi31ny73rpXfSSBXR4Jw6FiplDKQseKskwRMuBZkUewrewqAbkBZpslHirvC5nEzRySoDIdTRnkVvTXZUXg75l3bQCjuuHxDd6DfrY8ihd6yZX1Y0XFeg239YBcYV4TpL9uQ8H3HFYxrWhLlG2PRVjUmiglP5iXkawszNwMVm1SZ5LZT4jkMZHxFegVi7170d16iaPWOovu50aDDHy087XBtLKVa")]
  84. // 257 chars of whitespace
  85. [InlineData(" ")]
  86. public void Title_Invalid(string title)
  87. {
  88. Assert.Throws<ArgumentException>(() =>
  89. {
  90. var builder = new EmbedBuilder();
  91. builder.Title = title;
  92. });
  93. Assert.Throws<ArgumentException>(() =>
  94. {
  95. new EmbedBuilder().WithTitle(title);
  96. });
  97. }
  98. /// <summary>
  99. /// Tests that valid titles do not throw any exceptions.
  100. /// </summary>
  101. /// <param name="title">The embed title to set.</param>
  102. [Theory]
  103. // 256 chars
  104. [InlineData("jVyLChmA7aBZozXQuZ3VDEcwW6zOq0nteOVYBZi31ny73rpXfSSBXR4Jw6FiplDKQseKskwRMuBZkUewrewqAbkBZpslHirvC5nEzRySoDIdTRnkVvTXZUXg75l3bQCjuuHxDd6DfrY8ihd6yZX1Y0XFeg239YBcYV4TpL9uQ8H3HFYxrWhLlG2PRVjUmiglP5iXkawszNwMVm1SZ5LZT4jkMZHxFegVi7170d16iaPWOovu50aDDHy087XBtLKV")]
  105. public void Tile_Valid(string title)
  106. {
  107. var builder = new EmbedBuilder();
  108. builder.Title = title;
  109. new EmbedBuilder().WithTitle(title);
  110. }
  111. /// <summary>
  112. /// Tests that invalid descriptions throw an <see cref="ArgumentException"/>.
  113. /// </summary>
  114. [Fact]
  115. public void Description_Invalid()
  116. {
  117. IEnumerable<string> GetInvalid()
  118. {
  119. yield return new string('a', 4097);
  120. }
  121. foreach (var description in GetInvalid())
  122. {
  123. Assert.Throws<ArgumentException>(() => new EmbedBuilder().WithDescription(description));
  124. Assert.Throws<ArgumentException>(() =>
  125. {
  126. var b = new EmbedBuilder();
  127. b.Description = description;
  128. });
  129. }
  130. }
  131. /// <summary>
  132. /// Tests that valid descriptions do not throw any exceptions.
  133. /// </summary>
  134. [Fact]
  135. public void Description_Valid()
  136. {
  137. IEnumerable<string> GetValid()
  138. {
  139. yield return string.Empty;
  140. yield return null;
  141. yield return new string('a', 4096);
  142. }
  143. foreach (var description in GetValid())
  144. {
  145. var b = new EmbedBuilder().WithDescription(description);
  146. Assert.Equal(description, b.Description);
  147. b = new EmbedBuilder();
  148. b.Description = description;
  149. Assert.Equal(description, b.Description);
  150. }
  151. }
  152. /// <summary>
  153. /// Tests that valid urls do not throw any exceptions.
  154. /// </summary>
  155. /// <param name="url">The url to set.</param>
  156. [Theory]
  157. [InlineData(null)]
  158. [InlineData("")]
  159. [InlineData("https://docs.stillu.cc")]
  160. public void Url_Valid(string url)
  161. {
  162. // does not throw an exception
  163. var result = new EmbedBuilder()
  164. .WithUrl(url)
  165. .WithImageUrl(url)
  166. .WithThumbnailUrl(url);
  167. Assert.Equal(result.Url, url);
  168. Assert.Equal(result.ImageUrl, url);
  169. Assert.Equal(result.ThumbnailUrl, url);
  170. result = new EmbedBuilder();
  171. result.Url = url;
  172. result.ImageUrl = url;
  173. result.ThumbnailUrl = url;
  174. Assert.Equal(result.Url, url);
  175. Assert.Equal(result.ImageUrl, url);
  176. Assert.Equal(result.ThumbnailUrl, url);
  177. }
  178. /// <summary>
  179. /// Tests the value of the <see cref="EmbedBuilder.Length"/> property when there are no fields set.
  180. /// </summary>
  181. [Fact]
  182. public void Length_Empty()
  183. {
  184. var empty = new EmbedBuilder();
  185. Assert.Equal(0, empty.Length);
  186. }
  187. /// <summary>
  188. /// Tests the value of the <see cref="EmbedBuilder.Length"/> property when all fields are set.
  189. /// </summary>
  190. [Fact]
  191. public void Length()
  192. {
  193. var e = new EmbedBuilder()
  194. .WithAuthor(name, icon, url)
  195. .WithColor(Color.Blue)
  196. .WithDescription("This is the test description.")
  197. .WithFooter("This is the footer", url)
  198. .WithImageUrl(url)
  199. .WithThumbnailUrl(url)
  200. .WithTimestamp(DateTimeOffset.MinValue)
  201. .WithTitle("This is the title")
  202. .WithUrl(url)
  203. .AddField("Field 1", "Inline", true)
  204. .AddField("Field 2", "Not Inline", false);
  205. Assert.Equal(100, e.Length);
  206. }
  207. /// <summary>
  208. /// Tests the behavior of <see cref="EmbedBuilder.WithCurrentTimestamp"/>.
  209. /// </summary>
  210. [Fact]
  211. public void WithCurrentTimestamp()
  212. {
  213. var e = new EmbedBuilder()
  214. .WithCurrentTimestamp();
  215. // ensure within a second of accuracy
  216. Assert.Equal(DateTime.UtcNow, e.Timestamp.Value.UtcDateTime, TimeSpan.FromSeconds(1));
  217. }
  218. /// <summary>
  219. /// Tests the behavior of <see cref="EmbedBuilder.WithColor(Color)"/>.
  220. /// </summary>
  221. [Fact]
  222. public void WithColor()
  223. {
  224. // use WithColor
  225. var e = new EmbedBuilder().WithColor(Color.Red);
  226. Assert.Equal(Color.Red.RawValue, e.Color.Value.RawValue);
  227. }
  228. /// <summary>
  229. /// Tests the behavior of <see cref="EmbedBuilder.WithFooter(Action{EmbedFooterBuilder})"/>
  230. /// </summary>
  231. [Fact]
  232. public void WithFooter_ActionFooterBuilder()
  233. {
  234. var e = new EmbedBuilder()
  235. .WithFooter(x =>
  236. {
  237. x.IconUrl = url;
  238. x.Text = name;
  239. });
  240. Assert.Equal(url, e.Footer.IconUrl);
  241. Assert.Equal(name, e.Footer.Text);
  242. }
  243. /// <summary>
  244. /// Tests the behavior of <see cref="EmbedBuilder.WithFooter(EmbedFooterBuilder)"/>
  245. /// </summary>
  246. [Fact]
  247. public void WithFooter_FooterBuilder()
  248. {
  249. var footer = new EmbedFooterBuilder()
  250. {
  251. IconUrl = url,
  252. Text = name
  253. };
  254. var e = new EmbedBuilder()
  255. .WithFooter(footer);
  256. Assert.Equal(url, e.Footer.IconUrl);
  257. Assert.Equal(name, e.Footer.Text);
  258. // use the property
  259. e = new EmbedBuilder();
  260. e.Footer = footer;
  261. Assert.Equal(url, e.Footer.IconUrl);
  262. Assert.Equal(name, e.Footer.Text);
  263. }
  264. /// <summary>
  265. /// Tests the behavior of <see cref="EmbedBuilder.WithFooter(string, string)"/>
  266. /// </summary>
  267. [Fact]
  268. public void WithFooter_Strings()
  269. {
  270. var e = new EmbedBuilder()
  271. .WithFooter(name, url);
  272. Assert.Equal(url, e.Footer.IconUrl);
  273. Assert.Equal(name, e.Footer.Text);
  274. }
  275. /// <summary>
  276. /// Tests the behavior of <see cref="EmbedFooterBuilder"/>.
  277. /// </summary>
  278. [Fact]
  279. public void EmbedFooterBuilder()
  280. {
  281. var footer = new EmbedFooterBuilder()
  282. .WithIconUrl(url)
  283. .WithText(name);
  284. Assert.Equal(url, footer.IconUrl);
  285. Assert.Equal(name, footer.Text);
  286. }
  287. /// <summary>
  288. /// Tests that invalid text throws an <see cref="ArgumentException"/>.
  289. /// </summary>
  290. [Fact]
  291. public void EmbedFooterBuilder_InvalidText()
  292. {
  293. Assert.Throws<ArgumentException>(() =>
  294. {
  295. new EmbedFooterBuilder().WithText(new string('a', 2049));
  296. });
  297. }
  298. [Fact]
  299. public void AddField_Strings()
  300. {
  301. var e = new EmbedBuilder()
  302. .AddField("name", "value", true);
  303. Assert.Equal("name", e.Fields[0].Name);
  304. Assert.Equal("value", e.Fields[0].Value);
  305. Assert.True(e.Fields[0].IsInline);
  306. }
  307. [Fact]
  308. public void AddField_EmbedFieldBuilder()
  309. {
  310. var field = new EmbedFieldBuilder()
  311. .WithIsInline(true)
  312. .WithValue("value")
  313. .WithName("name");
  314. var e = new EmbedBuilder()
  315. .AddField(field);
  316. Assert.Equal("name", e.Fields[0].Name);
  317. Assert.Equal("value", e.Fields[0].Value);
  318. Assert.True(e.Fields[0].IsInline);
  319. }
  320. [Fact]
  321. public void AddField_ActionEmbedFieldBuilder()
  322. {
  323. var e = new EmbedBuilder()
  324. .AddField(x => x
  325. .WithName("name")
  326. .WithValue("value")
  327. .WithIsInline(true));
  328. Assert.Equal("name", e.Fields[0].Name);
  329. Assert.Equal("value", e.Fields[0].Value);
  330. Assert.True(e.Fields[0].IsInline);
  331. }
  332. [Fact]
  333. public void AddField_TooManyFields()
  334. {
  335. var e = new EmbedBuilder();
  336. for (var i = 0; i < 25; i++)
  337. {
  338. e = e.AddField("name", "value", false);
  339. }
  340. Assert.Throws<ArgumentException>(() =>
  341. {
  342. e = e.AddField("name", "value", false);
  343. });
  344. }
  345. [Fact]
  346. public void EmbedFieldBuilder()
  347. {
  348. var e = new EmbedFieldBuilder()
  349. .WithIsInline(true)
  350. .WithName("name")
  351. .WithValue("value");
  352. Assert.Equal("name", e.Name);
  353. Assert.Equal("value", e.Value);
  354. Assert.True(e.IsInline);
  355. // use the properties
  356. e = new EmbedFieldBuilder();
  357. e.IsInline = true;
  358. e.Name = "name";
  359. e.Value = "value";
  360. Assert.Equal("name", e.Name);
  361. Assert.Equal("value", e.Value);
  362. Assert.True(e.IsInline);
  363. }
  364. [Theory]
  365. [InlineData("")]
  366. [InlineData(" ")]
  367. [InlineData(null)]
  368. // 257 chars
  369. [InlineData("jVyLChmA7aBZozXQuZ3VDEcwW6zOq0nteOVYBZi31ny73rpXfSSBXR4Jw6FiplDKQseKskwRMuBZkUewrewqAbkBZpslHirvC5nEzRySoDIdTRnkVvTXZUXg75l3bQCjuuHxDd6DfrY8ihd6yZX1Y0XFeg239YBcYV4TpL9uQ8H3HFYxrWhLlG2PRVjUmiglP5iXkawszNwMVm1SZ5LZT4jkMZHxFegVi7170d16iaPWOovu50aDDHy087XBtLKVa")]
  370. // 257 chars of whitespace
  371. [InlineData(" ")]
  372. public void EmbedFieldBuilder_InvalidName(string name)
  373. {
  374. Assert.Throws<ArgumentException>(() => new EmbedFieldBuilder().WithName(name));
  375. }
  376. [Fact]
  377. public void EmbedFieldBuilder_InvalidValue()
  378. {
  379. IEnumerable<string> GetInvalidValue()
  380. {
  381. yield return null;
  382. yield return string.Empty;
  383. yield return " ";
  384. yield return new string('a', 1025);
  385. };
  386. foreach (var v in GetInvalidValue())
  387. Assert.Throws<ArgumentException>(() => new EmbedFieldBuilder().WithValue(v));
  388. }
  389. }
  390. }