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

Added Tests and Some Fixes #19

Merged
merged 12 commits into from
Apr 11, 2018
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
![PUBG Developer API Logo](https://developer.playbattlegrounds.com/d3fa01d31345504b60eacea226638a02.png)


# Pubg-DotNet
# Pubg-DotNet [![Build status](https://ci.appveyor.com/api/projects/status/w3vk9q4avelqpgcp?svg=true)](https://ci.appveyor.com/project/GavinPower747/pubg-dotnet)

A sync/async client library for communicating with the Pubg developer api. Supporting .Net Standard 2.0.

Contact GavinPower747 on the Pubg Api Discord for more details
Expand Down
51 changes: 51 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 1.0.0.{build}
image: Visual Studio 2017
skip_tags: true

environment:
PUBG_API_KEY:
secure: nKrgxWXcCr2GkDIzvtKvEyQNVprTcJzHx56hiB8A8Od16OmcYU6Kv78s7cEecYKo+S/C0Hi6B26cZ+V6RqFw7cpHgj6Vpix9uUfkuluYfWikvgqfFgs1EV3PVMP4Nw6rur3lo2KWe7UOHfI5mDqz4aLB0pWY0oP2uAIvYVsRdB7tk6K6raIiNJL5z+REh6ramPPyGgK3DUjgpUoGByKts8pS8dvMrER48JPoGHfjymbX5zzsypGX/V+48VykcP8FBT+0HQYEAiT3l7/udER+EtZ1FwG6XNZ90NnuL+idcAbKqq0EXfOCPHc8UHDUS6nhmIfRER+0MwgHNeNv3uMo736hw57Vv5TXRN+7aRgonoF/DB9692kjqdTdn5kBJR0l3LEjrNzI3UrBkmaRfoKZxw==

deploy:
- provider: NuGet
api_key:
secure: tRU8M11vrr1xpuhdmBSOSSjQZXAEQVGHR1dP+f/c+RkA1+ZJqCDY2Rsv9Nk4okeT
on:
branch: master

- provider: Github
release: Pubg.Net-v$(appveyor_build_version)
description: 'Release of $(appveyor_build_version)'
auth_token:
secure: 6bQdMR64k8Hsx3yyvLjkfD9K16vBFYQg85PqD5tAypkcBRe8cSsofZAgavw1QrVm
artifact: /.*\.nupkg/ # upload all NuGet packages to release assets
draft: false
prerelease: false
on:
branch: master # release from master branch only


before_build:
- dotnet --info
- ps: Write-Host $("Performing Dot Net Restore")
- dotnet restore

build:
parallel: true

build_script:
- ps: Write-Host $("Performing build")
- dotnet build -c Release src\pubg-dotnet
- dotnet build -c Debug src\pubg-dotnet
- dotnet build -c Debug test\pubg-dotnet.Tests

after_build:
- ps: Write-Host $("Performing dotnet pack")
- dotnet pack -c Release src\pubg-dotnet

test_script:
- ps: Write-Host $("Starting tests")
- dotnet test test\pubg-dotnet.Tests\pubg-dotnet.Tests.csproj

artifacts:
- path: '**\*.nupkg'
4 changes: 0 additions & 4 deletions src/pubg-dotnet/Infrastructure/HttpRequestor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using Pubg.Net.Exceptions;
using System;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down
5 changes: 4 additions & 1 deletion src/pubg-dotnet/Models/Common/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public enum PubgRegion
PCKakao, //What?

[EnumMember(Value = "pc-krjp")]
PCKoreaJapan,
PCKorea,

[EnumMember(Value = "pc-jp")]
PCJapan,

[EnumMember(Value = "pc-na")]
PCNorthAmerica,
Expand Down
17 changes: 0 additions & 17 deletions src/pubg-dotnet/Models/Participants/PubgMatchPlayer.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/pubg-dotnet/Models/Participants/PubgParticipant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ public class PubgParticipant : PubgShardedEntity

[JsonProperty]
public string Actor { get; set; }

[JsonProperty]
public PubgMatchPlayer Player { get; set; }
}
}
12 changes: 6 additions & 6 deletions src/pubg-dotnet/Models/Participants/PubgParticipantStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ namespace Pubg.Net
{
public class PubgParticipantStats
{
[JsonProperty]
public string Name { get; set; }

[JsonProperty]
public string PlayerId { get; set; }

[JsonProperty("DBNOs")]
public int DBNOs { get; set; }

Expand Down Expand Up @@ -49,12 +55,6 @@ public class PubgParticipantStats
[JsonProperty]
public int MostDamage { get; set; }

[JsonProperty]
public string Name { get; set; }

[JsonProperty]
public string PlayerId { get; set; }

[JsonProperty]
public int Revives { get; set; }

Expand Down
22 changes: 2 additions & 20 deletions src/pubg-dotnet/pubg-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,23 @@
<PropertyGroup>
<Description>Sync and Async client library for communicating with the Pubg Developer API supporting .net standard 2.0</Description>
<AssemblyTitle>Pubg.Net</AssemblyTitle>
<VersionPrefix>0.7</VersionPrefix>
<Version>0.7</Version>
<Version>1.0.1</Version>
<Authors>Gavin Power</Authors>
<TargetFramework>netstandard2.0;net45</TargetFramework>
<AssemblyName>Pubg.Net</AssemblyName>
<PackageId>Pubg-DotNet</PackageId>
<PackageTags>pubg;playerunknown;battlegrounds;developer;api</PackageTags>
<PackageProjectUrl>https://github.com/GavinPower747/pubg-dotnet</PackageProjectUrl>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard2.0' ">$(PackageTargetFallback);netcoreapp1.0</PackageTargetFallback>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard2.0' ">1.6.1</NetStandardImplicitPackageVersion>
<SignAssembly>True</SignAssembly>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Pubg.Net</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Product>Pubg.Net</Product>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="JsonApiSerializer" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
Expand Down
9 changes: 0 additions & 9 deletions test/pubg-dotnet.Tests/Class1.cs

This file was deleted.

45 changes: 45 additions & 0 deletions test/pubg-dotnet.Tests/Matches/MatchTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using FluentAssertions;
using Pubg.Net.Tests.Util;
using Pubg.Net.Extensions;
using System.Linq;
using Xunit;
using Pubg.Net.Exceptions;
using System;

namespace Pubg.Net.Tests.Matches
{
public class MatchTests
{
[Fact]
public void Can_Retrieve_Match()
{
var region = PubgRegion.PCEurope;
var player = Storage.GetPlayer(region);
var matchService = new PubgMatchService(Storage.ApiKey);

var match = matchService.GetMatch(region, player.MatchIds.FirstOrDefault());

match.ShardId.Should().Equals(region.Serialize());
match.Rosters.Should().NotBeNull();

var participants = match.Rosters.SelectMany(x => x.Participants);

participants.Should().NotBeNullOrEmpty();

var matchPlayer = participants.FirstOrDefault(p => p.Stats.PlayerId == player.Id);

matchPlayer.Should().NotBeNull();
matchPlayer.Stats.Name.Should().Equals(player.Name);

Assert.All(participants, p => p.Stats.Should().NotBeNull());
Assert.All(participants, p => p.ShardId.Should().Equals(region.Serialize()));
Assert.All(participants, p => p.Id.Should().NotBeNullOrWhiteSpace());
}

[Fact]
public void Throws_Exception_When_NotFound()
{
Assert.Throws<PubgNotFoundException>(() => new PubgMatchService(Storage.ApiKey).GetMatch(PubgRegion.PCEurope, Guid.Empty.ToString()));
}
}
}
61 changes: 61 additions & 0 deletions test/pubg-dotnet.Tests/Players/PlayerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Pubg.Net.Tests.Util;
using Pubg.Net;
using Pubg.Net.Exceptions;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Pubg.Net.Tests.Players
{
public class PlayerTests
{
[Fact]
public void Can_Get_Players_ByName()
{
var playerService = new PubgPlayerService(Storage.ApiKey);

KnownPlayers.KnownPlayerNames.TryGetValue(PubgRegion.PCEurope, out string[] playerNames);

var filter = new GetPubgPlayersRequest
{
PlayerNames = playerNames
};

var players = playerService.GetPlayers(PubgRegion.PCEurope, filter);

Assert.NotEmpty(players);
Assert.All(players.Select(p => p.Name), name => playerNames.Contains(name));
}

[Fact]
public void Can_Get_Players_ById()
{
var playerService = new PubgPlayerService(Storage.ApiKey);

KnownPlayers.KnownPlayerIds.TryGetValue(PubgRegion.PCEurope, out string[] playerIds);

var filter = new GetPubgPlayersRequest
{
PlayerIds = playerIds
};

var players = playerService.GetPlayers(PubgRegion.PCEurope, filter);

Assert.NotEmpty(players);
Assert.All(players.Select(p => p.Id), id => playerIds.Contains(id));
}

[Fact]
public void GetPlayers_Throws_Exception_When_NotFound()
{
var playerService = new PubgPlayerService(Storage.ApiKey);

var filter = new GetPubgPlayersRequest
{
PlayerNames = new string[] { "NonExistantPlayerHopefully" }
};

Assert.Throws<PubgNotFoundException>(() => playerService.GetPlayers(PubgRegion.PCEurope, filter));
}
}
}
20 changes: 20 additions & 0 deletions test/pubg-dotnet.Tests/Status/StatusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FluentAssertions;
using Pubg.Net.Tests.Util;
using Pubg.Net;
using Xunit;

namespace Pubg.Net.Tests.Status
{
public class StatusTests
{
[Fact]
public void Can_Retrieve_Status()
{
var status = new PubgStatusService(Storage.ApiKey).GetStatus();

status.Attributes.Should().NotBeNull();
status.Attributes.Version.Should().NotBeNullOrWhiteSpace();
status.Id.Should().NotBeNullOrWhiteSpace();
}
}
}
23 changes: 23 additions & 0 deletions test/pubg-dotnet.Tests/Telemetry/TelemetryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentAssertions;
using Pubg.Net.Tests.Util;
using Pubg.Net;
using System.Linq;
using Xunit;

namespace Pubg.Net.Tests.Telemetry
{
public class TelemetryTests
{
[Fact]
public void Can_Pull_Telemetry_From_Match()
{
var match = Storage.GetMatch(PubgRegion.PCEurope);
var asset = match.Assets.FirstOrDefault();
var telemetryService = new PubgTelemetryService();

var telemetry = telemetryService.GetTelemetry(PubgRegion.PCEurope, asset);

telemetry.Should().NotBeEmpty();
}
}
}
35 changes: 35 additions & 0 deletions test/pubg-dotnet.Tests/Util/KnownPlayers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Pubg.Net;
using System.Collections.Generic;

namespace Pubg.Net.Tests.Util
{
//Far from ideal but there is no way to query a list of players
public static class KnownPlayers
{
public static Dictionary<PubgRegion, string[]> KnownPlayerNames = new Dictionary<PubgRegion, string[]>
{
{
PubgRegion.PCEurope,
new string[]
{
"jebuzjack",
"Dutsization",
"irishdiablo",
"chmcl08"
}
}
};

public static Dictionary<PubgRegion, string[]> KnownPlayerIds = new Dictionary<PubgRegion, string[]>
{
{
PubgRegion.PCEurope,
new string[]
{
"account.dbe0812874d642f7be09814cfb92c89a",
"account.e9548dfdc07847b29bb51cbcc0b4cde7"
}
}
};
}
}
Loading