public void No_tweet_format_returns_no_match_result_filter()
        {
            var parsedQueryString = HttpUtility.ParseQueryString(string.Empty);
            var parser            = new MatchesRssQueryStringParser();

            var result = parser.ParseFilterFromQueryString(parsedQueryString);

            Assert.Empty(result.MatchResultTypes);
        }
        public void Tweets_should_only_return_matches_with_an_unknown_result()
        {
            var parsedQueryString = HttpUtility.ParseQueryString("?format=tweet");
            var parser            = new MatchesRssQueryStringParser();

            var result = parser.ParseFilterFromQueryString(parsedQueryString);

            Assert.Single(result.MatchResultTypes);
            Assert.Null(result.MatchResultTypes.First());
        }
        public void Tournament_filter_is_parsed_correctly()
        {
            var parsedQueryString = HttpUtility.ParseQueryString("?type=1");
            var parser            = new MatchesRssQueryStringParser();

            var result = parser.ParseFilterFromQueryString(parsedQueryString);

            Assert.False(result.IncludeMatches);
            Assert.True(result.IncludeTournaments);
            Assert.False(result.IncludeTournamentMatches);
        }
        public void No_date_in_querystring_returns_default_date_filter_as_UK_date()
        {
            var parser = new MatchesRssQueryStringParser();

            var result = parser.ParseFilterFromQueryString(new NameValueCollection());

            var ukTimeZone = TimeZoneInfo.FindSystemTimeZoneById(Constants.UkTimeZone());
            var ukToday    = new DateTimeOffset(DateTimeOffset.UtcNow.Date, ukTimeZone.GetUtcOffset(DateTimeOffset.UtcNow.Date));

            Assert.Equal(ukToday, result.FromDate);
            Assert.Equal(ukToday.AddDays(366).AddSeconds(-1), result.UntilDate);
        }
        public void Today_filter_is_parsed_correctly_as_UK_date()
        {
            var parsedQueryString = HttpUtility.ParseQueryString("?format=tweet&today=true");
            var parser            = new MatchesRssQueryStringParser();

            var result = parser.ParseFilterFromQueryString(parsedQueryString);

            var ukTimeZone = TimeZoneInfo.FindSystemTimeZoneById(Constants.UkTimeZone());
            var ukToday    = new DateTimeOffset(DateTimeOffset.UtcNow.Date, ukTimeZone.GetUtcOffset(DateTimeOffset.UtcNow.Date));

            Assert.Equal(ukToday, result.FromDate);
            Assert.Equal(ukToday.AddDays(1).AddSeconds(-1), result.UntilDate);
        }
        public void PlayerType_filter_is_parsed_correctly(string queryString, PlayerType?expectedPlayerType)
        {
            var parsedQueryString = HttpUtility.ParseQueryString(queryString);
            var parser            = new MatchesRssQueryStringParser();

            var result = parser.ParseFilterFromQueryString(parsedQueryString);

            if (expectedPlayerType.HasValue)
            {
                Assert.Single(result.PlayerTypes);
                Assert.Equal(expectedPlayerType, result.PlayerTypes.First());
            }
            else
            {
                Assert.Empty(result.PlayerTypes);
            }
        }
        public void Date_filters_are_parsed_correctly_as_UK_dates(string queryString, int?fromYear, int?fromMonth, int?fromDate, int?fromOffsetHours, int?untilYear, int?untilMonth, int?untilDate, int?untilOffsetHours)
        {
            var parsedQueryString = HttpUtility.ParseQueryString(queryString);
            var parser            = new MatchesRssQueryStringParser();

            var result = parser.ParseFilterFromQueryString(parsedQueryString);

            if (fromYear.HasValue && fromMonth.HasValue && fromDate.HasValue && fromOffsetHours.HasValue)
            {
                Assert.Equal(new DateTimeOffset(fromYear.Value, fromMonth.Value, fromDate.Value, 0, 0, 0, TimeSpan.FromHours(fromOffsetHours.Value)), result.FromDate);
            }

            if (untilYear.HasValue && untilMonth.HasValue && untilDate.HasValue && untilOffsetHours.HasValue)
            {
                Assert.Equal(new DateTimeOffset(untilYear.Value, untilMonth.Value, untilDate.Value, 0, 0, 0, TimeSpan.FromHours(untilOffsetHours.Value)).AddDays(1).AddSeconds(-1), result.UntilDate);
            }
        }
        public void MatchType_filter_is_parsed_correctly(string queryString, MatchType?expectedMatchType)
        {
            var parsedQueryString = HttpUtility.ParseQueryString(queryString);
            var parser            = new MatchesRssQueryStringParser();

            var result = parser.ParseFilterFromQueryString(parsedQueryString);

            if (expectedMatchType.HasValue)
            {
                Assert.Single(result.MatchTypes);
                Assert.Equal(expectedMatchType, result.MatchTypes.First());
                Assert.True(result.IncludeMatches);
                Assert.False(result.IncludeTournaments);
                Assert.False(result.IncludeTournamentMatches);
            }
            else
            {
                Assert.Empty(result.MatchTypes);
                Assert.True(result.IncludeMatches);
                Assert.False(result.IncludeTournaments);
                Assert.False(result.IncludeTournamentMatches);
            }
        }