private Task SendPut(string url, string content, UserCredentials userCredentials, int expectedCode) { var source = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously); _client.Put(url, content, "application/json", userCredentials, response => { if (response.HttpStatusCode == expectedCode) { source.SetResult(null); } else { source.SetException(new UserCommandFailedException( response.HttpStatusCode, string.Format("Server returned {0} ({1}) for PUT on {2}", response.HttpStatusCode, response.StatusDescription, url))); } }, source.SetException); return(source.Task); }
private Task SendPut(string url, string content, UserCredentials userCredentials, int expectedCode) { var source = new TaskCompletionSource <object>(); _client.Put(url, content, "application/json", userCredentials, TimeSpan.FromMilliseconds(5000), response => { if (response.HttpStatusCode == expectedCode) { source.SetResult(null); } else { source.SetException(new ProjectionCommandFailedException( string.Format("Server returned {0} ({1}) for PUT on {2}", response.HttpStatusCode, response.StatusDescription, url))); } }, source.SetException); return(source.Task); }
public void of_http_requests_routing() { const int iterations = 100000; IPublisher inputBus = new NoopPublisher(); var bus = InMemoryBus.CreateTest(); var queue = new QueuedHandlerThreadPool(bus, "Test", true, TimeSpan.FromMilliseconds(50)); var multiQueuedHandler = new MultiQueuedHandler(new IQueuedHandler[] { queue }, null); var providers = new HttpAuthenticationProvider[] { new AnonymousHttpAuthenticationProvider() }; var httpService = new HttpService(ServiceAccessibility.Public, inputBus, new TrieUriRouter(), multiQueuedHandler, false, "http://localhost:12345/"); HttpService.CreateAndSubscribePipeline(bus, providers); var fakeController = new FakeController(iterations, null); httpService.SetupController(fakeController); httpService.Handle(new SystemMessage.SystemInit()); var rnd = new Random(); var sw = Stopwatch.StartNew(); var httpClient = new HttpAsyncClient(); for (int i = 0; i < iterations; ++i) { var route = fakeController.BoundRoutes[rnd.Next(0, fakeController.BoundRoutes.Count)]; switch (route.Item2) { case HttpMethod.Get: httpClient.Get(route.Item1, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); }); break; case HttpMethod.Post: httpClient.Post(route.Item1, "abracadabra", ContentType.Json, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); }); break; case HttpMethod.Delete: httpClient.Delete(route.Item1, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); }); break; case HttpMethod.Put: httpClient.Put(route.Item1, "abracadabra", ContentType.Json, TimeSpan.FromMilliseconds(10000), x => { }, x => { throw new Exception(); }); break; default: throw new Exception(); } } fakeController.CountdownEvent.Wait(); sw.Stop(); Console.WriteLine("{0} request done in {1} ({2:0.00} per sec)", iterations, sw.Elapsed, 1000.0 * iterations / sw.ElapsedMilliseconds); httpService.Shutdown(); multiQueuedHandler.Stop(); }
private Task SendPut(string url, string content, int expectedCode) { var source = new TaskCompletionSource <object>(); _client.Put(url, content, ContentType.Json, response => { if (response.HttpStatusCode == expectedCode) { source.SetResult(null); } else { source.SetException(new ProjectionCommandFailedException( string.Format("Server returned : {0} ({1})", response.HttpStatusCode, response.StatusDescription))); } }, source.SetException); return(source.Task); }
public async void Put_valid_request_returns_response_not_cached() { // arrange var responseObj = _fixture.Create <RandomObject>(); var requestObj = _fixture.Create <RandomObject>(); _httpCachingService.Setup(x => x.CheckCache <RandomObject>(_baseAddress, _uri, _headers, null)) .Returns(Task.FromResult((RandomObject)null)); _httpService.Setup( x => x.CallHttpMethod <RandomObject, RandomObject>(_baseAddress, _uri, requestObj, _headers, HttpMethods.PUT)) .Returns(Task.FromResult(responseObj)); // act RandomObject response = await _sut.Put <RandomObject, RandomObject>(_baseAddress, _uri, requestObj, _headers); // assert response.PointlessProperty.Should().Be(responseObj.PointlessProperty); response.BackInTime.Should().Be(responseObj.BackInTime); }