public async Task ShouldOAuthRequest() { await FHClient.Init(); //given ServiceFinder.RegisterType<IOAuthClientHandlerService, MockOAuthClient>(); var json = JObject.Parse(@"{ ""hosts"": {""host"": ""HOST""} }"); var config = new FHConfig(new MockDeviceService()); var props = new CloudProps(json, config); var authRequest = new FHAuthRequest(props); authRequest.SetAuthUser("gmail", "user", "password"); var mockHttpCLient = new MockHttpClient {Content = "{\"status\": \"ok\", \"url\": \"http://oauthurl.url\"}"}; FHHttpClientFactory.Get = () => mockHttpCLient; //when var response = await authRequest.ExecAsync(); //then Assert.IsNotNull(response); var responseParams = response.GetResponseAsDictionary(); Assert.IsNotNull(responseParams); Assert.AreEqual("token", responseParams["sessionToken"]); }
public async Task ShouldPerformGet() { //given await FHClient.Init(); var mock = new MockHttpClient(); FHHttpClientFactory.Get = () => mock; const string method = "GET"; //when await FHHttpClient.SendAsync(new Uri("http://localhost/test"), method, null, JObject.Parse("{'key-data': 'value'}"), TimeSpan.FromSeconds(20)); //then Assert.IsNotNull(mock.Request); Assert.AreEqual("http://localhost/test?key-data=\"value\"", mock.Request.RequestUri.ToString()); }
public async Task ShouldSendAsync() { //given await FHClient.Init(); var mock = new MockHttpClient(); FHHttpClientFactory.Get = () => mock; const string method = "POST"; //when await FHHttpClient.SendAsync(new Uri("http://localhost/test"), method, new Dictionary<string, string>() {{"key", "value"}}, "request-data", TimeSpan.FromSeconds(20)); //then Assert.IsNotNull(mock.Request); Assert.AreEqual(method, mock.Request.Method.Method); Assert.IsTrue(mock.Request.Headers.Contains("key")); Assert.AreEqual("\"request-data\"", await mock.Request.Content.ReadAsStringAsync()); Assert.AreEqual(20, mock.Timeout.Seconds); }