コード例 #1
0
ファイル: RestClientTests.cs プロジェクト: TianyuanC/dals
        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);
        }
コード例 #2
0
ファイル: GoogleApiClient.cs プロジェクト: TianyuanC/IsbnApi
 /// <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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 public void Set()
 {
     var config = new HttpConfiguration(new Uri("http://happy.ca/"), "happy", HttpRequest.Put)
         {Data = "test"};
     config.ValidateSet();
 }
コード例 #5
0
 public void Get()
 {
     var config = new HttpConfiguration(new Uri("http://happy.ca/"), "happy", HttpRequest.Get);
     config.ValidateGet();
 }
コード例 #6
0
 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);
 }