Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svajunas PR #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .vs/NetParty/DesignTimeBuild/.dtbcache
Binary file not shown.
Binary file added .vs/NetParty/v16/.suo
Binary file not shown.
Empty file.
Binary file added .vs/NetParty/v16/Server/sqlite3/storage.ide
Binary file not shown.
Binary file not shown.
Binary file added .vs/NetParty/v16/Server/sqlite3/storage.ide-wal
Binary file not shown.
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\NetParty.sln",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
Binary file added .vs/svajunas-branch/v16/.suo
Binary file not shown.
23 changes: 23 additions & 0 deletions NetParty.API/NetParty.Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NetParty.Application\NetParty.Application.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
51 changes: 51 additions & 0 deletions NetParty.API/PlaygroundApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using NetParty.Application.Interfaces;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Net.Http;
using System;
using Newtonsoft.Json;
using System.Text;
using System.IO;
using System.Net.Http.Headers;

namespace NetParty.Api
{
public class PlaygroundApi: IApi
{
private IConfiguration _configuration;
private readonly HttpClient _client;
public PlaygroundApi()
{
_configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
;
_client = new HttpClient();
}

public async Task<string> GetAuthorizationToken(string username, string password)
{
var uri = new Uri(_configuration.GetSection("authorization_url").Value);
var request = JsonConvert.SerializeObject(new { username = username, password = password });
var remoteResult = await _client.PostAsync(uri, new StringContent(request, Encoding.UTF8, "application/json"));
var contentOfResponse = await remoteResult.Content.ReadAsStringAsync();
var jsonResult = JsonConvert.DeserializeObject<Token>(contentOfResponse);
string token = jsonResult.token;

return token;
}

public async Task<IList<IServer>> GetServers(string token)
{
var uri = new Uri(_configuration.GetSection("servers_list_url").Value);
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var remoteResult = await _client.GetAsync(uri);
var contentOfResponse = await remoteResult.Content.ReadAsStringAsync();
var res = JsonConvert.DeserializeObject<Server[]>(contentOfResponse);

return res;
}
}
}
10 changes: 10 additions & 0 deletions NetParty.API/Server.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using NetParty.Application.Interfaces;

namespace NetParty.Api
{
internal class Server : IServer
{
public string Name { get; set; }
public string Distance { get; set; }
}
}
7 changes: 7 additions & 0 deletions NetParty.API/Token.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace NetParty.Api
{
public class Token
{
public string token { get; set; }
}
}
4 changes: 4 additions & 0 deletions NetParty.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"authorization_url": "http://playground.tesonet.lt/v1/tokens",
"servers_list_url": "http://playground.tesonet.lt/v1/servers"
}
23 changes: 23 additions & 0 deletions NetParty.API/obj/Debug/netstandard2.0/NetParty.Api.AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("NetParty.Api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("NetParty.Api")]
[assembly: System.Reflection.AssemblyTitleAttribute("NetParty.Api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
179b044fe6aeb86e235a774c96924c5df672bf92
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f5dd11798fca2cfabdb48805e59e087146898bcf
122 changes: 122 additions & 0 deletions NetParty.API/server_list_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
[
{
"name": "Singapore #40",
"distance": 1364
},
{
"name": "Germany #95",
"distance": 1095
},
{
"name": "United States #68",
"distance": 1670
},
{
"name": "United Kingdom #73",
"distance": 1005
},
{
"name": "Japan #66",
"distance": 1039
},
{
"name": "Germany #43",
"distance": 843
},
{
"name": "Japan #40",
"distance": 1524
},
{
"name": "Japan #23",
"distance": 982
},
{
"name": "Singapore #41",
"distance": 334
},
{
"name": "Lithuania #35",
"distance": 634
},
{
"name": "Japan #38",
"distance": 1343
},
{
"name": "Germany #23",
"distance": 1400
},
{
"name": "United States #97",
"distance": 1327
},
{
"name": "United States #62",
"distance": 1283
},
{
"name": "United States #21",
"distance": 1750
},
{
"name": "Japan #47",
"distance": 1975
},
{
"name": "Japan #85",
"distance": 1112
},
{
"name": "Germany #75",
"distance": 1351
},
{
"name": "Singapore #85",
"distance": 1060
},
{
"name": "Germany #59",
"distance": 1574
},
{
"name": "Latvia #76",
"distance": 1410
},
{
"name": "Japan #89",
"distance": 143
},
{
"name": "Singapore #85",
"distance": 1209
},
{
"name": "Lithuania #57",
"distance": 1937
},
{
"name": "United States #30",
"distance": 655
},
{
"name": "United States #47",
"distance": 1275
},
{
"name": "Latvia #49",
"distance": 1069
},
{
"name": "Latvia #68",
"distance": 356
},
{
"name": "Germany #77",
"distance": 1397
},
{
"name": "Lithuania #68",
"distance": 1594
}
]
42 changes: 42 additions & 0 deletions NetParty.Application.Tests/Infrastucture/Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using NetParty.Application.Constants;
using System.Collections.Generic;

namespace NetParty.Application.Tests.Infrastucture
{
public static class SubstitutedCommands
{
public static SubCommand NotServerListCommandParametersAsNull = new SubCommand()
{
CommandName = "not server list command",
CommandParameters = null
};
public static SubCommand ServerListCommandParametersAsNull = new SubCommand()
{
CommandName = Command.GetServers,
CommandParameters = null
};
public static SubCommand ServerListCommandParametersAsEmptyList = new SubCommand()
{
CommandName = Command.GetServers,
CommandParameters = new Dictionary<string, string>()
};
public static SubCommand ServerListCommandWithParameters = new SubCommand()
{
CommandName = Command.GetServers,
CommandParameters = new Dictionary<string, string>() { { "key1", "value1" } }
};

public static SubCommand ServerListCommandWithFlagParameterAndValue = new SubCommand()
{
CommandName = Command.GetServers,
CommandParameters = new Dictionary<string, string>() { { Parameter.FlagToFetchOnlyPersistedServers, "value1" } }
};

public static SubCommand ServerListCommandWithFlagParameterWithoutValue = new SubCommand()
{
CommandName = Command.GetServers,
CommandParameters = new Dictionary<string, string>() { { Parameter.FlagToFetchOnlyPersistedServers, null } }
};

}
}
11 changes: 11 additions & 0 deletions NetParty.Application.Tests/Infrastucture/SubCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using NetParty.Application.Interfaces;
using System.Collections.Generic;

namespace NetParty.Application.Tests.Infrastucture
{
public class SubCommand : ICommandArgs
{
public string CommandName { get; set; }
public IDictionary<string, string> CommandParameters { get; set; }
}
}
24 changes: 24 additions & 0 deletions NetParty.Application.Tests/NetParty.Application.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NSubstitute" Version="4.0.0" />
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NetParty.Application\NetParty.Application.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Server\Handlers\" />
</ItemGroup>

</Project>
Loading