Inheritance: IThumbnailService
        public void ParseInLocation_PlanetTest()
        {
            var json      = @"{
  ""meta"": { ""code"": 200 },
  ""response"": {
    ""checkin"": {
      ""id"": ""xxxxxxxxx"",
      ""type"": ""checkin"",
      ""venue"": {
        ""id"": ""5069d8bdc640385aa7711fe4"",
        ""name"": ""Gale Crater"",
        ""location"": {
          ""planet"": ""mars"",
          ""lat"": 34.201694,
          ""lng"": -118.17166
        }
      }
    }
  }
}";
            var jsonBytes = Encoding.UTF8.GetBytes(json);
            var location  = FoursquareCheckin.ParseIntoLocation(jsonBytes);

            // 地球以外の位置にあるベニューに対しては null を返す
            Assert.Null(location);
        }
        public void ParseInLocation_CultureTest()
        {
            var json        = @"{
  ""meta"": { ""code"": 200 },
  ""response"": {
    ""checkin"": {
      ""id"": ""xxxxxxxxx"",
      ""type"": ""checkin"",
      ""venue"": {
        ""id"": ""4b73dedcf964a5206bbe2de3"",
        ""name"": ""高松駅 (Takamatsu Sta.)"",
        ""location"": {
          ""lat"": 34.35067978344854,
          ""lng"": 134.04693603515625
        }
      }
    }
  }
}";
            var origCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");

            var jsonBytes = Encoding.UTF8.GetBytes(json);
            var location  = FoursquareCheckin.ParseIntoLocation(jsonBytes);

            Thread.CurrentThread.CurrentCulture = origCulture;

            Assert.NotNull(location);
            Assert.Equal(34.35067978344854, location.Latitude);
            Assert.Equal(134.04693603515625, location.Longitude);
        }
        public async Task GetThumbnailInfoAsync_GeoLocatedTweetTest()
        {
            var handler = new HttpMessageHandlerMock();

            using (var http = new HttpClient(handler))
            {
                var service = new FoursquareCheckin(http);

                handler.Enqueue(x =>
                {
                    // このリクエストは実行されないはず
                    Assert.True(false);
                    return(new HttpResponseMessage(HttpStatusCode.NotFound));
                });

                // 既にジオタグが付いているツイートに対しては何もしない
                var post = new PostClass
                {
                    PostGeo = new PostClass.StatusGeo(134.04693603515625, 34.35067978344854),
                };

                await service.GetThumbnailInfoAsync(
                    "https://www.swarmapp.com/c/xxxxxxxx",
                    post, CancellationToken.None);

                Assert.Equal(1, handler.QueueCount);
            }
        }
        public void ParseInLocation_VenueNullTest()
        {
            var json      = @"{
  ""meta"": { ""code"": 200 },
  ""response"": {
    ""checkin"": {
      ""id"": ""xxxxxxxxx"",
      ""type"": ""checkin"",
      ""venue"": null
    }
  }
}";
            var jsonBytes = Encoding.UTF8.GetBytes(json);
            var location  = FoursquareCheckin.ParseIntoLocation(jsonBytes);

            // ベニュー情報が得られなかった場合は null を返す
            Assert.Null(location);
        }
        public async Task GetThumbnailInfoAsync_RequestWithSignatureTest()
        {
            var handler = new HttpMessageHandlerMock();

            using (var http = new HttpClient(handler))
            {
                var service = new FoursquareCheckin(http);

                handler.Enqueue(x =>
                {
                    Assert.Equal(HttpMethod.Get, x.Method);
                    Assert.Equal("https://api.foursquare.com/v2/checkins/xxxxxxxx",
                                 x.RequestUri.GetLeftPart(UriPartial.Path));

                    var query = HttpUtility.ParseQueryString(x.RequestUri.Query);

                    Assert.Equal(ApplicationSettings.FoursquareClientId, query["client_id"]);
                    Assert.Equal(ApplicationSettings.FoursquareClientSecret, query["client_secret"]);
                    Assert.NotNull(query["v"]);
                    Assert.Equal("aaaaaaa", query["signature"]);

                    // リクエストに対するテストなのでレスポンスは適当に返す
                    return(new HttpResponseMessage(HttpStatusCode.NotFound));
                });

                var post = new PostClass
                {
                    PostGeo = new PostClass.StatusGeo {
                    },
                };

                var thumb = await service.GetThumbnailInfoAsync(
                    "https://foursquare.com/hogehoge/checkin/xxxxxxxx?s=aaaaaaa",
                    post, CancellationToken.None);

                Assert.Equal(0, handler.QueueCount);
            }
        }
        public async Task GetThumbnailInfoAsync_RequestWithSignatureTest()
        {
            var handler = new HttpMessageHandlerMock();
            using (var http = new HttpClient(handler))
            {
                var service = new FoursquareCheckin(http);

                handler.Enqueue(x =>
                {
                    Assert.Equal(HttpMethod.Get, x.Method);
                    Assert.Equal("https://api.foursquare.com/v2/checkins/xxxxxxxx",
                        x.RequestUri.GetLeftPart(UriPartial.Path));

                    var query = HttpUtility.ParseQueryString(x.RequestUri.Query);

                    Assert.Equal(ApplicationSettings.FoursquareClientId, query["client_id"]);
                    Assert.Equal(ApplicationSettings.FoursquareClientSecret, query["client_secret"]);
                    Assert.NotNull(query["v"]);
                    Assert.Equal("aaaaaaa", query["signature"]);

                    // リクエストに対するテストなのでレスポンスは適当に返す
                    return new HttpResponseMessage(HttpStatusCode.NotFound);
                });

                var post = new PostClass
                {
                    PostGeo = new PostClass.StatusGeo { },
                };

                var thumb = await service.GetThumbnailInfoAsync(
                    "https://foursquare.com/hogehoge/checkin/xxxxxxxx?s=aaaaaaa",
                    post, CancellationToken.None);

                Assert.Equal(0, handler.QueueCount);
            }
        }
        public async Task GetThumbnailInfoAsync_GeoLocatedTweetTest()
        {
            var handler = new HttpMessageHandlerMock();
            using (var http = new HttpClient(handler))
            {
                var service = new FoursquareCheckin(http);

                handler.Enqueue(x =>
                {
                    // このリクエストは実行されないはず
                    Assert.True(false);
                    return new HttpResponseMessage(HttpStatusCode.NotFound);
                });

                // 既にジオタグが付いているツイートに対しては何もしない
                var post = new PostClass
                {
                    PostGeo = new PostClass.StatusGeo
                    {
                        Lat = 34.35067978344854,
                        Lng = 134.04693603515625,
                    },
                };

                var thumb = await service.GetThumbnailInfoAsync(
                    "https://foursquare.com/hogehoge/checkin/xxxxxxxx?s=aaaaaaa",
                    post, CancellationToken.None);

                Assert.Equal(1, handler.QueueCount);
            }
        }