public async Task GetAsync() { var init = Substitute.For<IHttpInitializer>(); var messager = new FakeMessageHandler(new HttpResponseMessage()); init.HttpClient.Returns(new HttpClient(messager)); var rest = new RestClient(init); var config = new HttpConfiguration(new Uri("http://happy.ca/"), "route", HttpRequest.Get); var ads = await rest.GetAsync(config, response => new List<Ad>{new Ad{AdID = Int32.MaxValue}}); Assert.AreEqual(1, ads.Count(x=>x.AdID==Int32.MaxValue)); Assert.AreEqual("http://happy.ca/route", messager.RequestMessage.RequestUri.AbsoluteUri); Assert.AreEqual(HttpMethod.Get, messager.RequestMessage.Method); }
/// <summary> /// Looks up. /// </summary> /// <param name="key">The key.</param> /// <returns>Book.</returns> /// <exception cref="System.NotImplementedException"></exception> public async Task<Book> LookUpAsync(string key) { var config = new HttpConfiguration(new Uri(BaseUrl), string.Format("volumes?q=isbn:{0}", key), HttpRequest.Get); return await restClient.GetAsync(config, LoadBook); }
public void SetData() { var config = new HttpConfiguration(new Uri("http://happy.ca/"), "happy", HttpRequest.Put); var ex = Assert.Throws<ArgumentException>(()=>config.ValidateSet()); Assert.AreEqual("Data", ex.Message); }
public void Set() { var config = new HttpConfiguration(new Uri("http://happy.ca/"), "happy", HttpRequest.Put) {Data = "test"}; config.ValidateSet(); }
public void Get() { var config = new HttpConfiguration(new Uri("http://happy.ca/"), "happy", HttpRequest.Get); config.ValidateGet(); }
public void BaseUri() { var config = new HttpConfiguration(new Uri("http://happy.ca/"), "", HttpRequest.Get); var ex = Assert.Throws<ArgumentException>(()=>config.ValidateBase()); Assert.AreEqual("Route", ex.Message); }