public void InvalidMethodVersion_RequestFails()
        {
            var response = DotaApiClient.GetTournamentInfoAsync(version: "v1.3")
                           .Result;

            SleepAfterSendingRequest();

            AssertRequestFailed(response);
            Assert.Null(response.Contents);
        }
        public void MinMaxTierParamsClash_ThrowsArgumentException()
        {
            var response = DotaApiClient.GetTournamentInfoAsync(minTier: 6)
                           .Result;

            SleepAfterSendingRequest();

            AssertRequestFailed(response);
            Assert.Null(response.Contents);
            Assert.True(response.ThrownException is ArgumentException);
        }
        public void MinTierDefined_ReturnsTournamentsAboveOrAtMinTier(uint minTier)
        {
            var response = DotaApiClient.GetTournamentInfoAsync(timestamp: 1489402851, minTier: minTier)
                           .Result;

            AssertRequestWasSuccessful(response);
            Assert.NotNull(response.Contents);
            Assert.NotEmpty(response.Contents);
            Assert.All(response.Contents, tournament => {
                Assert.True(tournament.Tier >= minTier);
            });
        }
        public void TimestampDefined_ReturnsTournamentsFromProvidedTimestamp(long timestamp)
        {
            var response = DotaApiClient.GetTournamentInfoAsync(timestamp)
                           .Result;

            SleepAfterSendingRequest();

            AssertRequestWasSuccessful(response);
            Assert.NotNull(response.Contents);
            Assert.NotEmpty(response.Contents);
            Assert.All(response.Contents, tournament => {
                Assert.NotNull(tournament);
                Assert.True(tournament.StartTimestamp > (ulong)timestamp);
            });
        }
        public void DefaultParameter_ReturnsTournamentInfoFromCurrentDate()
        {
            var response = DotaApiClient.GetTournamentInfoAsync()
                           .Result;

            SleepAfterSendingRequest();

            AssertRequestWasSuccessful(response);
            Assert.NotNull(response);
            Assert.NotEmpty(response.Contents);
            Assert.All(response.Contents, tournament => {
                Assert.NotNull(tournament);
                Assert.True(tournament.StartTimestamp
                            > (ulong)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
            });
        }
        public void DateDefined_ReturnsTournamentsFromProvidedDate(long timestamp)
        {
            // convert compile time argument to Datetime object
            DateTime date = new DateTime(1970, 1, 1) + TimeSpan.FromSeconds(timestamp);

            var response = DotaApiClient.GetTournamentInfoAsync(date)
                           .Result;

            SleepAfterSendingRequest();

            AssertRequestWasSuccessful(response);
            Assert.NotEmpty(response.Contents);
            Assert.All(response.Contents, tournament => {
                Assert.NotNull(tournament);
                Assert.True(tournament.StartTimestamp > (ulong)timestamp);
            });
        }
        public async Task MethodGotCancelled_RequestFails()
        {
            CancellationTokenSource source = new CancellationTokenSource();

            // Start task to be cancelled
            var task = Task.Run(async() =>
            {
                return(await DotaApiClient.GetTournamentInfoAsync(cToken: source.Token));
            });

            // Cancel method
            source.Cancel();

            var response = await task;

            SleepAfterSendingRequest();

            AssertRequestWasCancelled(response);
            Assert.Null(response.Contents);
        }