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);
            }
Exemplo n.º 2
0
 public Handle_Returns
 (
     WebApplicationFactory <Startup> aWebApplicationFactory,
     JsonSerializerOptions aJsonSerializerOptions
 ) : base(aWebApplicationFactory, aJsonSerializerOptions)
 {
     GetWeatherForecastsRequest = new GetWeatherForecastsRequest {
         Days = 10
     };
 }
Exemplo n.º 3
0
 public Returns
 (
     TimeWarpBlazorServerApplication aTimeWarpBlazorServerApplication
 )
 {
     GetWeatherForecastsRequest = new GetWeatherForecastsRequest {
         Days = 10
     };
     TimeWarpBlazorServerApplication = aTimeWarpBlazorServerApplication;
 }
Exemplo n.º 4
0
        public void Be_Valid()
        {
            var getWeatherForecastsRequest = new GetWeatherForecastsRequest
            {
                Days = 5
            };

            ValidationResult validationResult = GetWeatherForecastsRequestValidator.TestValidate(getWeatherForecastsRequest);

            validationResult.IsValid.Should().BeTrue();
        }
        public async Task ShouldGetAllWeatherForecasts()
        {
            // Arrange
            var getWeatherForecastsRequest = new GetWeatherForecastsRequest();

            //Act
            GetWeatherForecastsResponse getWeatherForecastsResponse =
                await Mediator.Send(getWeatherForecastsRequest);

            //Assert
            getWeatherForecastsResponse.WeatherForecasts.Count.ShouldBe(5);
        }
Exemplo n.º 6
0
            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);
            }
Exemplo n.º 7
0
            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);
            }
Exemplo n.º 8
0
        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));
        }