public void Uri_MatchesExpected(string gamertag, Enumeration.Halo5.UserGeneratedContentSort sort, int skip, int take)
        {
            var query = new ListMapVariants(gamertag);

            Assert.AreEqual($"https://www.haloapi.com/ugc/h5/players/{gamertag}/mapvariants", query.Uri);

            query.SortBy(sort);

            Assert.AreEqual($"https://www.haloapi.com/ugc/h5/players/{gamertag}/mapvariants?sort={sort}", query.Uri);

            query.OrderByAscending();

            Assert.AreEqual($"https://www.haloapi.com/ugc/h5/players/{gamertag}/mapvariants?sort={sort}&order=asc", query.Uri);

            query.OrderByDescending();

            Assert.AreEqual($"https://www.haloapi.com/ugc/h5/players/{gamertag}/mapvariants?sort={sort}&order=desc", query.Uri);

            query.Skip(skip);

            Assert.AreEqual($"https://www.haloapi.com/ugc/h5/players/{gamertag}/mapvariants?sort={sort}&order=desc&start={skip}", query.Uri);

            query.Take(take);

            Assert.AreEqual($"https://www.haloapi.com/ugc/h5/players/{gamertag}/mapvariants?sort={sort}&order=desc&start={skip}&count={take}", query.Uri);
        }
        public static void Validate(this ListMapVariants listMapVariants)
        {
            var validationResult = new ValidationResult();

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

            if (listMapVariants.Parameters.ContainsKey("count"))
            {
                int count;
                var parsed = int.TryParse(listMapVariants.Parameters["count"], out count);

                if (!parsed || count < 1 || count > 100)
                {
                    validationResult.Messages.Add($"ListMapVariants optional parameter 'Take' is invalid: {count}.");
                }
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public void GetConstructedUri_NoParameters_MatchesExpected()
        {
            var query = new ListMapVariants();

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants", uri);
        }
        public async Task ListMapVariants_InvalidGamertag(string gamertag)
        {
            var query = new ListMapVariants(gamertag);

            await Global.Session.Query(query);

            Assert.Fail("An exception should have been thrown");
        }
        public void GetConstructedUri_NoParameters_MatchesExpected()
        {
            var query = new ListMapVariants();

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants", uri);
        }
        public async Task ListMapVariants_MissingPlayer()
        {
            var query = new ListMapVariants();

            await Global.Session.Query(query);

            Assert.Fail("An exception should have been thrown");
        }
        public async Task ListMapVariants_IsSerializable(string gamertag)
        {
            var query = new ListMapVariants(gamertag)
                        .SkipCache();

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

            SerializationUtility <MapVariantResult> .AssertRoundTripSerializationIsPossible(result);
        }
        public async Task ListMapVariants_InvalidTake(int take)
        {
            var query = new ListMapVariants("ducain23")
                        .Take(take);

            await Global.Session.Query(query);

            Assert.Fail("An exception should have been thrown");
        }
        public void GetConstructedUri_SortBy_MatchesExpected(Enumeration.UserGeneratedContentSort sort)
        {
            var query = new ListMapVariants()
                .SortBy(sort);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants?sort={sort}", uri);
        }
        public async Task ListMapVariants_DoesNotThrow(string gamertag)
        {
            var query = new ListMapVariants(gamertag)
                        .SkipCache();

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

            Assert.IsInstanceOf(typeof(MapVariantResult), result);
        }
        public void GetConstructedUri_Skip_MatchesExpected(int skip)
        {
            var query = new ListMapVariants()
                        .Skip(skip);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants?start={skip}", uri);
        }
        public void GetConstructedUri_OrderByDescending_MatchesExpected()
        {
            var query = new ListMapVariants()
                        .OrderByDescending();

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants?order=desc", uri);
        }
        public void GetConstructedUri_SortBy_MatchesExpected(Enumeration.UserGeneratedContentSort sort)
        {
            var query = new ListMapVariants()
                        .SortBy(sort);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants?sort={sort}", uri);
        }
        public void GetConstructedUri_ForPlayer_MatchesExpected(string gamertag)
        {
            var query = new ListMapVariants()
                        .ForPlayer(gamertag);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{gamertag}/mapvariants", uri);
        }
        public void GetConstructedUri_OrderByDescending_MatchesExpected()
        {
            var query = new ListMapVariants()
                .OrderByDescending();

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants?order=desc", uri);
        }
        public void GetConstructedUri_ForPlayer_MatchesExpected(string gamertag)
        {
            var query = new ListMapVariants()
                .ForPlayer(gamertag);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{gamertag}/mapvariants", uri);
        }
        public void GetConstructedUri_Take_MatchesExpected(int take)
        {
            var query = new ListMapVariants()
                        .Take(take);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants?count={take}", uri);
        }
        public async Task Query_DoesNotThrow(string gamertag)
        {
            var query = new ListMapVariants(gamertag)
                        .SkipCache();

            var result = await _mockSession.Query(query);

            Assert.IsInstanceOf(typeof(MapVariantResult), result);
            Assert.AreEqual(_mapVariantResult, result);
        }
        public void GetConstructedUri_Complex_MatchesExpected(string gamertag, Enumeration.UserGeneratedContentSort sort, int skip, int take)
        {
            var query = new ListMapVariants()
                        .ForPlayer(gamertag)
                        .SortBy(sort)
                        .OrderByAscending()
                        .Skip(skip)
                        .Take(take);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{gamertag}/mapvariants?sort={sort}&order=asc&start={skip}&count={take}", uri);
        }
        public async Task ListMapVariants_SchemaIsValid(string gamertag)
        {
            var weaponsSchema = JSchema.Parse(File.ReadAllText(Halo5Config.UserGeneratedContentMapVariantsJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri  = new Uri(Path.GetFullPath(Halo5Config.UserGeneratedContentMapVariantsJsonSchemaPath))
            });

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

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

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

            var query = new ListMapVariants(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 ListMapVariants_InvalidGamertag(string gamertag)
        {
            var query = new ListMapVariants()
                .ForPlayer(gamertag);

            await Global.Session.Query(query);
            Assert.Fail("An exception should have been thrown");
        }
        public void GetConstructedUri_Take_MatchesExpected(int take)
        {
            var query = new ListMapVariants()
                .Take(take);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants?count={take}", uri);
        }
        public void GetConstructedUri_Complex_MatchesExpected(string gamertag, Enumeration.UserGeneratedContentSort sort, int skip, int take)
        {
            var query = new ListMapVariants()
                .ForPlayer(gamertag)
                .SortBy(sort)
                .OrderByAscending()
                .Skip(skip)
                .Take(take);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{gamertag}/mapvariants?sort={sort}&order=asc&start={skip}&count={take}", uri);
        }
        public async Task ListMapVariants_DoesNotThrow(string gamertag)
        {
            var query = new ListMapVariants()
                .ForPlayer(gamertag)
                .SkipCache();

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

            Assert.IsInstanceOf(typeof(MapVariantResult), result);
        }
        public async Task ListMapVariants_SchemaIsValid(string gamertag)
        {
            var weaponsSchema = JSchema.Parse(File.ReadAllText(Config.UserGeneratedContentMapVariantsJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri = new Uri(Path.GetFullPath(Config.UserGeneratedContentMapVariantsJsonSchemaPath))
            });

            var query = new ListMapVariants()
                .ForPlayer(gamertag)
                .SkipCache();

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

            SchemaUtility.AssertSchemaIsValid(weaponsSchema, jArray);
        }
        public async Task ListMapVariants_ModelMatchesSchema(string gamertag)
        {
            var schema = JSchema.Parse(File.ReadAllText(Config.UserGeneratedContentMapVariantsJsonSchemaPath), new JSchemaReaderSettings
            {
                Resolver = new JSchemaUrlResolver(),
                BaseUri = new Uri(Path.GetFullPath(Config.UserGeneratedContentMapVariantsJsonSchemaPath))
            });

            var query = new ListMapVariants()
                .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 ListMapVariants_IsSerializable(string gamertag)
        {
            var query = new ListMapVariants()
                .ForPlayer(gamertag)
                .SkipCache();

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

            SerializationUtility<MapVariantResult>.AssertRoundTripSerializationIsPossible(result);
        }
        public async Task ListMapVariants_MissingPlayer()
        {
            var query = new ListMapVariants();

            await Global.Session.Query(query);
            Assert.Fail("An exception should have been thrown");
        }
        public void GetConstructedUri_Skip_MatchesExpected(int skip)
        {
            var query = new ListMapVariants()
                .Skip(skip);

            var uri = query.GetConstructedUri();

            Assert.AreEqual($"ugc/h5/players/{null}/mapvariants?start={skip}", uri);
        }
        public async Task ListMapVariants_InvalidTake(int take)
        {
            var query = new ListMapVariants()
                .ForPlayer("ducain23")
                .Take(take);

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