public async void CountryListService_EndpointWorks() { var testApiPath = "/countries"; var mockedData = new CountryListDTO { CountryCollection = new List <CountryDetailsDTO> { new CountryDetailsDTO { TranslatedName = "Norge", Code = "no" } } }; ApiStubHelper.StubServer .Given(Request.Create().WithPath(testApiPath).UsingGet()) .RespondWith( Response.Create() .WithStatusCode(System.Net.HttpStatusCode.OK) .WithBody(Newtonsoft.Json.JsonConvert.SerializeObject(mockedData)) ); var baseService = new BaseWebService(); ApiResponse <CountryListDTO> response = await baseService.Get <CountryListDTO>(ApiStubHelper.StubServerUrl + testApiPath); Assert.True(response.IsSuccessfull); Assert.Equal(mockedData.CountryCollection.Count, response.Data.CountryCollection.Count); Assert.Equal(mockedData.CountryCollection[0].Code, response.Data.CountryCollection[0].Code); Assert.Equal(mockedData.CountryCollection[0].TranslatedName, response.Data.CountryCollection[0].TranslatedName); }
/// <summary> /// Calls the server and requests a list of countries to show in the questionnaire /// </summary> /// <returns>A list of countries, or an empty list if the service call fails</returns> public async Task <List <CountryDetailsViewModel> > GetListOfCountriesAsync() { CountryListDTO countryList = await(new CountryListService()).GetCountryList(); return(countryList?.CountryCollection?.Select(x => new CountryDetailsViewModel { Name = x.GetName(), Code = x.Code }).ToList() ?? new List <CountryDetailsViewModel>()); }
/// <summary> /// Returns a list of country dimensions /// </summary> /// <param name="Page"></param> /// <param name="PageSize"></param> /// <returns></returns> public CountryListDTO GetCountryDimensions(int Page, int PageSize, string CountryName = "") { try { CountryListDTO list = DimensionDAL.GetCountryDimensions(Page, PageSize, CountryName); return(list); } catch (Exception) { throw; } }
/// <summary> /// Returns a list of accounts from the database /// </summary> /// <returns></returns> public CountryListDTO GetCountryDimensions(int Page, int PageSize, string CountryName = "") { CountryListDTO list = new CountryListDTO(); SQLAzure.DbConnection dbConn = new SQLAzure.DbConnection(_connectionString); try { dbConn.Open(); SQLAzure.RetryLogic.DbCommand dbComm = new SQLAzure.RetryLogic.DbCommand(dbConn); if (CountryName != string.Empty) { dbComm.CommandText = String.Format("SELECT ID, CountryCode, CountryName, TotalCount = COUNT(ID) OVER() FROM DimCountry WHERE CountryName LIKE '%' + @CountryName + '%' ORDER BY ID OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY", (Page * PageSize), PageSize); dbComm.Parameters.Add(new SqlParameter("CountryName", CountryName)); } else { dbComm.CommandText = String.Format("SELECT ID, CountryCode, CountryName, TotalCount = COUNT(ID) OVER() FROM DimCountry ORDER BY ID OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY", (Page * PageSize), PageSize); } System.Data.IDataReader rdr = dbComm.ExecuteReader(System.Data.CommandType.Text); while (rdr.Read()) { CountryDTO country = new CountryDTO(); country.ID = Convert.ToInt32(rdr["ID"]); country.CountryCode = rdr["CountryCode"].ToString(); country.CountryName = rdr["CountryName"].ToString(); list.Items.Add(country); list.RecordCount = Convert.ToInt32(rdr["TotalCount"]); } list.PageNumber = Page; list.PageSize = PageSize; list.TotalPages = GetNumberOfPagesAvailable(PageSize, list.RecordCount); } catch (SqlException) { throw; } finally { dbConn.Close(); } return(list); }
public IHttpActionResult Get(int Page, int PageSize, string CountryName = "") { ValidateModel(); try { CountryListDTO list = _dimensionBLL.GetCountryDimensions(Page, PageSize, CountryName); CountryDimensionList countryDimensions = new CountryDimensionList(); foreach (CountryDTO c in list.Items) { countryDimensions.Items.Add((CountryDimension)c); } if (countryDimensions.Items.Count > 0) { countryDimensions.PageNumber = list.PageNumber; countryDimensions.PageSize = list.PageSize; countryDimensions.RecordCount = list.RecordCount; countryDimensions.TotalPages = list.TotalPages; return(Ok(countryDimensions)); } else { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NoContent); response.Content = new StringContent("No Content"); return(ResponseMessage(response)); } } catch (Exception ex) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.InternalServerError); response.Content = new StringContent("Unknown Error"); // Insert Logging here Console.WriteLine(ex); return(ResponseMessage(response)); } }