Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        public async Task _10WeatherForecasts_Given_10DaysRequested()
        {
            GetWeatherForecastsResponse getWeatherForecastsResponse =
                await GetJsonAsync <GetWeatherForecastsResponse>(GetWeatherForecastsRequest.GetRoute());

            ValidateGetWeatherForecastsResponse(getWeatherForecastsResponse);
        }
Ejemplo n.º 3
0
        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);
            }
Ejemplo n.º 5
0
        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);
            }
Ejemplo n.º 8
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);
            }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
            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);
            }
Ejemplo n.º 11
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);
            }
Ejemplo n.º 12
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));
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        public async Task _10WeatherForecasts_Given_10DaysRequested()
        {
            GetWeatherForecastsResponse getWeatherForecastsResponse = await Send(GetWeatherForecastsRequest);

            ValidateGetWeatherForecastsResponse(getWeatherForecastsResponse);
        }