public async Task RequestTiming(int millisecondsDelay) { // Arrange var command = new CheckHttpEndpoint( HttpMonitorCheckId.Create(), HttpMonitorId.Create(), new HttpRequest(HttpMethod.Get, _httpServer.BaseAddress)); _httpServer.Handler = async ctx => { await Task.Delay(millisecondsDelay); }; // Act var expectedStartTime = DateTime.UtcNow; var @event = await _executor.CheckHttpEndpointAsync(command); var expectedEndTime = DateTime.UtcNow; // Assert AssertDateTime.Equal(expectedStartTime, @event.RequestTiming.StartTime, TimeSpanComparer.DefaultTolerance); AssertDateTime.Equal(expectedEndTime, @event.RequestTiming.EndTime, TimeSpanComparer.DefaultTolerance); }
public async Task Test() { // Arrange (_, var entity) = await _client.PostAsync(new { Request = new { Url = new Uri(_httpServer.BaseAddress, "foo/bar?q=123"), Method = "GET" } }); string actualMethod = null; string actualPath = null; string actualQueryString = null; _httpServer.Handler = ctx => { actualMethod = ctx.Request.Method; actualPath = ctx.Request.Path.Value; actualQueryString = ctx.Request.QueryString.Value; return(Task.CompletedTask); }; // Act (var response, var testResult) = await _client.TestAsync(entity.Id); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(entity.Request.Method, actualMethod, StringComparer.InvariantCultureIgnoreCase); Assert.Equal(entity.Request.Url.AbsolutePath, actualPath); Assert.Equal(entity.Request.Url.Query, actualQueryString); var expectedResult = new HttpMonitorCheckedDto() { HttpMonitorId = entity.Id, Request = new HttpRequestDto() { Url = entity.Request.Url, Method = HttpMethod.Get.ToString() }, Response = new HttpResponseDto() { StatusCode = (int)HttpStatusCode.OK }, RequestTiming = new HttpRequestTimingDto() { StartTime = DateTime.UtcNow, EndTime = DateTime.UtcNow } }; Assert.Equal(expectedResult.HttpMonitorId, testResult.HttpMonitorId); Assert.Equal(expectedResult.Request, testResult.Request); Assert.Equal(expectedResult.Response, testResult.Response); AssertDateTime.Equal(expectedResult.RequestTiming.StartTime, testResult.RequestTiming.StartTime, TimeSpanComparer.DefaultTolerance); AssertDateTime.Equal(expectedResult.RequestTiming.EndTime, testResult.RequestTiming.EndTime, TimeSpanComparer.DefaultTolerance); }