public async Task Should_call_esrijson() { var httpContext = new DefaultHttpContext(); httpContext.Request.QueryString = new QueryString("?format=esriJSON"); var mediator = new Mock <IMediator>(); var response = new ApiResponseContainer <Graphic> { Result = new Graphic(new Point(2, 2), new Dictionary <string, object>()) }; mediator.Setup(x => x.Send(It.IsAny <EsriGraphic.Command>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(response)); var filter = new JsonOutputFormatResultFilter(mediator.Object); var contexts = CreateContext(httpContext); await filter.OnResultExecutionAsync(contexts.ExecutingContext, () => Task.FromResult(contexts.ExecutedContext)); var result = contexts.ExecutingContext.Result as ObjectResult; var result2 = contexts.ExecutedContext.Result as ObjectResult; result.Value.ShouldBeOfType <ApiResponseContainer <Graphic> >(); result2.Value.ShouldBeOfType <ApiResponseContainer <Graphic> >(); }
public async Task Should_call_geojson() { var httpContext = new DefaultHttpContext(); httpContext.Request.QueryString = new QueryString("?format=GeoJSON"); var mediator = new Mock <IMediator>(); var response = new ApiResponseContainer <Feature> { Result = new Feature(new GeoJSON.Net.Geometry.Point(new Position(1, 1))) }; mediator.Setup(x => x.Send(It.IsAny <GeoJsonFeature.Command>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(response)); var filter = new JsonOutputFormatResultFilter(mediator.Object); var contexts = CreateContext(httpContext); await filter.OnResultExecutionAsync(contexts.ExecutingContext, () => Task.FromResult(contexts.ExecutedContext)); var result = contexts.ExecutingContext.Result as ObjectResult; var result2 = contexts.ExecutedContext.Result as ObjectResult; result.Value.ShouldBeOfType <ApiResponseContainer <Feature> >(); result2.Value.ShouldBeOfType <ApiResponseContainer <Feature> >(); }
public async Task Should_be_ok_if_format_is_unknown() { var httpContext = new DefaultHttpContext(); httpContext.Request.QueryString = new QueryString("?format=someUnknownFormat"); var mediator = new Mock <IMediator>(); var filter = new JsonOutputFormatResultFilter(mediator.Object); var contexts = CreateContext(httpContext); await filter.OnResultExecutionAsync(contexts.ExecutingContext, () => Task.FromResult(contexts.ExecutedContext)); var result = contexts.ExecutingContext.Result as ObjectResult; var result2 = contexts.ExecutedContext.Result as ObjectResult; result.Value.ShouldBeOfType <ApiResponseContainer <GeocodeAddressApiResponse> >(); result2.Value.ShouldBeOfType <ApiResponseContainer <GeocodeAddressApiResponse> >(); }