public async Task <CampaignServiceRecord> GetCampaignServiceRecord(string gamertag) { var query = new GetCampaignServiceRecord().ForPlayer(gamertag); var record = await _session.Query(query); return(record); }
public static void Validate(this GetCampaignServiceRecord getCampaignServiceRecord) { var validationResult = new ValidationResult(); if (getCampaignServiceRecord.Parameters.ContainsKey("players")) { var players = getCampaignServiceRecord.Parameters["players"].Split(','); foreach (var player in players) { if (!player.IsValidGamertag()) { validationResult.Messages.Add("GetCampaignServiceRecord query requires valid Gamertags (Players) to be set."); } } } else { validationResult.Messages.Add("GetCampaignServiceRecord query requires a Player to be set."); } if (!validationResult.Success) { throw new ValidationException(validationResult.Messages); } }
public void GetConstructedUri_NoParameters_MatchesExpected() { var query = new GetCampaignServiceRecord(); var uri = query.GetConstructedUri(); Assert.AreEqual("stats/h5/servicerecords/campaign", uri); }
public void GetConstructedUri_NoParameters_MatchesExpected() { var query = new GetCampaignServiceRecord(); var uri = query.GetConstructedUri(); Assert.AreEqual("stats/h5/servicerecords/campaign", uri); }
public async Task GetCampaignServiceRecord_MissingPlayer() { var query = new GetCampaignServiceRecord(); await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); }
public async Task GetCampaignServiceRecord_InvalidGamertag(string gamertag) { var query = new GetCampaignServiceRecord(gamertag); await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); }
public async Task GetCampaignServiceRecord(string gamertag) { var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); var result = await Global.Session.Query(query); Assert.IsInstanceOf(typeof(CampaignServiceRecord), result); }
public async Task GetCampaignServiceRecord_IsSerializable(string gamertag) { var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); var result = await Global.Session.Query(query); SerializationUtility <CampaignServiceRecord> .AssertRoundTripSerializationIsPossible(result); }
public async Task GetCampaignServiceRecord_DoesNotThrow(string gamertag) { var query = new GetCampaignServiceRecord(gamertag) .SkipCache(); var result = await Global.Session.Query(query); Assert.IsInstanceOf(typeof(CampaignServiceRecord), result); }
public void GetConstructedUri_ForPlayers_MatchesExpected(string gamertag, string gamertag2) { var query = new GetCampaignServiceRecord() .ForPlayers(new List<string> { gamertag, gamertag2 }); var uri = query.GetConstructedUri(); Assert.AreEqual($"stats/h5/servicerecords/campaign?players={gamertag},{gamertag2}", uri); }
public async Task GetCampaignServiceRecord(string gamertag) { var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); var result = await Session.Query(query); Assert.IsInstanceOf(typeof (CampaignServiceRecord), result); }
public void GetConstructedUri_ForPlayer_MatchesExpected(string gamertag) { var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); var uri = query.GetConstructedUri(); Assert.AreEqual($"stats/h5/servicerecords/campaign?players={gamertag}", uri); }
public async Task Query_DoesNotThrow() { var query = new GetCampaignServiceRecord() .ForPlayer("Player"); var result = await _mockSession.Query(query); Assert.IsInstanceOf(typeof(CampaignServiceRecord), result); Assert.AreEqual(_campaignServiceRecord, result); }
public async Task GetCampaignServiceRecord_IsSerializable(string gamertag) { var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); var result = await Global.Session.Query(query); var serializationUtility = new SerializationUtility<CampaignServiceRecord>(); serializationUtility.AssertRoundTripSerializationIsPossible(result); }
public async Task GetCampaignServiceRecord_SchemaIsValid(string gamertag) { var weaponsSchema = JSchema.Parse(File.ReadAllText(Config.CampaignServiceRecordJsonSchemaPath), new JSchemaReaderSettings { Resolver = new JSchemaUrlResolver(), BaseUri = new Uri(Path.GetFullPath(Config.CampaignServiceRecordJsonSchemaPath)) }); var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); var jArray = await Global.Session.Get <JObject>(query.GetConstructedUri()); SchemaUtility.AssertSchemaIsValid(weaponsSchema, jArray); }
public async Task GetCampaignServiceRecord_ForPlayers() { var gamertags = new List<string> { "Greenskull", "Furiousn00b" }; var query = new GetCampaignServiceRecord() .ForPlayers(gamertags); var result = await Session.Query(query); Assert.IsInstanceOf(typeof(CampaignServiceRecord), result); Assert.AreEqual(2, result.Results.Count); }
public async Task GetCampaignServiceRecord_ModelMatchesSchema(string gamertag) { var schema = JSchema.Parse(File.ReadAllText(Config.CampaignServiceRecordJsonSchemaPath), new JSchemaReaderSettings { Resolver = new JSchemaUrlResolver(), BaseUri = new Uri(Path.GetFullPath(Config.CampaignServiceRecordJsonSchemaPath)) }); var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); var result = await Global.Session.Query(query); var json = JsonConvert.SerializeObject(result); var jContainer = JsonConvert.DeserializeObject <JObject>(json); SchemaUtility.AssertSchemaIsValid(schema, jContainer); }
public async Task GetCampaignServiceRecord_MissingPlayer() { var query = new GetCampaignServiceRecord(); try { await Session.Query(query); Assert.Fail("An exception should have been thrown"); } catch (HaloApiException e) { Assert.AreEqual((int)Enumeration.StatusCode.NotFound, e.HaloApiError.StatusCode); } catch (System.Exception e) { Assert.Fail("Unexpected exception of type {0} caught: {1}", e.GetType(), e.Message); } }
public async Task GetCampaignServiceRecord_SchemaIsValid(string gamertag) { var weaponsSchema = JSchema.Parse(File.ReadAllText(Config.CampaignServiceRecordJsonSchemaPath), new JSchemaReaderSettings { Resolver = new JSchemaUrlResolver(), BaseUri = new Uri(Path.GetFullPath(Config.CampaignServiceRecordJsonSchemaPath)) }); var query = new GetCampaignServiceRecord() .ForPlayer(gamertag) .SkipCache(); var jArray = await Global.Session.Get<JObject>(query.GetConstructedUri()); SchemaUtility.AssertSchemaIsValid(weaponsSchema, jArray); }
public void Uri_MatchesExpected(string gamertag) { var query = new GetCampaignServiceRecord(gamertag); Assert.AreEqual($"https://www.haloapi.com/stats/h5/servicerecords/campaign?players={gamertag}", query.Uri); }
public async Task GetCampaignServiceRecord_DoesNotThrow(string gamertag) { var query = new GetCampaignServiceRecord() .ForPlayer(gamertag) .SkipCache(); var result = await Global.Session.Query(query); Assert.IsInstanceOf(typeof(CampaignServiceRecord), result); }
public async Task GetCampaignServiceRecord_InvalidGamertag(string gamertag) { var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); try { await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); } catch (HaloApiException e) { Assert.AreEqual((int)Enumeration.StatusCode.BadRequest, e.HaloApiError.StatusCode); } catch (System.Exception e) { Assert.Fail("Unexpected exception of type {0} caught: {1}", e.GetType(), e.Message); } }
public async Task GetCampaignServiceRecord_ModelMatchesSchema(string gamertag) { var schema = JSchema.Parse(File.ReadAllText(Config.CampaignServiceRecordJsonSchemaPath), new JSchemaReaderSettings { Resolver = new JSchemaUrlResolver(), BaseUri = new Uri(Path.GetFullPath(Config.CampaignServiceRecordJsonSchemaPath)) }); var query = new GetCampaignServiceRecord() .ForPlayer(gamertag) .SkipCache(); var result = await Global.Session.Query(query); var json = JsonConvert.SerializeObject(result); var jContainer = JsonConvert.DeserializeObject<JObject>(json); SchemaUtility.AssertSchemaIsValid(schema, jContainer); }
public async Task GetCampaignServiceRecord_MissingPlayer() { var query = new GetCampaignServiceRecord(); await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); }
public async Task Query_DoesNotThrow() { var query = new GetCampaignServiceRecord() .ForPlayer("Player") .SkipCache(); var result = await _mockSession.Query(query); Assert.IsInstanceOf(typeof(CampaignServiceRecord), result); Assert.AreEqual(_campaignServiceRecord, result); }
public async Task GetCampaignServiceRecord_InvalidGamertag(string gamertag) { var query = new GetCampaignServiceRecord() .ForPlayer(gamertag); await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); }