private void ValidateGetWeatherForecastsResponse(GetWeatherForecastsResponse aGetWeatherForecastsResponse) { aGetWeatherForecastsResponse.RequestId.ShouldBe(GetWeatherForecastsRequest.Id); aGetWeatherForecastsResponse.RequestId.Should().Be(GetWeatherForecastsRequest.Id); aGetWeatherForecastsResponse.WeatherForecasts.Count.ShouldBe(GetWeatherForecastsRequest.Days); aGetWeatherForecastsResponse.WeatherForecasts.Count.Should().Be(GetWeatherForecastsRequest.Days); }
public async Task _10WeatherForecasts_Given_10DaysRequested() { GetWeatherForecastsResponse getWeatherForecastsResponse = await GetJsonAsync <GetWeatherForecastsResponse>(GetWeatherForecastsRequest.GetRoute()); ValidateGetWeatherForecastsResponse(getWeatherForecastsResponse); }
public async Task _10WeatherForecasts_Given_10DaysRequested() { GetWeatherForecastsResponse getWeatherForecastsResponse = await TimeWarpBlazorServerApplication.GetResponse <GetWeatherForecastsResponse>(GetWeatherForecastsRequest); ValidateGetWeatherForecastsResponse(getWeatherForecastsResponse); }
public override async Task <WeatherForecastsState> Handle ( FetchWeatherForecastsAction aFetchWeatherForecastsRequest, CancellationToken aCancellationToken ) { var getWeatherForecastsRequest = new GetWeatherForecastsRequest { Days = 10 }; using HttpResponseMessage httpResponseMessage = await HttpClient.GetAsync ( $"{GetWeatherForecastsRequest.Route}?days={getWeatherForecastsRequest.Days}" ); string content = await httpResponseMessage.Content.ReadAsStringAsync(); GetWeatherForecastsResponse getWeatherForecastsResponse = JsonSerializer.Parse <GetWeatherForecastsResponse>(content, JsonSerializerOptions); List <WeatherForecastDto> weatherForecasts = getWeatherForecastsResponse.WeatherForecasts; WeatherForecastsState._WeatherForecasts = weatherForecasts; return(WeatherForecastsState); }
public override async Task <GetWeatherForecastsResponse> GetWeatherForecasts(Empty request, ServerCallContext context) { var weatherForecastDtos = await _mediator.Send(new GetWeatherForecastsQuery()); var response = new GetWeatherForecastsResponse(); response.WeatherForecastDtos.AddRange(weatherForecastDtos); return(response); }
public async Task ShouldGetAllWeatherForecasts() { // Arrange var getWeatherForecastsRequest = new GetWeatherForecastsRequest(); //Act GetWeatherForecastsResponse getWeatherForecastsResponse = await Mediator.Send(getWeatherForecastsRequest); //Assert getWeatherForecastsResponse.WeatherForecasts.Count.ShouldBe(5); }
public override async Task <WeatherForecastsState> Handle( FetchWeatherForecastsRequest aFetchWeatherForecastsRequest, CancellationToken aCancellationToken) { GetWeatherForecastsResponse getWeatherForecastsResponse = await HttpClient.GetJsonAsync <GetWeatherForecastsResponse> (GetWeatherForecastsRequest.Route); List <WeatherForecastDto> weatherForecasts = getWeatherForecastsResponse.WeatherForecasts; WeatherForecastsState._WeatherForecasts = weatherForecasts; return(WeatherForecastsState); }
public override async Task <Unit> Handle ( FetchWeatherForecastsAction aFetchWeatherForecastsAction, CancellationToken aCancellationToken ) { var getWeatherForecastsRequest = new GetWeatherForecastsRequest { Days = 10 }; GetWeatherForecastsResponse getWeatherForecastsResponse = await HttpClient.PostJsonAsync <GetWeatherForecastsResponse>(GetWeatherForecastsRequest.Route, getWeatherForecastsRequest); WeatherForecastsState._WeatherForecasts = getWeatherForecastsResponse.WeatherForecasts; return(Unit.Value); }
public override Task <GetWeatherForecastsResponse> GetWeatherForecasts(Empty request, ServerCallContext context) { var rng = new Random(); var results = Enumerable.Range(1, 300).Select(index => new WeatherForecast { Date = DateTime.UtcNow.AddDays(index).ToTimestamp(), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }).ToArray(); var response = new GetWeatherForecastsResponse(); response.Forecasts.AddRange(results); return(Task.FromResult(response)); }
public override async Task <WeatherForecastsState> Handle( FetchWeatherForecastsAction aFetchWeatherForecastsRequest, CancellationToken aCancellationToken) { using HttpResponseMessage httpResponseMessage = await HttpClient.GetAsync(GetWeatherForecastsRequest.Route); string content = await httpResponseMessage.Content.ReadAsStringAsync(); GetWeatherForecastsResponse getWeatherForecastsResponse = await HttpClient.GetJsonAsync <GetWeatherForecastsResponse>(GetWeatherForecastsRequest.Route); List <WeatherForecastDto> weatherForecasts = getWeatherForecastsResponse.WeatherForecasts; WeatherForecastsState._WeatherForecasts = weatherForecasts; return(WeatherForecastsState); }
public override async Task <WeatherForecastsState> Handle ( FetchWeatherForecastsAction aFetchWeatherForecastsRequest, CancellationToken aCancellationToken ) { var getWeatherForecastsRequest = new GetWeatherForecastsRequest { Days = 10 }; GetWeatherForecastsResponse getWeatherForecastsResponse = await HttpClient.GetJsonAsync <GetWeatherForecastsResponse>(getWeatherForecastsRequest.RouteWithQueryString); List <WeatherForecastDto> weatherForecasts = getWeatherForecastsResponse.WeatherForecasts; WeatherForecastsState._WeatherForecasts = weatherForecasts; return(WeatherForecastsState); }
public override Task <GetWeatherForecastsResponse> GetWeatherForecasts(GetWeatherForecastsRequest request, ServerCallContext context) { if (request.ReturnCount > 999999) { throw new RpcException(new Status(StatusCode.InvalidArgument, "Return count is too large.")); } var rng = new Random(); var results = Enumerable.Range(1, request.ReturnCount).Select(index => new WeatherForecast { Date = DateTime.UtcNow.AddDays(index).ToTimestamp(), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }).ToArray(); var response = new GetWeatherForecastsResponse(); response.Forecasts.AddRange(results); return(Task.FromResult(response)); }
public override async Task <GetWeatherForecastsResponse> GetWeatherForecasts(Empty request, ServerCallContext context) { var httpContext = context.GetHttpContext(); await context.WriteResponseHeadersAsync(new Metadata { { "host", $"{httpContext.Request.Scheme}://{httpContext.Request.Host}" } }); var rng = new Random(); var results = Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.UtcNow.AddDays(index).ToTimestamp(), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }).ToArray(); var response = new GetWeatherForecastsResponse(); response.Forecasts.AddRange(results); return(response); }
public async Task _10WeatherForecasts_Given_10DaysRequested() { GetWeatherForecastsResponse getWeatherForecastsResponse = await Send(GetWeatherForecastsRequest); ValidateGetWeatherForecastsResponse(getWeatherForecastsResponse); }