public async Task WhenGetJson_AndContentContainsGarbage_ThrowsException() { var expected = "dfsgsdf%#@$%^&*()"; var stubHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expected) }); var http = new HttpWrapper("http://foo.com/", new TestLogger(), new Envelope(new TextMessage(CreateTestUser(), "test")), stubHandler); Assert.Throws <AggregateException>(() => http.GetJson().Result); }
public async Task WhenGetJsonIsCalled_ResponseContentIsDeserialized() { var expectedString = JsonConvert.SerializeObject(new { Id = 4, Foo = "Foo", Bar = "Bar", Date = DateTime.Now }); var expected = JsonConvert.DeserializeObject(expectedString); var stubHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expectedString) }); var http = new HttpWrapper("http://foo.com/", new TestLogger(), new Envelope(new TextMessage(CreateTestUser(), "test")), stubHandler); var actual = await http.GetJson(); Assert.True(new JTokenEqualityComparer().Equals((JToken)expected, (JToken)actual)); }
public async Task WhenGetJsonWithCallbackReturnsErrorHttpStatusCode_CodeIsAccessibleViaResponseParameter() { var expectedString = JsonConvert.SerializeObject(new { Id = 4, Foo = "Foo", Bar = "Bar", Date = DateTime.Now }); var expected = JsonConvert.DeserializeObject(expectedString); var stubHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(expectedString) }); var http = new HttpWrapper("http://foo.com/", new TestLogger(), new Envelope(new TextMessage(CreateTestUser(), "test")), stubHandler); var callback = false; await http.GetJson((err, res, body) => { callback = true; Assert.Equal(HttpStatusCode.NotFound, res.StatusCode); }); Assert.True(callback); }
public async Task WhenGetJsonWithCallback_AndContentContainsGarbage_ThrowsException() { var expected = "dfsgsdf%#@$%^&*()"; var stubHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expected) }); var http = new HttpWrapper("http://foo.com/", new TestLogger(), new Envelope(new TextMessage(CreateTestUser(), "test")), stubHandler); var callback = false; await http.GetJson((err, res, body) => { callback = true; Assert.NotNull(err); Assert.IsType <JsonReaderException>(err); }); Assert.True(callback); }
public async Task WhenGetJsonWithCallbackReturnsErrorHttpStatusCode_CodeIsAccessibleViaResponseParameter() { var expectedString = JsonConvert.SerializeObject(new { Id = 4, Foo = "Foo", Bar = "Bar", Date = DateTime.Now }); var expected = JsonConvert.DeserializeObject(expectedString); var stubHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(expectedString) }); var http = new HttpWrapper("http://foo.com/", new TestLogger(), new Envelope(new TextMessage(CreateTestUser(), "test", "id")), stubHandler); var callback = false; await http.GetJson((err, res, body) => { callback = true; Assert.AreEqual(HttpStatusCode.NotFound, res.StatusCode); }); Assert.IsTrue(callback); }
public async Task WhenGetJsonIsCalled_ResponseContentIsDeserialized() { var expectedString = JsonConvert.SerializeObject(new {Id=4, Foo = "Foo", Bar = "Bar", Date = DateTime.Now}); var expected = JsonConvert.DeserializeObject(expectedString); var stubHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expectedString) }); var http = new HttpWrapper("http://foo.com/", new TestLogger(), new Envelope(new TextMessage(CreateTestUser(), "test", "id")), stubHandler); var actual = await http.GetJson(); Assert.IsTrue(new JTokenEqualityComparer().Equals((JToken)expected, (JToken)actual)); }
public async Task WhenGetJsonWithCallback_AndContentContainsGarbage_ThrowsException() { var expected = "dfsgsdf%#@$%^&*()"; var stubHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expected) }); var http = new HttpWrapper("http://foo.com/", new TestLogger(), new Envelope(new TextMessage(CreateTestUser(), "test", "id")), stubHandler); var callback = false; await http.GetJson((err, res, body) => { callback = true; Assert.IsNotNull(err); Assert.IsInstanceOfType(err, typeof(Exception)); }); Assert.IsTrue(callback); }
public async Task WhenGetJson_AndContentContainsGarbage_ThrowsException() { var expected = "dfsgsdf%#@$%^&*()"; var stubHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expected) }); var http = new HttpWrapper("http://foo.com/", new TestLogger(), new Envelope(new TextMessage(CreateTestUser(), "test", "id")), stubHandler); await http.GetJson(); Assert.Fail("Should have thrown"); }