public void UpdateFromHeader_DictionaryTest()
        {
            var status = new TwitterApiStatus();

            var header = new Dictionary <string, string>
            {
                ["X-Rate-Limit-Limit"]         = "150",
                ["X-Rate-Limit-Remaining"]     = "100",
                ["X-Rate-Limit-Reset"]         = "1356998400",
                ["X-MediaRateLimit-Limit"]     = "30",
                ["X-MediaRateLimit-Remaining"] = "20",
                ["X-MediaRateLimit-Reset"]     = "1357084800",
                ["X-Access-Level"]             = "read-write-directmessages",
            };

            Assert.Raises <TwitterApiStatus.AccessLimitUpdatedEventArgs>(
                x => status.AccessLimitUpdated += x,
                x => status.AccessLimitUpdated -= x,
                () => status.UpdateFromHeader(header, "/statuses/home_timeline")
                );

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];

            Assert.Equal(150, rateLimit.AccessLimitCount);
            Assert.Equal(100, rateLimit.AccessLimitRemain);
            Assert.Equal(new DateTimeUtc(2013, 1, 1, 0, 0, 0), rateLimit.AccessLimitResetDate);

            var mediaLimit = status.MediaUploadLimit;

            Assert.Equal(30, mediaLimit.AccessLimitCount);
            Assert.Equal(20, mediaLimit.AccessLimitRemain);
            Assert.Equal(new DateTimeUtc(2013, 1, 2, 0, 0, 0), mediaLimit.AccessLimitResetDate);

            Assert.Equal(TwitterApiAccessLevel.ReadWriteAndDirectMessage, status.AccessLevel);
        }
Beispiel #2
0
        public void UpdateFromApiTest2()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;

            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var apiResponse = new TwitterDataModel.RateLimitStatus
            {
                HourlyLimit        = 150,
                RemainingHits      = 100,
                ResetTime          = "Tue Jan 01 00:00:00 +0000 2013",
                ResetTimeInSeconds = 1356998400,
                Photos             = null,
            };

            status.UpdateFromApi(apiResponse);

            var rateLimit = status.AccessLimit;

            Assert.That(rateLimit.AccessLimitCount, Is.EqualTo(150));
            Assert.That(rateLimit.AccessLimitRemain, Is.EqualTo(100));
            Assert.That(rateLimit.AccessLimitResetDate, Is.EqualTo(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()));

            Assert.That(status.MediaUploadLimit, Is.Null);

            Assert.That(eventCalled, Is.True);
        }
        public void ResetTest()
        {
            var apiStatus = new TwitterApiStatus();

            apiStatus.AccessLimit["/statuses/home_timeline"] = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            apiStatus.MediaUploadLimit = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            apiStatus.AccessLevel = TwitterApiAccessLevel.ReadWriteAndDirectMessage;

            apiStatus.Reset();

            Assert.Null(apiStatus.AccessLimit["/statuses/home_timeline"]);
            Assert.Null(apiStatus.MediaUploadLimit);
            Assert.Equal(TwitterApiAccessLevel.Anonymous, apiStatus.AccessLevel);
        }
        public void ResetTest()
        {
            var apiStatus = new TwitterApiStatus();

            apiStatus.AccessLimit["/statuses/home_timeline"] = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            apiStatus.MediaUploadLimit = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            apiStatus.AccessLevel      = TwitterApiAccessLevel.ReadWriteAndDirectMessage;

            apiStatus.Reset();

            Assert.Null(apiStatus.AccessLimit["/statuses/home_timeline"]);
            Assert.Null(apiStatus.MediaUploadLimit);
            Assert.Equal(TwitterApiAccessLevel.Anonymous, apiStatus.AccessLevel);
        }
Beispiel #5
0
        public void ResetTest()
        {
            var apiStatus = new TwitterApiStatus();

            apiStatus.AccessLimit      = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            apiStatus.MediaUploadLimit = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            apiStatus.AccessLevel      = TwitterApiAccessLevel.ReadWriteAndDirectMessage;

            apiStatus.Reset();

            Assert.That(apiStatus.AccessLimit, Is.Null);
            Assert.That(apiStatus.MediaUploadLimit, Is.Null);
            Assert.That(apiStatus.AccessLevel, Is.EqualTo(TwitterApiAccessLevel.Anonymous));
        }
Beispiel #6
0
        public void UpdateFromApiTest3()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;

            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            Assert.That(() => status.UpdateFromApi(null), Throws.TypeOf <ArgumentNullException>());

            Assert.That(status.AccessLimit, Is.Null);
            Assert.That(status.MediaUploadLimit, Is.Null);

            Assert.That(eventCalled, Is.False);
        }
Beispiel #7
0
        public void AccessLimitUpdatedTest()
        {
            var apiStatus = new TwitterApiStatus();

            var eventCount = 0;

            apiStatus.AccessLimitUpdated += (s, e) => eventCount++;

            Assert.That(eventCount, Is.EqualTo(0));

            apiStatus.AccessLimit = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            Assert.That(eventCount, Is.EqualTo(1));

            apiStatus.Reset();
            Assert.That(eventCount, Is.EqualTo(2));
        }
        public void AccessLimitUpdatedTest()
        {
            var apiStatus = new TwitterApiStatus();

            Assert.Raises <TwitterApiStatus.AccessLimitUpdatedEventArgs>(
                x => apiStatus.AccessLimitUpdated += x,
                x => apiStatus.AccessLimitUpdated -= x,
                () => apiStatus.AccessLimit["/statuses/home_timeline"] = new ApiLimit(150, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0))
                );

            Assert.Raises <TwitterApiStatus.AccessLimitUpdatedEventArgs>(
                x => apiStatus.AccessLimitUpdated += x,
                x => apiStatus.AccessLimitUpdated -= x,
                () => apiStatus.Reset()
                );
        }
        public void AccessLimitUpdatedTest()
        {
            var apiStatus = new TwitterApiStatus();

            var eventCount = 0;

            apiStatus.AccessLimitUpdated += (s, e) => eventCount++;

            Assert.Equal(0, eventCount);

            apiStatus.AccessLimit["/statuses/home_timeline"] = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            Assert.Equal(1, eventCount);

            apiStatus.Reset();
            Assert.Equal(2, eventCount);
        }
        public void UpdateFromJsonTest2()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;

            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var json = "INVALID JSON";

            Assert.Throws <XmlException>(() => status.UpdateFromJson(json));

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];

            Assert.Null(rateLimit);

            Assert.False(eventCalled);
        }
        public void UpdateFromJsonTest()
        {
            var status = new TwitterApiStatus();

            var json = "{\"resources\":{\"statuses\":{\"/statuses/home_timeline\":{\"limit\":150,\"remaining\":100,\"reset\":1356998400}}}}";

            Assert.Raises <TwitterApiStatus.AccessLimitUpdatedEventArgs>(
                x => status.AccessLimitUpdated += x,
                x => status.AccessLimitUpdated -= x,
                () => status.UpdateFromJson(TwitterRateLimits.ParseJson(json))
                );

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];

            Assert.Equal(150, rateLimit.AccessLimitCount);
            Assert.Equal(100, rateLimit.AccessLimitRemain);
            Assert.Equal(new DateTimeUtc(2013, 1, 1, 0, 0, 0), rateLimit.AccessLimitResetDate);
        }
        public void UpdateFromJsonTest()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;

            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var json = "{\"resources\":{\"statuses\":{\"/statuses/home_timeline\":{\"limit\":150,\"remaining\":100,\"reset\":1356998400}}}}";

            status.UpdateFromJson(json);

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];

            Assert.Equal(150, rateLimit.AccessLimitCount);
            Assert.Equal(100, rateLimit.AccessLimitRemain);
            Assert.Equal(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(), rateLimit.AccessLimitResetDate);

            Assert.True(eventCalled);
        }
        public void UpdateFromHeader_HttpClientTest()
        {
            var status = new TwitterApiStatus();

            var response = new HttpResponseMessage
            {
                Headers =
                {
                    { "x-rate-limit-limit",         "150"                       },
                    { "x-rate-limit-remaining",     "100"                       },
                    { "x-rate-limit-reset",         "1356998400"                },
                    { "x-mediaratelimit-limit",     "30"                        },
                    { "x-mediaratelimit-remaining", "20"                        },
                    { "x-mediaratelimit-reset",     "1357084800"                },
                    { "x-access-level",             "read-write-directmessages" },
                },
            };

            Assert.Raises <TwitterApiStatus.AccessLimitUpdatedEventArgs>(
                x => status.AccessLimitUpdated += x,
                x => status.AccessLimitUpdated -= x,
                () => status.UpdateFromHeader(response.Headers, "/statuses/home_timeline")
                );

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];

            Assert.Equal(150, rateLimit.AccessLimitCount);
            Assert.Equal(100, rateLimit.AccessLimitRemain);
            Assert.Equal(new DateTimeUtc(2013, 1, 1, 0, 0, 0), rateLimit.AccessLimitResetDate);

            var mediaLimit = status.MediaUploadLimit;

            Assert.Equal(30, mediaLimit.AccessLimitCount);
            Assert.Equal(20, mediaLimit.AccessLimitRemain);
            Assert.Equal(new DateTimeUtc(2013, 1, 2, 0, 0, 0), mediaLimit.AccessLimitResetDate);

            Assert.Equal(TwitterApiAccessLevel.ReadWriteAndDirectMessage, status.AccessLevel);
        }
Beispiel #14
0
        public void UpdateFromHeader(IDictionary <string, string> header)
        {
            var rateLimit = TwitterApiStatus.ParseRateLimit(header);

            if (rateLimit != null)
            {
                this.AccessLimit = rateLimit;
            }

            var mediaLimit = TwitterApiStatus.ParseMediaRateLimit(header);

            if (mediaLimit != null)
            {
                this.MediaUploadLimit = mediaLimit;
            }

            var accessLevel = TwitterApiStatus.ParseAccessLevel(header);

            if (accessLevel.HasValue)
            {
                this.AccessLevel = accessLevel.Value;
            }
        }
Beispiel #15
0
        public void UpdateFromHeader(IDictionary <string, string> header, string endpointName)
        {
            var rateLimit = TwitterApiStatus.ParseRateLimit(header, "X-Rate-Limit-");

            if (rateLimit != null)
            {
                this.AccessLimit[endpointName] = rateLimit;
            }

            var mediaLimit = TwitterApiStatus.ParseRateLimit(header, "X-MediaRateLimit-");

            if (mediaLimit != null)
            {
                this.MediaUploadLimit = mediaLimit;
            }

            var accessLevel = TwitterApiStatus.ParseAccessLevel(header, "X-Access-Level");

            if (accessLevel.HasValue)
            {
                this.AccessLevel = accessLevel.Value;
            }
        }
Beispiel #16
0
        public void UpdateFromHeaderTest()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;

            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var header = new Dictionary <string, string>
            {
                { "X-RateLimit-Limit", "150" },
                { "X-RateLimit-Remaining", "100" },
                { "X-RateLimit-Reset", "1356998400" },
                { "X-MediaRateLimit-Limit", "30" },
                { "X-MediaRateLimit-Remaining", "20" },
                { "X-MediaRateLimit-Reset", "1357084800" },
                { "X-Access-Level", "read-write-directmessages" },
            };

            status.UpdateFromHeader(header);

            var rateLimit = status.AccessLimit;

            Assert.That(rateLimit.AccessLimitCount, Is.EqualTo(150));
            Assert.That(rateLimit.AccessLimitRemain, Is.EqualTo(100));
            Assert.That(rateLimit.AccessLimitResetDate, Is.EqualTo(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()));

            var mediaLimit = status.MediaUploadLimit;

            Assert.That(mediaLimit.AccessLimitCount, Is.EqualTo(30));
            Assert.That(mediaLimit.AccessLimitRemain, Is.EqualTo(20));
            Assert.That(mediaLimit.AccessLimitResetDate, Is.EqualTo(new DateTime(2013, 1, 2, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()));

            Assert.That(status.AccessLevel, Is.EqualTo(TwitterApiAccessLevel.ReadWriteAndDirectMessage));

            Assert.That(eventCalled, Is.True);
        }
        public void UpdateFromHeaderTest()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;

            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var header = new Dictionary <string, string>
            {
                { "X-Rate-Limit-Limit", "150" },
                { "X-Rate-Limit-Remaining", "100" },
                { "X-Rate-Limit-Reset", "1356998400" },
                { "X-MediaRateLimit-Limit", "30" },
                { "X-MediaRateLimit-Remaining", "20" },
                { "X-MediaRateLimit-Reset", "1357084800" },
                { "X-Access-Level", "read-write-directmessages" },
            };

            status.UpdateFromHeader(header, "/statuses/home_timeline");

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];

            Assert.Equal(150, rateLimit.AccessLimitCount);
            Assert.Equal(100, rateLimit.AccessLimitRemain);
            Assert.Equal(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(), rateLimit.AccessLimitResetDate);

            var mediaLimit = status.MediaUploadLimit;

            Assert.Equal(30, mediaLimit.AccessLimitCount);
            Assert.Equal(20, mediaLimit.AccessLimitRemain);
            Assert.Equal(new DateTime(2013, 1, 2, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(), mediaLimit.AccessLimitResetDate);

            Assert.Equal(TwitterApiAccessLevel.ReadWriteAndDirectMessage, status.AccessLevel);

            Assert.True(eventCalled);
        }
        public void AccessLimitUpdatedTest()
        {
            var apiStatus = new TwitterApiStatus();

            var eventCount = 0;
            apiStatus.AccessLimitUpdated += (s, e) => eventCount++;

            Assert.That(eventCount, Is.EqualTo(0));

            apiStatus.AccessLimit = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            Assert.That(eventCount, Is.EqualTo(1));

            apiStatus.Reset();
            Assert.That(eventCount, Is.EqualTo(2));
        }
Beispiel #19
0
 public EndpointLimits(TwitterApiStatus owner)
 {
     this.Owner = owner;
 }
 public EndpointLimits(TwitterApiStatus owner)
 {
     this.Owner = owner;
 }
        public void ParseRateLimitTest(IDictionary <string, string> header, ApiLimit expected)
        {
            var limit = TwitterApiStatus.ParseRateLimit(header, "X-RateLimit-");

            Assert.Equal(expected, limit);
        }
Beispiel #22
0
        public void ParseAccessLevelTest(IDictionary <string, string> header, TwitterApiAccessLevel?expect)
        {
            var accessLevel = TwitterApiStatus.ParseAccessLevel(header, "X-Access-Level");

            Assert.That(accessLevel, Is.EqualTo(expect));
        }
        public void UpdateFromApiTest3()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;
            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            Assert.That(() => status.UpdateFromApi(null), Throws.TypeOf<ArgumentNullException>());

            Assert.That(status.AccessLimit, Is.Null);
            Assert.That(status.MediaUploadLimit, Is.Null);

            Assert.That(eventCalled, Is.False);
        }
        public void UpdateFromJsonTest()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;
            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var json = "{\"resources\":{\"statuses\":{\"/statuses/home_timeline\":{\"limit\":150,\"remaining\":100,\"reset\":1356998400}}}}";
            status.UpdateFromJson(json);

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];
            Assert.That(rateLimit.AccessLimitCount, Is.EqualTo(150));
            Assert.That(rateLimit.AccessLimitRemain, Is.EqualTo(100));
            Assert.That(rateLimit.AccessLimitResetDate, Is.EqualTo(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()));

            Assert.That(eventCalled, Is.True);
        }
        public void UpdateFromJsonTest2()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;
            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var json = "INVALID JSON";
            Assert.That(() => status.UpdateFromJson(json), Throws.TypeOf<XmlException>());

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];
            Assert.That(rateLimit, Is.Null);

            Assert.That(eventCalled, Is.False);
        }
        public void ParseAccessLevelTest(IDictionary <string, string> header, TwitterApiAccessLevel?expected)
        {
            var accessLevel = TwitterApiStatus.ParseAccessLevel(header, "X-Access-Level");

            Assert.Equal(expected, accessLevel);
        }
Beispiel #27
0
        public void ParseRateLimitTest(IDictionary <string, string> header, ApiLimit expect)
        {
            var limit = TwitterApiStatus.ParseRateLimit(header, "X-RateLimit-");

            Assert.That(limit, Is.EqualTo(expect));
        }
        public void UpdateFromHeader_DictionaryTest()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;
            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var header = new Dictionary<string, string>
            {
                ["X-Rate-Limit-Limit"] = "150",
                ["X-Rate-Limit-Remaining"] = "100",
                ["X-Rate-Limit-Reset"] = "1356998400",
                ["X-MediaRateLimit-Limit"] = "30",
                ["X-MediaRateLimit-Remaining"] = "20",
                ["X-MediaRateLimit-Reset"] = "1357084800",
                ["X-Access-Level"] = "read-write-directmessages",
            };

            status.UpdateFromHeader(header, "/statuses/home_timeline");

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];
            Assert.Equal(150, rateLimit.AccessLimitCount);
            Assert.Equal(100, rateLimit.AccessLimitRemain);
            Assert.Equal(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(), rateLimit.AccessLimitResetDate);

            var mediaLimit = status.MediaUploadLimit;
            Assert.Equal(30, mediaLimit.AccessLimitCount);
            Assert.Equal(20, mediaLimit.AccessLimitRemain);
            Assert.Equal(new DateTime(2013, 1, 2, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(), mediaLimit.AccessLimitResetDate);

            Assert.Equal(TwitterApiAccessLevel.ReadWriteAndDirectMessage, status.AccessLevel);

            Assert.True(eventCalled);
        }
        public async Task GetAsync_UpdateRateLimitTest()
        {
            using (var mockHandler = new HttpMessageHandlerMock())
            using (var http = new HttpClient(mockHandler))
            using (var apiConnection = new TwitterApiConnection("", ""))
            {
                apiConnection.http = http;

                mockHandler.Enqueue(x =>
                {
                    Assert.Equal(HttpMethod.Get, x.Method);
                    Assert.Equal("https://api.twitter.com/1.1/hoge/tetete.json",
                        x.RequestUri.GetLeftPart(UriPartial.Path));

                    return new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Headers =
                        {
                            { "X-Rate-Limit-Limit", "150" },
                            { "X-Rate-Limit-Remaining", "100" },
                            { "X-Rate-Limit-Reset", "1356998400" },
                            { "X-Access-Level", "read-write-directmessages" },
                        },
                        Content = new StringContent("\"hogehoge\""),
                    };
                });

                var apiStatus = new TwitterApiStatus();
                MyCommon.TwitterApiInfo = apiStatus;

                var endpoint = new Uri("hoge/tetete.json", UriKind.Relative);

                await apiConnection.GetAsync<string>(endpoint, null, endpointName: "/hoge/tetete")
                    .ConfigureAwait(false);

                Assert.Equal(apiStatus.AccessLevel, TwitterApiAccessLevel.ReadWriteAndDirectMessage);
                Assert.Equal(apiStatus.AccessLimit["/hoge/tetete"], new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()));

                Assert.Equal(0, mockHandler.QueueCount);
            }
        }
        public void ResetTest()
        {
            var apiStatus = new TwitterApiStatus();

            apiStatus.AccessLimit = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            apiStatus.MediaUploadLimit = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            apiStatus.AccessLevel = TwitterApiAccessLevel.ReadWriteAndDirectMessage;

            apiStatus.Reset();

            Assert.That(apiStatus.AccessLimit, Is.Null);
            Assert.That(apiStatus.MediaUploadLimit, Is.Null);
            Assert.That(apiStatus.AccessLevel, Is.EqualTo(TwitterApiAccessLevel.Anonymous));
        }
        public void UpdateFromApiTest2()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;
            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var apiResponse = new TwitterDataModel.RateLimitStatus
            {
                HourlyLimit = 150,
                RemainingHits = 100,
                ResetTime = "Tue Jan 01 00:00:00 +0000 2013",
                ResetTimeInSeconds = 1356998400,
                Photos = null,
            };

            status.UpdateFromApi(apiResponse);

            var rateLimit = status.AccessLimit;
            Assert.That(rateLimit.AccessLimitCount, Is.EqualTo(150));
            Assert.That(rateLimit.AccessLimitRemain, Is.EqualTo(100));
            Assert.That(rateLimit.AccessLimitResetDate, Is.EqualTo(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()));

            Assert.That(status.MediaUploadLimit, Is.Null);

            Assert.That(eventCalled, Is.True);
        }
        public void AccessLimitUpdatedTest()
        {
            var apiStatus = new TwitterApiStatus();

            var eventCount = 0;
            apiStatus.AccessLimitUpdated += (s, e) => eventCount++;

            Assert.Equal(0, eventCount);

            apiStatus.AccessLimit["/statuses/home_timeline"] = new ApiLimit(150, 100, new DateTime(2013, 1, 1, 0, 0, 0));
            Assert.Equal(1, eventCount);

            apiStatus.Reset();
            Assert.Equal(2, eventCount);
        }
        public void UpdateFromHeaderTest()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;
            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var header = new Dictionary<string, string>
            {
                {"X-RateLimit-Limit", "150"},
                {"X-RateLimit-Remaining", "100"},
                {"X-RateLimit-Reset", "1356998400"},
                {"X-MediaRateLimit-Limit", "30"},
                {"X-MediaRateLimit-Remaining", "20"},
                {"X-MediaRateLimit-Reset", "1357084800"},
                {"X-Access-Level", "read-write-directmessages"},
            };

            status.UpdateFromHeader(header);

            var rateLimit = status.AccessLimit;
            Assert.That(rateLimit.AccessLimitCount, Is.EqualTo(150));
            Assert.That(rateLimit.AccessLimitRemain, Is.EqualTo(100));
            Assert.That(rateLimit.AccessLimitResetDate, Is.EqualTo(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()));

            var mediaLimit = status.MediaUploadLimit;
            Assert.That(mediaLimit.AccessLimitCount, Is.EqualTo(30));
            Assert.That(mediaLimit.AccessLimitRemain, Is.EqualTo(20));
            Assert.That(mediaLimit.AccessLimitResetDate, Is.EqualTo(new DateTime(2013, 1, 2, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()));

            Assert.That(status.AccessLevel, Is.EqualTo(TwitterApiAccessLevel.ReadWriteAndDirectMessage));

            Assert.That(eventCalled, Is.True);
        }
        public void UpdateFromHeader_HttpClientTest()
        {
            var status = new TwitterApiStatus();

            var eventCalled = false;
            status.AccessLimitUpdated += (s, e) => eventCalled = true;

            var response = new HttpResponseMessage
            {
                Headers =
                {
                    { "x-rate-limit-limit", "150" },
                    { "x-rate-limit-remaining", "100" },
                    { "x-rate-limit-reset", "1356998400" },
                    { "x-mediaratelimit-limit", "30" },
                    { "x-mediaratelimit-remaining", "20" },
                    { "x-mediaratelimit-reset", "1357084800" },
                    { "x-access-level", "read-write-directmessages" },
                },
            };

            status.UpdateFromHeader(response.Headers, "/statuses/home_timeline");

            var rateLimit = status.AccessLimit["/statuses/home_timeline"];
            Assert.Equal(150, rateLimit.AccessLimitCount);
            Assert.Equal(100, rateLimit.AccessLimitRemain);
            Assert.Equal(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(), rateLimit.AccessLimitResetDate);

            var mediaLimit = status.MediaUploadLimit;
            Assert.Equal(30, mediaLimit.AccessLimitCount);
            Assert.Equal(20, mediaLimit.AccessLimitRemain);
            Assert.Equal(new DateTime(2013, 1, 2, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(), mediaLimit.AccessLimitResetDate);

            Assert.Equal(TwitterApiAccessLevel.ReadWriteAndDirectMessage, status.AccessLevel);

            Assert.True(eventCalled);
        }