public async Task SubscribeAsync_CreatesGeoSubscription() { // Arrange Initialize(TestId); HttpResponseMessage response = new HttpResponseMessage(); response.Content = new StringContent("{ \"meta\": { \"code\": 200 }, \"data\": { \"id\": \"1\", \"type\": \"subscribe\", \"object\": \"geography\", \"object_id\": \"12345\", \"aspect\": \"media\", \"callback_url\": \"" + TestCallback + "\" } }", Encoding.UTF8, "application/json"); _handlerMock.Handler = async(req, counter) => { MultipartFormDataContent content = await ValidateCoreSubscriptionRequest(req); await ValidateSubscriptionContent(content, 0, "object", "geography"); await ValidateSubscriptionContent(content, 1, "aspect", "media"); await ValidateSubscriptionContent(content, 2, "lat", "1.2345"); await ValidateSubscriptionContent(content, 3, "lng", "2.2345"); await ValidateSubscriptionContent(content, 4, "radius", "1000"); return(response); }; // Act InstagramSubscription actual = await _client.SubscribeAsync(TestId, _callback, 1.2345, 2.2345, 1000); // Assert Assert.Equal("1", actual.Id); Assert.Equal("geography", actual.Object); Assert.Equal(TestCallback, actual.Callback.AbsoluteUri); }
public InstagramWebHookClientExtensionsTests() { _config = new HttpConfiguration(); _helperMock = new Mock<UrlHelper>(); _clientMock = new Mock<InstagramWebHookClient>(_config); _callback = new Uri(Link); _sub = new InstagramSubscription(); }
private async Task <InstagramSubscription> CreateSubscription(string id, Uri callback, IDictionary <string, object> parameters) { if (!callback.IsAbsoluteUri) { string msg = string.Format(CultureInfo.CurrentCulture, InstagramReceiverResources.Client_NotAbsoluteCallback, "https://<host>/api/webhooks/incoming/instagram"); throw new ArgumentException(msg, "receiver"); } if (!callback.IsHttps()) { string msg = string.Format(CultureInfo.CurrentCulture, InstagramReceiverResources.Client_NoHttps, Uri.UriSchemeHttps); throw new InvalidOperationException(msg); } // Build up subscription request body MultipartFormDataContent content = new MultipartFormDataContent(); // Add default properties Tuple <string, string> clientInfo = await GetClientConfig(id); parameters["client_id"] = clientInfo.Item1; parameters["client_secret"] = clientInfo.Item2; parameters["callback_url"] = callback.AbsoluteUri; // Add subscription specific properties foreach (KeyValuePair <string, object> parameter in parameters) { StringContent p = new StringContent(parameter.Value.ToString()); p.Headers.ContentType = null; content.Add(p, parameter.Key); } using (HttpResponseMessage response = await _httpClient.PostAsync(_subscriptionAddress, content)) { if (!response.IsSuccessStatusCode) { string errorMessage = await GetErrorContent(response); string msg = string.Format(CultureInfo.CurrentCulture, InstagramReceiverResources.Client_SubscribeFailure, response.StatusCode, errorMessage); throw new InvalidOperationException(msg); } JObject subscriptionData = await response.Content.ReadAsAsync <JObject>(); InstagramSubscription subs = subscriptionData.Value <JObject>(DataKey).ToObject <InstagramSubscription>(); return(subs); } }
public void InstagramSubscription_Roundtrips() { // Arrange JObject data = EmbeddedResource.ReadAsJObject("Microsoft.AspNet.WebHooks.Messages.SubscriptionMessage.json"); InstagramSubscription expectedSubscription = new InstagramSubscription { Id = "19985884", Object = "tag", ObjectId = "mytag", Callback = new Uri("http://requestb.in/18jwdvk1"), }; // Act InstagramSubscription actualPost = data.ToObject<InstagramSubscription>(); // Assert string expectedJson = JsonConvert.SerializeObject(expectedSubscription); string actualJson = JsonConvert.SerializeObject(actualPost); Assert.Equal(expectedJson, actualJson); }
public void InstagramSubscription_Roundtrips() { // Arrange JObject data = EmbeddedResource.ReadAsJObject("Microsoft.AspNet.WebHooks.Messages.SubscriptionMessage.json"); InstagramSubscription expectedSubscription = new InstagramSubscription { Id = "19985884", Object = "tag", ObjectId = "mytag", Callback = new Uri("http://requestb.in/18jwdvk1"), }; // Act InstagramSubscription actualPost = data.ToObject <InstagramSubscription>(); // Assert string expectedJson = JsonConvert.SerializeObject(expectedSubscription); string actualJson = JsonConvert.SerializeObject(actualPost); Assert.Equal(expectedJson, actualJson); }