예제 #1
0
        public async Task <CustomMatch> GetCustomMatch(Guid id)
        {
            //CustomMatchData data = await _db.FindAsync<CustomMatchData>(id.ToString());

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

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

            await PopulateBaseMatch(match);

            foreach (var teamStat in match.TeamStats)
            {
                teamStat.TeamColor = await _metadataRepository.GetTeamColor(teamStat.TeamId);
            }

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

            //data = new CustomMatchData(id, match);
            //_db.InsertAsync(data);
            return(match);
            //}
            //return data.Deserialize();
        }
        public void GetConstructedUri_NoParameters_MatchesExpected()
        {
            var query = new GetCustomMatchDetails();

            var uri = query.GetConstructedUri();

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

            var uri = query.GetConstructedUri();

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

            var uri = query.GetConstructedUri();

            Assert.AreEqual("stats/h5/custom/matches/", uri);
        }
        public async Task GetCustomMatchDetails_MissingGuid()
        {
            var query = new GetCustomMatchDetails();

            await Global.Session.Query(query);

            Assert.Fail("An exception should have been thrown");
        }
        public async Task GetCustomMatchDetails_DoesNotThrow(string guid)
        {
            var query = new GetCustomMatchDetails(new Guid(guid))
                        .SkipCache();

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

            Assert.IsInstanceOf(typeof(CustomMatch), result);
        }
        public async Task GetCustomMatchDetails_IsSerializable(string guid)
        {
            var query = new GetCustomMatchDetails(new Guid(guid))
                        .SkipCache();

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

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

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

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

            var result = await _mockSession.Query(query);

            Assert.IsInstanceOf(typeof(CustomMatch), result);
            Assert.AreEqual(_customMatch, result);
        }
        public void GetConstructedUri_ForMatchId_MatchesExpected(string guid)
        {
            var query = new GetCustomMatchDetails()
                        .ForMatchId(new Guid(guid));

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"stats/h5/custom/matches/{guid}", uri);
        }
        public void GetConstructedUri_ForMatchId_MatchesExpected(string guid)
        {
            var query = new GetCustomMatchDetails()
                .ForMatchId(new Guid(guid));

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"stats/h5/custom/matches/{guid}", uri);
        }
예제 #12
0
        public async Task Query_DoesNotThrow()
        {
            var query = new GetCustomMatchDetails()
                        .ForMatchId(Guid.Empty);

            var result = await _mockSession.Query(query);

            Assert.IsInstanceOf(typeof(CustomMatch), result);
            Assert.AreEqual(_customMatch, result);
        }
        public async Task GetCustomMatchDetails_IsSerializable(string guid)
        {
            var query = new GetCustomMatchDetails()
                .ForMatchId(new Guid(guid));

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

            var serializationUtility = new SerializationUtility<CustomMatch>();
            serializationUtility.AssertRoundTripSerializationIsPossible(result);
        }
예제 #14
0
        public static void Validate(this GetCustomMatchDetails getCustomMatchDetails)
        {
            var validationResult = new ValidationResult();

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

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

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

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

            SchemaUtility.AssertSchemaIsValid(weaponsSchema, jArray);
        }
        public async Task GetCustomMatchDetails_ModelMatchesSchema(string guid)
        {
            var schema = JSchema.Parse(File.ReadAllText(Halo5Config.CustomMatchJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri  = new Uri(Path.GetFullPath(Halo5Config.CustomMatchJsonSchemaPath))
            });

            var query = new GetCustomMatchDetails(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 GetCustomMatchDetails_MissingGuid()
        {
            var query = new GetCustomMatchDetails();

            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 GetCustomMatchDetails_InvalidGuid()
        {
            var query = new GetCustomMatchDetails(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 GetCustomMatchDetails(string gamertag)
        {
            var getMatchesQuery = new GetMatches()
                .InGameMode(Enumeration.GameMode.Custom)
                .ForPlayer(gamertag);

            var matches = await Session.Query(getMatchesQuery);

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

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

                var result = await Session.Query(getCustomMatchDetailsQuery);

                Assert.IsInstanceOf(typeof(CustomMatch), result);
            }
        }
        public async Task GetCustomMatchDetails_SchemaIsValid(string guid)
        {
            var weaponsSchema = JSchema.Parse(File.ReadAllText(Config.CustomMatchJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri = new Uri(Path.GetFullPath(Config.CustomMatchJsonSchemaPath))
            });

            var query = new GetCustomMatchDetails()
                .ForMatchId(new Guid(guid))
                .SkipCache();

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

            SchemaUtility.AssertSchemaIsValid(weaponsSchema, jArray);
        }
        public void Uri_MatchesExpected(string guid)
        {
            var query = new GetCustomMatchDetails(new Guid(guid));

            Assert.AreEqual($"https://www.haloapi.com/stats/h5pc/custom/matches/{guid}", query.Uri);
        }
        public async Task GetCustomMatchDetails_MissingGuid()
        {
            var query = new GetCustomMatchDetails();

            await Global.Session.Query(query);
            Assert.Fail("An exception should have been thrown");
        }
        public async Task GetCustomMatchDetails_ModelMatchesSchema(string guid)
        {
            var schema = JSchema.Parse(File.ReadAllText(Config.CustomMatchJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri = new Uri(Path.GetFullPath(Config.CustomMatchJsonSchemaPath))
            });

            var query = new GetCustomMatchDetails()
                .ForMatchId(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 GetCustomMatchDetails_InvalidGuid(string guid)
        {
            var query = new GetCustomMatchDetails()
                .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);
            }
        }