public async Task <ActionResult <GetCountriesResponse> > GetCountries()
        {
            var result = new GetCountriesResponse
            {
                Countries = await _listOfValuesService.GetAllCountriesAsync()
            };

            _logger.LogInformation("Countries found: {0}", result.Countries.Count);
            return(Ok(result));
        }
Example #2
0
        public GetCountriesResponse GetCountries(GetCountriesRequest request)
        {
            GetCountriesResponse  response = new GetCountriesResponse();
            IEnumerable <dynamic> countries;

            countries = repository.GetCountries().ToList();
            if (countries == null)
            {
                throw new ResourceNotFoundException("The requested countries list was not found.");
            }
            response.Countries = countries;
            return(response);
        }
Example #3
0
        /**
         * Get the countries.
         */
        public async Task <APIGatewayProxyResponse> GetCountries(IDataStores dataStores)
        {
            Debug.Tested();
            Debug.AssertValid(dataStores);

            try {
                // Get the NoSQL DB client
                AmazonDynamoDBClient dbClient = dataStores.GetNoSQLDataStore().GetDBClient();
                Debug.AssertValid(dbClient);

                // Get response information
                IEnumerable <Country> countries = await CountryServiceLogicLayer.GetCountries(dbClient);

                Debug.AssertValid(countries);
                GetCountriesResponse      responseBody       = new GetCountriesResponse();
                List <GetCountryResponse> availableCountries = new List <GetCountryResponse>();
                foreach (Country country in countries)
                {
                    Debug.Tested();
                    Debug.AssertValid(country);
                    if (country.Available)
                    {
                        Debug.Tested();
                        availableCountries.Add(new GetCountryResponse {
                            code = country.Code, name = country.Name, currencies = country.Currencies.ToArray()
                        });
                    }
                    else
                    {
                        Debug.Tested();
                    }
                }
                responseBody.countries = availableCountries.ToArray();

                // Return response
                return(new APIGatewayProxyResponse
                {
                    StatusCode = STATUS_CODE_OK,
                    Body = JsonConvert.SerializeObject(responseBody)
                });
            } catch (Exception exception) {
                Debug.Unreachable();
                return(APIHelper.ResponseFromException(exception));
            }
        }
Example #4
0
        public async void GetCountriesAsync_ShouldReturn_ResultsInMappedFormat()
        {
            // Arrange
            var response = new GetCountriesResponse
            {
                GetCountriesResult = ResultDataSet.ToArray()
            };

            _mockProxy
            .Setup(x => x.Execute(It.IsAny <Func <ICountryServiceChannel, Task <GetCountriesResponse> > >()))
            .Returns(Task.FromResult(response));

            // Act
            var result = await _wrapper.GetCountriesAsync();

            // Assert
            result
            .Should().HaveCount(2)
            .And.ContainSingle(x => x.Code == "fi" && x.Name == "Finland");
        }