Skip to content
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
3 changes: 3 additions & 0 deletions Source/HaloSharp.Test/Config/Halo5Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public static class Halo5Config
public const string WeaponsJsonPath = "JSON/Halo5/Metadata/weapons.json";
public const string WeaponsJsonSchemaPath = "JSON/Halo5/Metadata/weapons.schema.json";

public const string PlayerAppearancePath = "JSON/Halo5/Profile/player-appearance.json";
public const string PlayerAppearanceSchemaPath = "JSON/Halo5/Profile/player-appearance.schema.json";

public const string ArenaMatchJsonPath = "JSON/Halo5/Stats/CarnageReport/arena-match.json";
public const string ArenaMatchJsonSchemaPath = "JSON/Halo5/Stats/CarnageReport/arena-match.schema.json";
public const string CampaignMatchJsonPath = "JSON/Halo5/Stats/CarnageReport/campaign-match.json";
Expand Down
10 changes: 10 additions & 0 deletions Source/HaloSharp.Test/HaloSharp.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<Compile Include="Query\Halo5\Metadata\GetTeamColorsTests.cs" />
<Compile Include="Query\Halo5\Metadata\GetVehiclesTests.cs" />
<Compile Include="Query\Halo5\Metadata\GetWeaponsTests.cs" />
<Compile Include="Query\Halo5\Profile\GetPlayerAppearanceTests.cs" />
<Compile Include="Query\Halo5\Stats\CarnageReport\GetMatchEventsTests.cs" />
<Compile Include="Query\Halo5\Stats\CarnageReport\GetArenaMatchDetailsTests.cs" />
<Compile Include="Query\Halo5\Stats\CarnageReport\GetCampaignMatchDetailsTests.cs" />
Expand Down Expand Up @@ -270,6 +271,12 @@
<None Include="JSON\Halo5\Metadata\Common\reward.schema.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="JSON\Halo5\Profile\player-appearance.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="JSON\Halo5\Profile\player-appearance.schema.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="JSON\Halo5\Stats\CarnageReport\Common\boost-info.schema.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -623,6 +630,9 @@
<Name>HaloSharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions />
Expand Down
14 changes: 14 additions & 0 deletions Source/HaloSharp.Test/JSON/Halo5/Profile/player-appearance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Gamertag": "Furiousn00b",
"LastModifiedUtc": {
"ISO8601Date": "2016-07-03T00:00:00Z"
},
"FirstModifiedUtc": {
"ISO8601Date": "2015-10-19T00:00:00Z"
},
"ServiceTag": "FURI",
"Company": {
"Id": "a2f47e59-5cc0-44f8-a542-77c162fe69e8",
"Name": "Section 3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"definitions": {
"Player-Appearance": {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"Gamertag": {
"type": "string"
},
"LastModifiedUTC": {
"$ref": "../../common/iso-8061.schema.json"
},
"FirstModifiedUTC": {
"$ref": "../../common/iso-8061.schema.json"
},
"ServiceTag": {
"type": "string"
},
"Company": {
"type": [ "array", "null" ],
"items": {
"Id": {
"type": "guid"
},
"Name": {
"type": "string"
}
}
}
},
"required": [
"Gamertag",
"LastModifiedUTC",
"FirstModifiedUTC",
"ServiceTag",
"Company"
]
}
},

"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"items": {
"$ref": "#/definitions/Player-Appearance"
}
}
144 changes: 144 additions & 0 deletions Source/HaloSharp.Test/Query/Halo5/Profile/GetPlayerAppearanceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using System;
using System.IO;
using System.Threading.Tasks;
using HaloSharp.Exception;
using HaloSharp.Extension;
using HaloSharp.Model;
using HaloSharp.Model.Common;
using HaloSharp.Model.Halo5.Profile;
using HaloSharp.Query.Halo5.Profile;
using HaloSharp.Test.Config;
using HaloSharp.Test.Utility;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using NUnit.Framework;

namespace HaloSharp.Test.Query.Halo5.Profile
{
[TestFixture]
public class GetPlayerAppearanceTests
{

private IHaloSession _mockSession;
private PlayerAppearance _playerAppearance;

[SetUp]
public void Setup()
{
_playerAppearance = JsonConvert.DeserializeObject<PlayerAppearance>(File.ReadAllText(Halo5Config.PlayerAppearancePath));

var mock = new Mock<IHaloSession>();
mock.Setup(m => m.Get<PlayerAppearance>(It.IsAny<string>()))
.ReturnsAsync(_playerAppearance);

_mockSession = mock.Object;
}

[Test]
[TestCase("Sn1p3r C")]
[TestCase("Furiousn00b")]
public void Uri_MatchesExpected(string gamertag)
{
var query = new GetPlayerAppearance(gamertag);

Assert.AreEqual($"https://www.haloapi.com/profile/h5/profiles/{gamertag}/appearance", query.Uri);
}

[Test]
[TestCase("Furiousn00b")]
public async Task Query_DoesNotThrow(string gamertag)
{
var query = new GetPlayerAppearance(gamertag)
.SkipCache();

var result = await _mockSession.Query(query);

Assert.IsInstanceOf(typeof(PlayerAppearance), result);
Assert.AreEqual(_playerAppearance, result);
}

[Test]
[TestCase("Greenskull")]
[TestCase("Furiousn00b")]
public async Task GetPlayerAppearance_DoesNotThrow(string gamertag)
{
var query = new GetPlayerAppearance(gamertag)
.SkipCache();

var result = await Global.Session.Query(query);

Assert.IsInstanceOf(typeof(PlayerAppearance), result);
}

[Test]
[TestCase("Greenskull")]
[TestCase("Furiousn00b")]
public async Task GetPlayerAppearance_SchemaIsValid(string gamertag)
{
var playerAppearanceSchema = JSchema.Parse(File.ReadAllText(Halo5Config.PlayerAppearancePath), new JSchemaReaderSettings
{
Resolver = new JSchemaUrlResolver(),
BaseUri = new Uri(Path.GetFullPath(Halo5Config.PlayerAppearanceSchemaPath))
});

var query = new GetPlayerAppearance(gamertag)
.SkipCache();

var jArray = await Global.Session.Get<JObject>(query.Uri);

SchemaUtility.AssertSchemaIsValid(playerAppearanceSchema, jArray);
}

[Test]
[TestCase("Greenskull")]
[TestCase("Furiousn00b")]
public async Task GetPlayerAppearance_ModelMatchesSchema(string gamertag)
{

var schema = JSchema.Parse(File.ReadAllText(Halo5Config.PlayerAppearancePath), new JSchemaReaderSettings
{
Resolver = new JSchemaUrlResolver(),
BaseUri = new Uri(Path.GetFullPath(Halo5Config.PlayerAppearanceSchemaPath))
});

var query = new GetPlayerAppearance(gamertag)
.SkipCache();

var result = await Global.Session.Query(query);

var json = JsonConvert.SerializeObject(result);
var jContainer = JsonConvert.DeserializeObject<JObject>(json);

SchemaUtility.AssertSchemaIsValid(schema, jContainer);
}

[Test]
[TestCase("Greenskull")]
[TestCase("Furiousn00b")]
public async Task GetPlayerAppearance_IsSerializable(string gamertag)
{
var query = new GetPlayerAppearance(gamertag)
.SkipCache();

var result = await Global.Session.Query(query);

SerializationUtility<PlayerAppearance>.AssertRoundTripSerializationIsPossible(result);
}

[Test]
[TestCase("00000000000000017")]
[TestCase("!$%")]
[ExpectedException(typeof(ValidationException))]
public async Task GetPlayerAppearance_InvalidGamertag(string gamertag)
{
var query = new GetPlayerAppearance(gamertag);

await Global.Session.Query(query);
Assert.Fail("An exception should have been thrown");
}


}
}
2 changes: 2 additions & 0 deletions Source/HaloSharp/HaloSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Compile Include="Model\Halo5\Metadata\Skull.cs" />
<Compile Include="Model\CacheSettings.cs" />
<Compile Include="Model\Halo5\Profile\HaloImage.cs" />
<Compile Include="Model\Halo5\Profile\PlayerAppearance.cs" />
<Compile Include="Model\Halo5\Stats\CarnageReport\Events\Death.cs" />
<Compile Include="Model\Halo5\Stats\CarnageReport\Events\Impulse.cs" />
<Compile Include="Model\Halo5\Stats\CarnageReport\Events\MatchEvent.cs" />
Expand Down Expand Up @@ -262,6 +263,7 @@
<Compile Include="Query\Halo5\Metadata\GetVehicles.cs" />
<Compile Include="Query\Halo5\Metadata\GetWeapons.cs" />
<Compile Include="Query\Halo5\Metadata\GetSkulls.cs" />
<Compile Include="Query\Halo5\Profile\GetPlayerAppearance.cs" />
<Compile Include="Query\Halo5\Profile\GetSpartanImage.cs" />
<Compile Include="Query\Halo5\Profile\GetEmblemImage.cs" />
<Compile Include="Query\Halo5\Stats\CarnageReport\GetMatchEvents.cs" />
Expand Down
77 changes: 77 additions & 0 deletions Source/HaloSharp/Model/Halo5/Profile/PlayerAppearance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using Newtonsoft.Json;
using HaloSharp.Model.Common;

namespace HaloSharp.Model.Halo5.Profile
{
[Serializable]
public class PlayerAppearance : IEquatable<PlayerAppearance>
{
[JsonProperty(PropertyName = "gamertag")]
public string Gamertag { get; set; }

[JsonProperty(PropertyName = "LastModifiedUtc")]
public ISO8601 LastModifiedUtc { get; set; }

[JsonProperty(PropertyName = "FirstModifiedUtc")]
public ISO8601 FirstModifiedUtc { get; set; }

[JsonProperty(PropertyName = "serviceTag")]
public string ServiceTag { get; set; }

[JsonProperty(PropertyName = "Company")]
public Company company { get; set; }

public bool Equals(PlayerAppearance other)
{
if (ReferenceEquals(null, other))
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return company.Equals(other.company)
&& Gamertag == other.Gamertag
&& LastModifiedUtc == other.LastModifiedUtc
&& FirstModifiedUtc == other.FirstModifiedUtc
&& ServiceTag == other.ServiceTag;
}
}

[Serializable]
public class Company : IEquatable<Company>
{
[JsonProperty(PropertyName = "id")]
public Guid Id { get; set; }

[JsonProperty(PropertyName = "name")]
public string Name { get; set; }


public bool Equals(Company other)
{

if (ReferenceEquals(null, other))
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return Id == other.Id
&& Name == other.Name;
}

}




}
37 changes: 37 additions & 0 deletions Source/HaloSharp/Query/Halo5/Profile/GetPlayerAppearance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using HaloSharp.Exception;
using HaloSharp.Model;
using HaloSharp.Model.Halo5.Profile;
using HaloSharp.Validation.Common;

namespace HaloSharp.Query.Halo5.Profile
{
public class GetPlayerAppearance : Query<PlayerAppearance>
{
protected virtual string Path => $"profile/h5/profiles/{_player}/appearance";

public override string Uri => HaloUriBuilder.Build(Path);

private readonly string _player;

public GetPlayerAppearance(string gamertag)
{
_player = gamertag;
}

protected override void Validate()
{
var validationResult = new ValidationResult();

if(!_player.IsValidGamertag())
{
validationResult.Messages.Add("GetPlayerAppearance query requires a valid Gamertag (Player) to be set.");
}

if (!validationResult.Success)
{
throw new ValidationException(validationResult.Messages);
}
}

}
}