| @@ -1,12 +1,14 @@ | |||||
| | | ||||
| Microsoft Visual Studio Solution File, Format Version 12.00 | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||
| # Visual Studio 14 | # Visual Studio 14 | ||||
| VisualStudioVersion = 14.0.25123.0 | |||||
| VisualStudioVersion = 14.0.25420.1 | |||||
| MinimumVisualStudioVersion = 10.0.40219.1 | MinimumVisualStudioVersion = 10.0.40219.1 | ||||
| Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net", "src\Discord.Net\Discord.Net.xproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net", "src\Discord.Net\Discord.Net.xproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" | ||||
| EndProject | EndProject | ||||
| Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Commands", "src\Discord.Net.Commands\Discord.Net.Commands.xproj", "{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}" | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Commands", "src\Discord.Net.Commands\Discord.Net.Commands.xproj", "{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}" | ||||
| EndProject | EndProject | ||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Tests", "test\Discord.Net.Tests\Discord.Net.Tests.csproj", "{855D6B1D-847B-42DA-BE6A-23683EA89511}" | |||||
| EndProject | |||||
| Global | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| Debug|Any CPU = Debug|Any CPU | Debug|Any CPU = Debug|Any CPU | ||||
| @@ -21,6 +23,10 @@ Global | |||||
| {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU | {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Release|Any CPU.ActiveCfg = Release|Any CPU | {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Release|Any CPU.Build.0 = Release|Any CPU | {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| {855D6B1D-847B-42DA-BE6A-23683EA89511}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {855D6B1D-847B-42DA-BE6A-23683EA89511}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {855D6B1D-847B-42DA-BE6A-23683EA89511}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {855D6B1D-847B-42DA-BE6A-23683EA89511}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
| @@ -37,7 +37,7 @@ | |||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <Reference Include="Discord.Net"> | <Reference Include="Discord.Net"> | ||||
| <HintPath>..\..\src\Discord.Net\bin\Debug\Discord.Net.dll</HintPath> | |||||
| <HintPath>..\..\src\Discord.Net\bin\Debug\netstandard1.3\Discord.Net.dll</HintPath> | |||||
| </Reference> | </Reference> | ||||
| <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||||
| <HintPath>..\..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> | <HintPath>..\..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> | ||||
| @@ -76,6 +76,12 @@ | |||||
| <ItemGroup> | <ItemGroup> | ||||
| <None Include="packages.config" /> | <None Include="packages.config" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | |||||
| <ProjectReference Include="..\..\src\Discord.Net.Commands\Discord.Net.Commands.xproj"> | |||||
| <Project>{078dd7e6-943d-4d09-afc2-d2ba58b76c9c}</Project> | |||||
| <Name>Discord.Net.Commands</Name> | |||||
| </ProjectReference> | |||||
| </ItemGroup> | |||||
| <Choose> | <Choose> | ||||
| <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> | <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| @@ -1,7 +1,7 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| namespace Discord.Tests.Rest | |||||
| namespace Discord.Tests.Framework | |||||
| { | { | ||||
| public class EndpointHandler | public class EndpointHandler | ||||
| { | { | ||||
| @@ -8,7 +8,7 @@ using System.Text; | |||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using System.Globalization; | using System.Globalization; | ||||
| namespace Discord.Tests.Rest | |||||
| namespace Discord.Tests.Framework | |||||
| { | { | ||||
| public class Json | public class Json | ||||
| { | { | ||||
| @@ -3,34 +3,43 @@ using System.Collections.Generic; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Discord.Rest; | |||||
| using Discord; | |||||
| using Discord.Net.Rest; | using Discord.Net.Rest; | ||||
| using System.Threading; | using System.Threading; | ||||
| using System.IO; | using System.IO; | ||||
| namespace Discord.Tests.Rest | |||||
| namespace Discord.Tests.Framework | |||||
| { | { | ||||
| class TestRestClient : IRestClient | class TestRestClient : IRestClient | ||||
| { | { | ||||
| public static Dictionary<string, string> Headers = new Dictionary<string, string>(); | public static Dictionary<string, string> Headers = new Dictionary<string, string>(); | ||||
| public TestRestClient(string baseUrl, CancellationToken cancelToken) | |||||
| public TestRestClient(string baseUrl) | |||||
| { | { | ||||
| } | |||||
| Task<Stream> IRestClient.SendAsync(string method, string endpoint, bool headerOnly = false) | |||||
| { | |||||
| if (headerOnly) return null; | |||||
| return Task.FromResult<Stream>(new MemoryStream(Encoding.UTF8.GetBytes(EndpointHandler.Instance.HandleMessage(method, endpoint, "")))); | |||||
| } | } | ||||
| Task<Stream> IRestClient.Send(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, bool headerOnly = false) | |||||
| Task<Stream> IRestClient.SendAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, bool headerOnly = false) | |||||
| { | { | ||||
| if (headerOnly) return null; | if (headerOnly) return null; | ||||
| throw new NotImplementedException("method only used for SendFile, not concerned with that yet."); | throw new NotImplementedException("method only used for SendFile, not concerned with that yet."); | ||||
| } | } | ||||
| Task<Stream> IRestClient.Send(string method, string endpoint, string json, bool headerOnly = false) | |||||
| Task<Stream> IRestClient.SendAsync(string method, string endpoint, string json, bool headerOnly = false) | |||||
| { | { | ||||
| if (headerOnly) return null; | if (headerOnly) return null; | ||||
| return Task.FromResult<Stream>(new MemoryStream(Encoding.UTF8.GetBytes(EndpointHandler.Instance.HandleMessage(method, endpoint, json)))); | return Task.FromResult<Stream>(new MemoryStream(Encoding.UTF8.GetBytes(EndpointHandler.Instance.HandleMessage(method, endpoint, json)))); | ||||
| } | } | ||||
| void IRestClient.SetCancelToken(CancellationToken cancelToken) | |||||
| { | |||||
| } | |||||
| void IRestClient.SetHeader(string key, string value) | void IRestClient.SetHeader(string key, string value) | ||||
| { | { | ||||
| if (Headers.ContainsKey(key)) | if (Headers.ContainsKey(key)) | ||||
| @@ -7,7 +7,7 @@ using System.Net; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace Discord.Tests.Rest.Responses.Guilds | |||||
| namespace Discord.Tests.Framework.Responses.Guilds | |||||
| { | { | ||||
| public static class GuildHandlers | public static class GuildHandlers | ||||
| { | { | ||||
| @@ -6,11 +6,13 @@ using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace Discord.Tests.Rest.Responses.Guilds | |||||
| namespace Discord.Tests.Framework.Responses.Guilds | |||||
| { | { | ||||
| public static class Guild_Mocks | public static class Guild_Mocks | ||||
| { | { | ||||
| public static Guild Guild_From_Id { get | |||||
| public static Guild Guild_From_Id | |||||
| { | |||||
| get | |||||
| { | { | ||||
| return new Guild | return new Guild | ||||
| { | { | ||||
| @@ -25,15 +27,18 @@ namespace Discord.Tests.Rest.Responses.Guilds | |||||
| EmbedEnabled = true, | EmbedEnabled = true, | ||||
| EmbedChannelId = null, | EmbedChannelId = null, | ||||
| VerificationLevel = 0, | VerificationLevel = 0, | ||||
| Roles = new Role[] {Roles.Constant_Role_Mocks.Mock_Everyone_Role}, | |||||
| Roles = new Role[] { Roles.Constant_Role_Mocks.Mock_Everyone_Role }, | |||||
| }; | }; | ||||
| } } | |||||
| } | |||||
| } | |||||
| public static IEnumerable<User> GuildBansList => new List<User> { Users.User_Mocks.Bot_User, Users.User_Mocks.Me_User }; | public static IEnumerable<User> GuildBansList => new List<User> { Users.User_Mocks.Bot_User, Users.User_Mocks.Me_User }; | ||||
| public static IEnumerable<UserGuild> UserGuildsList() => new List<UserGuild>{ User_Guild_1, User_Guild_2 }; | |||||
| public static IEnumerable<UserGuild> UserGuildsList() => new List<UserGuild> { User_Guild_1, User_Guild_2 }; | |||||
| public static UserGuild User_Guild_1 { get | |||||
| public static UserGuild User_Guild_1 | |||||
| { | |||||
| get | |||||
| { | { | ||||
| return new UserGuild | return new UserGuild | ||||
| { | { | ||||
| @@ -43,7 +48,8 @@ namespace Discord.Tests.Rest.Responses.Guilds | |||||
| Owner = false, | Owner = false, | ||||
| Permissions = 103926785 | Permissions = 103926785 | ||||
| }; | }; | ||||
| } } | |||||
| } | |||||
| } | |||||
| public static UserGuild User_Guild_2 | public static UserGuild User_Guild_2 | ||||
| { | { | ||||
| @@ -5,25 +5,31 @@ using System.Text; | |||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Discord.API; | using Discord.API; | ||||
| namespace Discord.Tests.Rest.Responses.Guilds | |||||
| namespace Discord.Tests.Framework.Responses.Guilds | |||||
| { | { | ||||
| public static class Member_Mocks | public static class Member_Mocks | ||||
| { | { | ||||
| public static IEnumerable<GuildMember> Guild_Members => new List<GuildMember> { Guild_Member_1, Guild_Member_2 }; | public static IEnumerable<GuildMember> Guild_Members => new List<GuildMember> { Guild_Member_1, Guild_Member_2 }; | ||||
| public static GuildMember Guild_Member_1 { get { | |||||
| public static GuildMember Guild_Member_1 | |||||
| { | |||||
| get | |||||
| { | |||||
| return new GuildMember() | return new GuildMember() | ||||
| { | { | ||||
| User = Users.User_Mocks.Me_User, | User = Users.User_Mocks.Me_User, | ||||
| Nick = "Voltamom", | |||||
| Nick = "voltana", | |||||
| JoinedAt = new DateTime(2009, 4, 19), | JoinedAt = new DateTime(2009, 4, 19), | ||||
| Deaf = true, | Deaf = true, | ||||
| Mute = false, | Mute = false, | ||||
| Roles = new ulong[] { 1UL } | Roles = new ulong[] { 1UL } | ||||
| }; | }; | ||||
| } } | |||||
| } | |||||
| } | |||||
| public static GuildMember Guild_Member_2 { get | |||||
| public static GuildMember Guild_Member_2 | |||||
| { | |||||
| get | |||||
| { | { | ||||
| return new GuildMember() | return new GuildMember() | ||||
| { | { | ||||
| @@ -31,6 +37,7 @@ namespace Discord.Tests.Rest.Responses.Guilds | |||||
| Nick = "foxbot", | Nick = "foxbot", | ||||
| JoinedAt = new DateTime(2016, 5, 5), | JoinedAt = new DateTime(2016, 5, 5), | ||||
| }; | }; | ||||
| } } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,30 @@ | |||||
| using Newtonsoft.Json; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Discord.API; | |||||
| namespace Discord.Tests.Framework.Responses.Roles | |||||
| { | |||||
| public static class Constant_Role_Mocks | |||||
| { | |||||
| public static Role Mock_Everyone_Role | |||||
| { | |||||
| get | |||||
| { | |||||
| return new Role | |||||
| { | |||||
| Id = 66078535390867456, | |||||
| Color = 0, | |||||
| Position = 0, | |||||
| Hoist = false, | |||||
| Managed = false, | |||||
| Name = "@everyone", | |||||
| Permissions = 36953089 | |||||
| }; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -4,7 +4,7 @@ using Discord.Net; | |||||
| using System.Net; | using System.Net; | ||||
| using System; | using System; | ||||
| namespace Discord.Tests.Rest.Responses.Users | |||||
| namespace Discord.Tests.Framework.Responses.Users | |||||
| { | { | ||||
| public static class UserHandlers | public static class UserHandlers | ||||
| { | { | ||||
| @@ -1,45 +1,55 @@ | |||||
| using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
| using Discord.API; | using Discord.API; | ||||
| namespace Discord.Tests.Rest.Responses.Users | |||||
| namespace Discord.Tests.Framework.Responses.Users | |||||
| { | { | ||||
| public static class User_Mocks | public static class User_Mocks | ||||
| { | { | ||||
| public static User Me_User { get { | |||||
| public static User Me_User | |||||
| { | |||||
| get | |||||
| { | |||||
| return new User | return new User | ||||
| { | { | ||||
| Id = 66078337084162048, | Id = 66078337084162048, | ||||
| Username = "Voltana", | Username = "Voltana", | ||||
| Discriminator = 0001, | |||||
| Discriminator = "0001", | |||||
| Avatar = "ec2b259bfe24686bf9d214b6bebe0834", | Avatar = "ec2b259bfe24686bf9d214b6bebe0834", | ||||
| IsVerified = true, | |||||
| Verified = true, | |||||
| Email = "hello-i-am-not-real@foxbot.me" | Email = "hello-i-am-not-real@foxbot.me" | ||||
| }; | }; | ||||
| } } | |||||
| } | |||||
| } | |||||
| public static User Bot_User { get | |||||
| public static User Bot_User | |||||
| { | |||||
| get | |||||
| { | { | ||||
| return new User | return new User | ||||
| { | { | ||||
| Id = 66078337084162048, | Id = 66078337084162048, | ||||
| Username = "foxboat", | Username = "foxboat", | ||||
| Discriminator = 0005, | |||||
| Discriminator = "0005", | |||||
| Avatar = "ec2b259bfe24686bf9d214b6bebe0834", | Avatar = "ec2b259bfe24686bf9d214b6bebe0834", | ||||
| IsVerified = true, | |||||
| Verified = true, | |||||
| Email = "hello-i-am-not-real@foxbot.me", | Email = "hello-i-am-not-real@foxbot.me", | ||||
| Bot = true | Bot = true | ||||
| }; | }; | ||||
| } } | |||||
| } | |||||
| } | |||||
| public static User Public_User { get | |||||
| public static User Public_User | |||||
| { | |||||
| get | |||||
| { | { | ||||
| return new User | return new User | ||||
| { | { | ||||
| Id = 96642168176807936, | Id = 96642168176807936, | ||||
| Username = "Khionu", | Username = "Khionu", | ||||
| Discriminator = 9999, | |||||
| Discriminator = "9999", | |||||
| Avatar = "ceeff590f1e0e1ccae0afc89967131ff" | Avatar = "ceeff590f1e0e1ccae0afc89967131ff" | ||||
| }; | }; | ||||
| } } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,10 +1,11 @@ | |||||
| using Discord.Rest; | |||||
| using Discord; | |||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Discord.Tests.Framework; | |||||
| namespace Discord.Tests.Rest | namespace Discord.Tests.Rest | ||||
| { | { | ||||
| @@ -12,7 +13,7 @@ namespace Discord.Tests.Rest | |||||
| public class GuildTests | public class GuildTests | ||||
| { | { | ||||
| public static TestContext Context; | public static TestContext Context; | ||||
| private static IDiscordClient _client; | |||||
| private static DiscordClient _client; | |||||
| [ClassInitialize] | [ClassInitialize] | ||||
| public static void Initialize(TestContext context) | public static void Initialize(TestContext context) | ||||
| @@ -21,15 +22,15 @@ namespace Discord.Tests.Rest | |||||
| _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | ||||
| if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | ||||
| if (Json.Serializer == null) new Json(); | if (Json.Serializer == null) new Json(); | ||||
| Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.User; | |||||
| _client.Login(TokenType.User, "UserToken_Voltana").Wait(); | |||||
| Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.User; | |||||
| _client.LoginAsync(TokenType.User, "UserToken_Voltana").GetAwaiter().GetResult(); | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Get_Guild() | public async Task Test_Get_Guild() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| Assert.AreEqual(66078535390867456UL, guild.Id, "Expected ID '66078535390867456'"); | Assert.AreEqual(66078535390867456UL, guild.Id, "Expected ID '66078535390867456'"); | ||||
| Assert.AreEqual("Discord API", guild.Name, "Expected Name 'Discord API'"); | Assert.AreEqual("Discord API", guild.Name, "Expected Name 'Discord API'"); | ||||
| // Cannot Verify Guild URL, ID not publicly exposed. | // Cannot Verify Guild URL, ID not publicly exposed. | ||||
| @@ -44,76 +45,76 @@ namespace Discord.Tests.Rest | |||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Get_Guild_Invalid_Id() | public async Task Test_Get_Guild_Invalid_Id() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(1); | |||||
| var guild = await _client.GetGuildAsync(1); | |||||
| Assert.IsNull(guild); | Assert.IsNull(guild); | ||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Get_Guilds() | public async Task Test_Get_Guilds() | ||||
| { | { | ||||
| var guilds = await _client.GetGuilds(); | |||||
| var guilds = await _client.GetGuildsAsync(); | |||||
| Assert.AreEqual(2, guilds.Count(), "Expected 2 Guilds"); | Assert.AreEqual(2, guilds.Count(), "Expected 2 Guilds"); | ||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Guild_Get_Bans() | public async Task Test_Guild_Get_Bans() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var bans = await guild.GetBans(); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| var bans = await guild.GetBansAsync(); | |||||
| Assert.AreEqual(2, bans.Count()); | Assert.AreEqual(2, bans.Count()); | ||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Guild_Get_User() | public async Task Test_Guild_Get_User() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var user = await guild.GetUser(66078337084162048); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| var user = await guild.GetUserAsync(66078337084162048); | |||||
| // TODO: Asserts | // TODO: Asserts | ||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Guild_Get_Invalid_User() | public async Task Test_Guild_Get_Invalid_User() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var user = await guild.GetUser(1); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| var user = await guild.GetUserAsync(1); | |||||
| Assert.IsNull(user, "Expected returned user to be null"); | Assert.IsNull(user, "Expected returned user to be null"); | ||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Guild_Get_Users() | public async Task Test_Guild_Get_Users() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var users = await guild.GetUsers(); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| var users = await guild.GetUsersAsync(); | |||||
| Assert.AreEqual(2, users.Count()); | Assert.AreEqual(2, users.Count()); | ||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Guild_Get_Role() | public async Task Test_Guild_Get_Role() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var role = await guild.GetRole(1); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| var role = guild.GetRole(1); | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Guild_Get_Invalid_Role() | public async Task Test_Guild_Get_Invalid_Role() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var role = await guild.GetRole(1); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| var role = guild.GetRole(1); | |||||
| Assert.IsNull(role, "Expected returned role to be null."); | Assert.IsNull(role, "Expected returned role to be null."); | ||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Guild_Get_Roles() | public async Task Test_Guild_Get_Roles() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var roles = await guild.GetRoles(); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| var roles = guild.Roles; | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Guilds")] | [TestCategory("Guilds")] | ||||
| public async Task Test_Guild_Get_Invites() | public async Task Test_Guild_Get_Invites() | ||||
| { | { | ||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var invites = await guild.GetInvites(); | |||||
| var guild = await _client.GetGuildAsync(66078535390867456); | |||||
| var invites = await guild.GetInvitesAsync(); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -4,7 +4,9 @@ using System.Collections.Generic; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Discord.Rest; | |||||
| using Discord; | |||||
| using Discord.Tests.Framework; | |||||
| using Discord.Tests.Framework.Responses; | |||||
| namespace Discord.Tests.Rest | namespace Discord.Tests.Rest | ||||
| { | { | ||||
| @@ -27,31 +29,31 @@ namespace Discord.Tests.Rest | |||||
| [TestCategory("Login")] | [TestCategory("Login")] | ||||
| public async Task Test_Login_As_User() | public async Task Test_Login_As_User() | ||||
| { | { | ||||
| Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.User; | |||||
| await _client.Login(TokenType.User, "UserToken_Voltana"); | |||||
| Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.User; | |||||
| await _client.LoginAsync(TokenType.User, "UserToken_Voltana"); | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [ExpectedException(typeof(Net.HttpException))] | [ExpectedException(typeof(Net.HttpException))] | ||||
| [TestCategory("Login")] | [TestCategory("Login")] | ||||
| public async Task Test_Login_As_User_With_Invalid_Token() | public async Task Test_Login_As_User_With_Invalid_Token() | ||||
| { | { | ||||
| Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.User; | |||||
| await _client.Login(TokenType.User, "UserToken-NotVoltana"); | |||||
| Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.User; | |||||
| await _client.LoginAsync(TokenType.User, "UserToken-NotVoltana"); | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Login")] | [TestCategory("Login")] | ||||
| public async Task Test_Login_As_Bot() | public async Task Test_Login_As_Bot() | ||||
| { | { | ||||
| Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.Bot; | |||||
| await _client.Login(TokenType.Bot, "UserToken_VoltanaBot"); | |||||
| Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.Bot; | |||||
| await _client.LoginAsync(TokenType.Bot, "UserToken_VoltanaBot"); | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [ExpectedException(typeof(Net.HttpException))] | [ExpectedException(typeof(Net.HttpException))] | ||||
| [TestCategory("Login")] | [TestCategory("Login")] | ||||
| public async Task Test_Login_As_Bot_With_Invalid_Token() | public async Task Test_Login_As_Bot_With_Invalid_Token() | ||||
| { | { | ||||
| Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.Bot; | |||||
| await _client.Login(TokenType.Bot, "UserToken-NotVoltanaBot"); | |||||
| Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.Bot; | |||||
| await _client.LoginAsync(TokenType.Bot, "UserToken-NotVoltanaBot"); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,23 +0,0 @@ | |||||
| using Newtonsoft.Json; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Discord.API; | |||||
| namespace Discord.Tests.Rest.Responses.Roles | |||||
| { | |||||
| public static class Constant_Role_Mocks | |||||
| { | |||||
| public static Role Mock_Everyone_Role { get { return new Role { | |||||
| Id = 66078535390867456, | |||||
| Color = 0, | |||||
| Position = 0, | |||||
| Hoist = false, | |||||
| Managed = false, | |||||
| Name = "@everyone", | |||||
| Permissions = 36953089 | |||||
| }; } } | |||||
| } | |||||
| } | |||||
| @@ -4,7 +4,8 @@ using System.Collections.Generic; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Discord.Rest; | |||||
| using Discord; | |||||
| using Discord.Tests.Framework; | |||||
| namespace Discord.Tests.Rest | namespace Discord.Tests.Rest | ||||
| { | { | ||||
| @@ -21,15 +22,15 @@ namespace Discord.Tests.Rest | |||||
| _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | ||||
| if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | ||||
| if (Json.Serializer == null) new Json(); | if (Json.Serializer == null) new Json(); | ||||
| Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.User; | |||||
| _client.Login(TokenType.User, "UserToken_Voltana").Wait(); | |||||
| Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.User; | |||||
| _client.LoginAsync(TokenType.User, "UserToken_Voltana").GetAwaiter().GetResult(); | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| [TestCategory("Users")] | [TestCategory("Users")] | ||||
| public async Task Test_Get_Current_User() | public async Task Test_Get_Current_User() | ||||
| { | { | ||||
| var currentUser = await _client.GetCurrentUser(); | |||||
| var currentUser = await _client.GetCurrentUserAsync(); | |||||
| Assert.AreEqual((UInt64)66078337084162048, currentUser.Id, "Expected Id '66078337084162048'"); | Assert.AreEqual((UInt64)66078337084162048, currentUser.Id, "Expected Id '66078337084162048'"); | ||||
| Assert.AreEqual("Voltana", currentUser.Username, "Expected Name 'Voltana'"); | Assert.AreEqual("Voltana", currentUser.Username, "Expected Name 'Voltana'"); | ||||
| Assert.AreEqual(0001, currentUser.Discriminator, "Expected Discriminator '0001'"); | Assert.AreEqual(0001, currentUser.Discriminator, "Expected Discriminator '0001'"); | ||||
| @@ -44,7 +45,7 @@ namespace Discord.Tests.Rest | |||||
| [TestCategory("Users")] | [TestCategory("Users")] | ||||
| public async Task Test_Get_User() | public async Task Test_Get_User() | ||||
| { | { | ||||
| var user = await _client.GetUser(96642168176807936); | |||||
| var user = await _client.GetUserAsync(96642168176807936); | |||||
| Assert.AreEqual((UInt64)96642168176807936, user.Id, "Expected Id '96642168176807936'"); | Assert.AreEqual((UInt64)96642168176807936, user.Id, "Expected Id '96642168176807936'"); | ||||
| Assert.AreEqual("Khionu", user.Username, "Expected Name 'Khionu'"); | Assert.AreEqual("Khionu", user.Username, "Expected Name 'Khionu'"); | ||||
| Assert.AreEqual(9999, user.Discriminator, "Expected Discriminator '0001'"); | Assert.AreEqual(9999, user.Discriminator, "Expected Discriminator '0001'"); | ||||
| @@ -57,7 +58,7 @@ namespace Discord.Tests.Rest | |||||
| [TestCategory("Users")] | [TestCategory("Users")] | ||||
| public async Task Test_Get_Invalid_User() | public async Task Test_Get_Invalid_User() | ||||
| { | { | ||||
| var user = await _client.GetUser(1); | |||||
| var user = await _client.GetUserAsync(1); | |||||
| Assert.IsNull(user, "Expected Invalid User to be 'null'"); | Assert.IsNull(user, "Expected Invalid User to be 'null'"); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,5 +1,4 @@ | |||||
| using Discord.Rest; | |||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Linq; | using System.Linq; | ||||
| @@ -317,184 +316,184 @@ namespace Discord.Tests | |||||
| x => _obGuildBot.UserUpdated -= x, | x => _obGuildBot.UserUpdated -= x, | ||||
| (s, e) => e.After.Username == name); | (s, e) => e.After.Username == name); | ||||
| }*/ | }*/ | ||||
| /* | |||||
| [TestMethod] | |||||
| public void TestSetStatus() | |||||
| { | |||||
| AssertEvent<UserUpdatedEventArgs>( | |||||
| "UserUpdated never fired", | |||||
| async () => await SetStatus(_targetBot, UserStatus.Idle), | |||||
| x => _observerBot.UserUpdated += x, | |||||
| x => _observerBot.UserUpdated -= x, | |||||
| (s, e) => e.After.Status == UserStatus.Idle); | |||||
| } | |||||
| private Task SetStatus(DiscordClient _client, UserStatus status) | |||||
| { | |||||
| throw new NotImplementedException(); | |||||
| /*_client.SetStatus(status); | |||||
| await Task.Delay(50); | |||||
| }*/ | |||||
| /* | |||||
| [TestMethod] | |||||
| public void TestSetGame() | |||||
| { | |||||
| AssertEvent<UserUpdatedEventArgs>( | |||||
| "UserUpdated never fired", | |||||
| async () => await SetGame(_targetBot, "test game"), | |||||
| x => _observerBot.UserUpdated += x, | |||||
| x => _observerBot.UserUpdated -= x, | |||||
| (s, e) => _targetBot.CurrentUser.CurrentGame == "test game"); | |||||
| } | |||||
| private Task SetGame(DiscordClient _client, string game) | |||||
| { | |||||
| throw new NotImplementedException(); | |||||
| //_client.SetGame(game); | |||||
| //await Task.Delay(5); | |||||
| } | |||||
| /* | |||||
| [TestMethod] | |||||
| public void TestSetStatus() | |||||
| { | |||||
| AssertEvent<UserUpdatedEventArgs>( | |||||
| "UserUpdated never fired", | |||||
| async () => await SetStatus(_targetBot, UserStatus.Idle), | |||||
| x => _observerBot.UserUpdated += x, | |||||
| x => _observerBot.UserUpdated -= x, | |||||
| (s, e) => e.After.Status == UserStatus.Idle); | |||||
| } | |||||
| private Task SetStatus(DiscordClient _client, UserStatus status) | |||||
| { | |||||
| throw new NotImplementedException(); | |||||
| /*_client.SetStatus(status); | |||||
| await Task.Delay(50); | |||||
| }*/ | |||||
| /* | |||||
| [TestMethod] | |||||
| public void TestSetGame() | |||||
| { | |||||
| AssertEvent<UserUpdatedEventArgs>( | |||||
| "UserUpdated never fired", | |||||
| async () => await SetGame(_targetBot, "test game"), | |||||
| x => _observerBot.UserUpdated += x, | |||||
| x => _observerBot.UserUpdated -= x, | |||||
| (s, e) => _targetBot.CurrentUser.CurrentGame == "test game"); | |||||
| } | |||||
| private Task SetGame(DiscordClient _client, string game) | |||||
| { | |||||
| throw new NotImplementedException(); | |||||
| //_client.SetGame(game); | |||||
| //await Task.Delay(5); | |||||
| } | |||||
| #endregion | |||||
| #endregion | |||||
| #region Permission Tests | |||||
| #region Permission Tests | |||||
| // Permissions | |||||
| [TestMethod] | |||||
| public async Task Test_AddGet_PermissionsRule() | |||||
| { | |||||
| var channel = await _testGuild.CreateTextChannel(GetRandomText()); | |||||
| var user = _testGuild.GetUser(_targetBot.CurrentUser.Id); | |||||
| var perms = new OverwritePermissions(sendMessages: PermValue.Deny); | |||||
| await channel.UpdatePermissionOverwrite(user, perms); | |||||
| var resultPerms = channel.GetPermissionOverwrite(user); | |||||
| Assert.IsNotNull(resultPerms, "Perms retrieved from Guild were null."); | |||||
| } | |||||
| [TestMethod] | |||||
| public async Task Test_AddRemove_PermissionsRule() | |||||
| { | |||||
| var channel = await _testGuild.CreateTextChannel(GetRandomText()); | |||||
| var user = _testGuild.GetUser(_targetBot.CurrentUser.Id); | |||||
| var perms = new OverwritePermissions(sendMessages: PermValue.Deny); | |||||
| await channel.UpdatePermissionOverwrite(user, perms); | |||||
| await channel.RemovePermissionOverwrite(user); | |||||
| await Task.Delay(200); | |||||
| Assert.AreEqual(PermValue.Inherit, channel.GetPermissionOverwrite(user)?.SendMessages); | |||||
| } | |||||
| [TestMethod] | |||||
| public async Task Test_Permissions_Event() | |||||
| { | |||||
| var channel = await _testGuild.CreateTextChannel(GetRandomText()); | |||||
| var user = _testGuild.GetUser(_targetBot.CurrentUser.Id); | |||||
| var perms = new OverwritePermissions(sendMessages: PermValue.Deny); | |||||
| AssertEvent<ChannelUpdatedEventArgs> | |||||
| ("ChannelUpdatedEvent never fired.", | |||||
| async () => await channel.UpdatePermissionOverwrite(user, perms), | |||||
| x => _targetBot.ChannelUpdated += x, | |||||
| x => _targetBot.ChannelUpdated -= x, | |||||
| (s, e) => e.Channel == channel && (e.After as GuildChannel).PermissionOverwrites.Count() != (e.Before as GuildChannel).PermissionOverwrites.Count()); | |||||
| } | |||||
| [TestMethod] | |||||
| [ExpectedException(typeof(Net.HttpException))] | |||||
| public async Task Test_Affect_Permissions_Invalid_Channel() | |||||
| { | |||||
| var channel = await _testGuild.CreateTextChannel(GetRandomText()); | |||||
| var user = _testGuild.GetUser(_targetBot.CurrentUser.Id); | |||||
| var perms = new OverwritePermissions(sendMessages: PermValue.Deny); | |||||
| await channel.Delete(); | |||||
| await channel.UpdatePermissionOverwrite(user, perms); | |||||
| } | |||||
| // Permissions | |||||
| [TestMethod] | |||||
| public async Task Test_AddGet_PermissionsRule() | |||||
| { | |||||
| var channel = await _testGuild.CreateTextChannel(GetRandomText()); | |||||
| var user = _testGuild.GetUser(_targetBot.CurrentUser.Id); | |||||
| var perms = new OverwritePermissions(sendMessages: PermValue.Deny); | |||||
| await channel.UpdatePermissionOverwrite(user, perms); | |||||
| var resultPerms = channel.GetPermissionOverwrite(user); | |||||
| Assert.IsNotNull(resultPerms, "Perms retrieved from Guild were null."); | |||||
| } | |||||
| [TestMethod] | |||||
| public async Task Test_AddRemove_PermissionsRule() | |||||
| { | |||||
| var channel = await _testGuild.CreateTextChannel(GetRandomText()); | |||||
| var user = _testGuild.GetUser(_targetBot.CurrentUser.Id); | |||||
| var perms = new OverwritePermissions(sendMessages: PermValue.Deny); | |||||
| await channel.UpdatePermissionOverwrite(user, perms); | |||||
| await channel.RemovePermissionOverwrite(user); | |||||
| await Task.Delay(200); | |||||
| Assert.AreEqual(PermValue.Inherit, channel.GetPermissionOverwrite(user)?.SendMessages); | |||||
| } | |||||
| [TestMethod] | |||||
| public async Task Test_Permissions_Event() | |||||
| { | |||||
| var channel = await _testGuild.CreateTextChannel(GetRandomText()); | |||||
| var user = _testGuild.GetUser(_targetBot.CurrentUser.Id); | |||||
| var perms = new OverwritePermissions(sendMessages: PermValue.Deny); | |||||
| AssertEvent<ChannelUpdatedEventArgs> | |||||
| ("ChannelUpdatedEvent never fired.", | |||||
| async () => await channel.UpdatePermissionOverwrite(user, perms), | |||||
| x => _targetBot.ChannelUpdated += x, | |||||
| x => _targetBot.ChannelUpdated -= x, | |||||
| (s, e) => e.Channel == channel && (e.After as GuildChannel).PermissionOverwrites.Count() != (e.Before as GuildChannel).PermissionOverwrites.Count()); | |||||
| } | |||||
| [TestMethod] | |||||
| [ExpectedException(typeof(Net.HttpException))] | |||||
| public async Task Test_Affect_Permissions_Invalid_Channel() | |||||
| { | |||||
| var channel = await _testGuild.CreateTextChannel(GetRandomText()); | |||||
| var user = _testGuild.GetUser(_targetBot.CurrentUser.Id); | |||||
| var perms = new OverwritePermissions(sendMessages: PermValue.Deny); | |||||
| await channel.Delete(); | |||||
| await channel.UpdatePermissionOverwrite(user, perms); | |||||
| } | |||||
| #endregion | |||||
| #endregion | |||||
| [ClassCleanup] | |||||
| public static async Task Cleanup() | |||||
| { | |||||
| WaitMany( | |||||
| (await _hostBot.GetGuilds()).Select(x => x.Owner.Id == _hostBot.CurrentUser.Id ? x.Delete() : x.Leave()), | |||||
| (await _targetBot.GetGuilds()).Select(x => x.Owner.Id == _targetBot.CurrentUser.Id ? x.Delete() : x.Leave()), | |||||
| (await _observerBot.GetGuilds()).Select(x => x.Owner.Id == _observerBot.CurrentUser.Id ? x.Delete() : x.Leave())); | |||||
| WaitAll( | |||||
| _hostBot.Disconnect(), | |||||
| _targetBot.Disconnect(), | |||||
| _observerBot.Disconnect()); | |||||
| } | |||||
| [ClassCleanup] | |||||
| public static async Task Cleanup() | |||||
| { | |||||
| WaitMany( | |||||
| (await _hostBot.GetGuilds()).Select(x => x.Owner.Id == _hostBot.CurrentUser.Id ? x.Delete() : x.Leave()), | |||||
| (await _targetBot.GetGuilds()).Select(x => x.Owner.Id == _targetBot.CurrentUser.Id ? x.Delete() : x.Leave()), | |||||
| (await _observerBot.GetGuilds()).Select(x => x.Owner.Id == _observerBot.CurrentUser.Id ? x.Delete() : x.Leave())); | |||||
| #region Helpers | |||||
| WaitAll( | |||||
| _hostBot.Disconnect(), | |||||
| _targetBot.Disconnect(), | |||||
| _observerBot.Disconnect()); | |||||
| } | |||||
| // Task Helpers | |||||
| #region Helpers | |||||
| private static void AssertEvent<TArgs>(string msg, Func<Task> action, Action<EventHandler<TArgs>> addEvent, Action<EventHandler<TArgs>> removeEvent, Func<object, TArgs, bool> test = null) | |||||
| { | |||||
| AssertEvent(msg, action, addEvent, removeEvent, test, true); | |||||
| } | |||||
| private static void AssertNoEvent<TArgs>(string msg, Func<Task> action, Action<EventHandler<TArgs>> addEvent, Action<EventHandler<TArgs>> removeEvent, Func<object, TArgs, bool> test = null) | |||||
| { | |||||
| AssertEvent(msg, action, addEvent, removeEvent, test, false); | |||||
| } | |||||
| private static void AssertEvent<TArgs>(string msg, Func<Task> action, Action<EventHandler<TArgs>> addEvent, Action<EventHandler<TArgs>> removeEvent, Func<object, TArgs, bool> test, bool assertTrue) | |||||
| { | |||||
| ManualResetEventSlim trigger = new ManualResetEventSlim(false); | |||||
| bool result = false; | |||||
| // Task Helpers | |||||
| EventHandler<TArgs> handler = (s, e) => | |||||
| { | |||||
| if (test != null) | |||||
| { | |||||
| result |= test(s, e); | |||||
| trigger.Set(); | |||||
| } | |||||
| else | |||||
| result = true; | |||||
| }; | |||||
| addEvent(handler); | |||||
| var task = action(); | |||||
| trigger.Wait(EventTimeout); | |||||
| task.Wait(); | |||||
| removeEvent(handler); | |||||
| Assert.AreEqual(assertTrue, result, msg); | |||||
| } | |||||
| private static void AssertEvent<TArgs>(string msg, Func<Task> action, Action<EventHandler<TArgs>> addEvent, Action<EventHandler<TArgs>> removeEvent, Func<object, TArgs, bool> test = null) | |||||
| { | |||||
| AssertEvent(msg, action, addEvent, removeEvent, test, true); | |||||
| } | |||||
| private static void AssertNoEvent<TArgs>(string msg, Func<Task> action, Action<EventHandler<TArgs>> addEvent, Action<EventHandler<TArgs>> removeEvent, Func<object, TArgs, bool> test = null) | |||||
| { | |||||
| AssertEvent(msg, action, addEvent, removeEvent, test, false); | |||||
| } | |||||
| private static void AssertEvent<TArgs>(string msg, Func<Task> action, Action<EventHandler<TArgs>> addEvent, Action<EventHandler<TArgs>> removeEvent, Func<object, TArgs, bool> test, bool assertTrue) | |||||
| { | |||||
| ManualResetEventSlim trigger = new ManualResetEventSlim(false); | |||||
| bool result = false; | |||||
| private static void AssertEvent(string msg, Func<Task> action, Action<EventHandler> addEvent, Action<EventHandler> removeEvent, Func<object, bool> test, bool assertTrue) | |||||
| EventHandler<TArgs> handler = (s, e) => | |||||
| { | { | ||||
| ManualResetEventSlim trigger = new ManualResetEventSlim(false); | |||||
| bool result = false; | |||||
| EventHandler handler = (s, e) => | |||||
| if (test != null) | |||||
| { | { | ||||
| if (test != null) | |||||
| { | |||||
| result |= test(s); | |||||
| trigger.Set(); | |||||
| } | |||||
| else | |||||
| result = true; | |||||
| }; | |||||
| addEvent(handler); | |||||
| var task = action(); | |||||
| trigger.Wait(EventTimeout); | |||||
| task.Wait(); | |||||
| removeEvent(handler); | |||||
| Assert.AreEqual(assertTrue, result, msg); | |||||
| } | |||||
| result |= test(s, e); | |||||
| trigger.Set(); | |||||
| } | |||||
| else | |||||
| result = true; | |||||
| }; | |||||
| addEvent(handler); | |||||
| var task = action(); | |||||
| trigger.Wait(EventTimeout); | |||||
| task.Wait(); | |||||
| removeEvent(handler); | |||||
| Assert.AreEqual(assertTrue, result, msg); | |||||
| } | |||||
| private static void AssertEvent(string msg, Func<Task> action, Action<EventHandler> addEvent, Action<EventHandler> removeEvent, Func<object, bool> test, bool assertTrue) | |||||
| { | |||||
| ManualResetEventSlim trigger = new ManualResetEventSlim(false); | |||||
| bool result = false; | |||||
| private static void WaitAll(params Task[] tasks) | |||||
| { | |||||
| Task.WaitAll(tasks); | |||||
| } | |||||
| private static void WaitAll(IEnumerable<Task> tasks) | |||||
| { | |||||
| Task.WaitAll(tasks.ToArray()); | |||||
| } | |||||
| private static void WaitMany(params IEnumerable<Task>[] tasks) | |||||
| EventHandler handler = (s, e) => | |||||
| { | { | ||||
| Task.WaitAll(tasks.Where(x => x != null).SelectMany(x => x).ToArray()); | |||||
| } | |||||
| if (test != null) | |||||
| { | |||||
| result |= test(s); | |||||
| trigger.Set(); | |||||
| } | |||||
| else | |||||
| result = true; | |||||
| }; | |||||
| addEvent(handler); | |||||
| var task = action(); | |||||
| trigger.Wait(EventTimeout); | |||||
| task.Wait(); | |||||
| removeEvent(handler); | |||||
| Assert.AreEqual(assertTrue, result, msg); | |||||
| } | |||||
| private static void WaitAll(params Task[] tasks) | |||||
| { | |||||
| Task.WaitAll(tasks); | |||||
| } | |||||
| private static void WaitAll(IEnumerable<Task> tasks) | |||||
| { | |||||
| Task.WaitAll(tasks.ToArray()); | |||||
| } | |||||
| private static void WaitMany(params IEnumerable<Task>[] tasks) | |||||
| { | |||||
| Task.WaitAll(tasks.Where(x => x != null).SelectMany(x => x).ToArray()); | |||||
| } | |||||
| #endregion | |||||
| }*/ | |||||
| #endregion | |||||
| }*/ | |||||
| } | } | ||||