Comment out Tests.cs (will delete later) Build backend for Testing/Mock Rest Repliespull/62/head
@@ -1,10 +1,12 @@ | |||||
| | ||||
Microsoft Visual Studio Solution File, Format Version 12.00 | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||
# Visual Studio 15 | # Visual Studio 15 | ||||
VisualStudioVersion = 15.0.25123.0 | |||||
VisualStudioVersion = 15.0.25302.0 | |||||
MinimumVisualStudioVersion = 10.0.40219.1 | MinimumVisualStudioVersion = 10.0.40219.1 | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net", "src\Discord.Net\Discord.Net.csproj", "{18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}" | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net", "src\Discord.Net\Discord.Net.csproj", "{18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}" | ||||
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 | ||||
@@ -15,6 +17,10 @@ Global | |||||
{18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Debug|Any CPU.Build.0 = Debug|Any CPU | {18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
{18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Release|Any CPU.ActiveCfg = Release|Any CPU | {18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
{18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Release|Any CPU.Build.0 = Release|Any CPU | {18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.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 | ||||
@@ -55,6 +55,11 @@ | |||||
</Otherwise> | </Otherwise> | ||||
</Choose> | </Choose> | ||||
<ItemGroup> | <ItemGroup> | ||||
<Compile Include="Rest.cs" /> | |||||
<Compile Include="Rest\EndpointHandler.cs" /> | |||||
<Compile Include="Rest\Responses\Users\Me_Mocks.cs" /> | |||||
<Compile Include="Rest\Responses\Users\UserHandlers.cs" /> | |||||
<Compile Include="Rest\TestRestClient.cs" /> | |||||
<Compile Include="Tests.cs" /> | <Compile Include="Tests.cs" /> | ||||
<Compile Include="Properties\AssemblyInfo.cs" /> | <Compile Include="Properties\AssemblyInfo.cs" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -62,11 +67,12 @@ | |||||
<None Include="packages.config" /> | <None Include="packages.config" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\..\src\Discord.Net\Discord.Net.Net45.csproj"> | |||||
<Project>{c6a50d24-cbd3-4e76-852c-4dca60bbd608}</Project> | |||||
<Name>Discord.Net.Net45</Name> | |||||
<ProjectReference Include="..\..\src\Discord.Net\Discord.Net.csproj"> | |||||
<Project>{18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}</Project> | |||||
<Name>Discord.Net</Name> | |||||
</ProjectReference> | </ProjectReference> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup /> | |||||
<Choose> | <Choose> | ||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> | <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -0,0 +1,32 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
namespace Discord.Tests.Rest | |||||
{ | |||||
public class EndpointHandler | |||||
{ | |||||
public static EndpointHandler Instance; | |||||
public delegate string RestMessageHandler(string method, string json); | |||||
public Dictionary<string, RestMessageHandler> Handlers; | |||||
public EndpointHandler() | |||||
{ | |||||
Instance = this; | |||||
// Setup Endpoints | |||||
Handlers = new Dictionary<string, RestMessageHandler>(); | |||||
// /users Endpoints | |||||
Handlers.Add("users/@me", Responses.Users.UserHandlers.Me_Handler); | |||||
} | |||||
public string HandleMessage(string method, string endpoint, string json) | |||||
{ | |||||
if (Handlers.ContainsKey(endpoint)) | |||||
return Handlers[endpoint].Invoke(method, json); | |||||
throw new NotImplementedException($"{method} -> {endpoint} -> {json}"); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,42 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Discord.Rest; | |||||
using Discord.Net.Rest; | |||||
using System.Threading; | |||||
using System.IO; | |||||
namespace Discord.Tests.Rest | |||||
{ | |||||
class TestRestClient : IRestClient | |||||
{ | |||||
public static Dictionary<string, string> Headers = new Dictionary<string, string>(); | |||||
public TestRestClient(string baseUrl, CancellationToken cancelToken) | |||||
{ | |||||
} | |||||
Task<Stream> IRestClient.Send(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams) | |||||
{ | |||||
throw new NotImplementedException("method only used for SendFile, not concerned with that yet."); | |||||
} | |||||
Task<Stream> IRestClient.Send(string method, string endpoint, string json) | |||||
{ | |||||
return Task.FromResult<Stream>(new MemoryStream(Encoding.UTF8.GetBytes(EndpointHandler.Instance.HandleMessage(method, endpoint, json)))); | |||||
} | |||||
void IRestClient.SetHeader(string key, string value) | |||||
{ | |||||
if (Headers.ContainsKey(key)) | |||||
{ | |||||
Headers.Remove(key); | |||||
} | |||||
Headers.Add(key, value); | |||||
Console.WriteLine($"[Header Set]: {key} -> {value}"); | |||||
} | |||||
} | |||||
} |
@@ -1,4 +1,5 @@ | |||||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
using Discord.Rest; | |||||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
@@ -7,8 +8,11 @@ using System.Threading.Tasks; | |||||
namespace Discord.Tests | namespace Discord.Tests | ||||
{ | { | ||||
//TODO: Tests are massively incomplete and out of date, needing a full rewrite | |||||
// these tests are really bad | |||||
// we're never going to look at them again | |||||
// but in case i do decide to look at them again they are still here | |||||
/* | |||||
[TestClass] | [TestClass] | ||||
public class Tests | public class Tests | ||||
{ | { | ||||
@@ -311,8 +315,9 @@ namespace Discord.Tests | |||||
async () => await _targetBot.CurrentUser.Modify(TargetPassword, name), | async () => await _targetBot.CurrentUser.Modify(TargetPassword, name), | ||||
x => _obGuildBot.UserUpdated += x, | x => _obGuildBot.UserUpdated += x, | ||||
x => _obGuildBot.UserUpdated -= x, | x => _obGuildBot.UserUpdated -= x, | ||||
(s, e) => e.After.Username == name);*/ | |||||
} | |||||
(s, e) => e.After.Username == name); | |||||
}*/ | |||||
/* | |||||
[TestMethod] | [TestMethod] | ||||
public void TestSetStatus() | public void TestSetStatus() | ||||
{ | { | ||||
@@ -327,8 +332,9 @@ namespace Discord.Tests | |||||
{ | { | ||||
throw new NotImplementedException(); | throw new NotImplementedException(); | ||||
/*_client.SetStatus(status); | /*_client.SetStatus(status); | ||||
await Task.Delay(50);*/ | |||||
} | |||||
await Task.Delay(50); | |||||
}*/ | |||||
/* | |||||
[TestMethod] | [TestMethod] | ||||
public void TestSetGame() | public void TestSetGame() | ||||
{ | { | ||||
@@ -490,5 +496,5 @@ namespace Discord.Tests | |||||
} | } | ||||
#endregion | #endregion | ||||
} | |||||
}*/ | |||||
} | } |