Ejemplo n.º 1
0
        public async Task <CampaignMatch> GetCampaignMatch(Guid id)
        {
            //var data = await _db.FindAsync<CampaignMatchData>(id.ToString());

            //if (data == null)
            //{
            var query = new GetCampaignMatchDetails().ForMatchId(id);
            var match = await _session.Query(query);

            if (match == null)
            {
                return(null);
            }

            await PopulateBaseMatch(match);

            foreach (var playerStat in match.PlayerStats)
            {
                await PopulatePlayer(playerStat);
            }

            //data = new CampaignMatchData(id, match);
            //_db.InsertAsync(data);
            return(match);
            //}
            //return data.Deserialize();
        }
Ejemplo n.º 2
0
        public void GetConstructedUri_NoParamaters_MatchesExpected()
        {
            var query = new GetCampaignMatchDetails();

            var uri = query.GetConstructedUri();

            Assert.AreEqual("stats/h5/campaign/matches/", uri);
        }
        public void GetConstructedUri_NoParamaters_MatchesExpected()
        {
            var query = new GetCampaignMatchDetails();

            var uri = query.GetConstructedUri();

            Assert.AreEqual(BaseUri, uri);
        }
        public void GetConstructedUri_NoParameters_MatchesExpected()
        {
            var query = new GetCampaignMatchDetails();

            var uri = query.GetConstructedUri();

            Assert.AreEqual("stats/h5/campaign/matches/", uri);
        }
Ejemplo n.º 5
0
        public async Task GetCampaignMatchDetails_MissingGuid()
        {
            var query = new GetCampaignMatchDetails();

            await Global.Session.Query(query);

            Assert.Fail("An exception should have been thrown");
        }
Ejemplo n.º 6
0
        public void GetConstructedUri_ForMatchId_MatchesExpected(string guid)
        {
            var query = new GetCampaignMatchDetails()
                        .ForMatchId(new Guid(guid));

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"stats/h5/campaign/matches/{guid}", uri);
        }
        public async Task GetCampaignMatchDetails_DoesNotThrow(string guid)
        {
            var query = new GetCampaignMatchDetails(new Guid(guid))
                        .SkipCache();

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

            Assert.IsInstanceOf(typeof(CampaignMatch), result);
        }
        public async Task Query_DoesNotThrow()
        {
            var query = new GetCampaignMatchDetails();

            var result = await _mockSession.Query(query);

            Assert.IsInstanceOf(typeof(CampaignMatch), result);
            Assert.AreEqual(_campaignMatch, result);
        }
        public void GetConstructedUri_ForMatchId_MatchesExpected(string guid)
        {
            var query = new GetCampaignMatchDetails()
                .ForMatchId(new Guid(guid));

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"{BaseUri}{guid}", uri);
        }
        public async Task GetCampaignMatchDetails_IsSerializable(string guid)
        {
            var query = new GetCampaignMatchDetails(new Guid(guid))
                        .SkipCache();

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

            SerializationUtility <CampaignMatch> .AssertRoundTripSerializationIsPossible(result);
        }
        public async Task GetCampaignMatchDetails(string guid)
        {
            var query = new GetCampaignMatchDetails()
                .ForMatchId(new Guid(guid));

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

            Assert.IsInstanceOf(typeof(CampaignMatch), result);
        }
Ejemplo n.º 12
0
        public async Task Query_DoesNotThrow()
        {
            var query = new GetCampaignMatchDetails()
                        .ForMatchId(Guid.Empty);

            var result = await _mockSession.Query(query);

            Assert.IsInstanceOf(typeof(CampaignMatch), result);
            Assert.AreEqual(_campaignMatch, result);
        }
        public async Task GetCampaignMatchDetails_IsSerializable(string guid)
        {
            var query = new GetCampaignMatchDetails()
                .ForMatchId(new Guid(guid));

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

            var serializationUtility = new SerializationUtility<CampaignMatch>();
            serializationUtility.AssertRoundTripSerializationIsPossible(result);
        }
        public static void Validate(this GetCampaignMatchDetails getCampaignMatchDetails)
        {
            var validationResult = new ValidationResult();

            if (string.IsNullOrWhiteSpace(getCampaignMatchDetails.MatchId))
            {
                validationResult.Messages.Add("GetCampaignMatchDetails query requires a MatchId to be set.");
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public async Task GetCampaignMatchDetails_SchemaIsValid(string guid)
        {
            var weaponsSchema = JSchema.Parse(File.ReadAllText(Halo5Config.CampaignMatchJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri  = new Uri(Path.GetFullPath(Halo5Config.CampaignMatchJsonSchemaPath))
            });

            var query = new GetCampaignMatchDetails(new Guid(guid))
                        .SkipCache();

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

            SchemaUtility.AssertSchemaIsValid(weaponsSchema, jArray);
        }
        public async Task GetCampaignMatchDetails_MissingGuid()
        {
            var query = new GetCampaignMatchDetails();

            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 GetCampaignMatchDetails_ModelMatchesSchema(string guid)
        {
            var schema = JSchema.Parse(File.ReadAllText(Halo5Config.CampaignMatchJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri  = new Uri(Path.GetFullPath(Halo5Config.CampaignMatchJsonSchemaPath))
            });

            var query = new GetCampaignMatchDetails(new Guid(guid))
                        .SkipCache();

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

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

            SchemaUtility.AssertSchemaIsValid(schema, jContainer);
        }
        public async Task GetCampaignMatchDetails(string gamertag)
        {
            var getMatchesQuery = new GetMatches()
                .InGameMode(Enumeration.GameMode.Campaign)
                .ForPlayer(gamertag);

            var matches = await Session.Query(getMatchesQuery);

            Assert.IsTrue(matches.Results.Any());

            foreach (var match in matches.Results)
            {
                var getCampaignMatchDetailsQuery = new GetCampaignMatchDetails()
                    .ForMatchId(match.Id.MatchId);

                var result = await Session.Query(getCampaignMatchDetailsQuery);

                Assert.IsInstanceOf(typeof(CampaignMatch), result);
            }
        }
        public async Task GetCampaignMatchDetails_InvalidGuid(string guid)
        {
            var query = new GetCampaignMatchDetails(Guid.NewGuid())
                        .SkipCache();

            try
            {
                await Global.Session.Query(query);

                Assert.Fail("An exception should have been thrown");
            }
            catch (HaloApiException e)
            {
                Assert.AreEqual((int)Enumeration.Halo5.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 GetCampaignMatchDetails_SchemaIsValid(string guid)
        {
            var weaponsSchema = JSchema.Parse(File.ReadAllText(Config.CampaignMatchJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri = new Uri(Path.GetFullPath(Config.CampaignMatchJsonSchemaPath))
            });

            var query = new GetCampaignMatchDetails()
                .ForMatchId(new Guid(guid));

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

            SchemaUtility.AssertSchemaIsValid(weaponsSchema, jArray);
        }
        public async Task GetCampaignMatchDetails_InvalidGuid(string guid)
        {
            var query = new GetCampaignMatchDetails()
                .ForMatchId(new Guid(guid))
                .SkipCache();

            try
            {
                await Global.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 void Uri_MatchesExpected(string guid)
        {
            var query = new GetCampaignMatchDetails(new Guid(guid));

            Assert.AreEqual($"https://www.haloapi.com/stats/h5/campaign/matches/{guid}", query.Uri);
        }
        public async Task GetCampaignMatchDetails_ModelMatchesSchema(string guid)
        {
            var schema = JSchema.Parse(File.ReadAllText(Config.CampaignMatchJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri = new Uri(Path.GetFullPath(Config.CampaignMatchJsonSchemaPath))
            });

            var query = new GetCampaignMatchDetails()
                .ForMatchId(new Guid(guid));

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

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

            SchemaUtility.AssertSchemaIsValid(schema, jContainer);
        }
        public async Task GetCampaignMatchDetails_MissingGuid()
        {
            var query = new GetCampaignMatchDetails();

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