public void BarDataModel_RemoveBarsOutsideRadius_NullRadius() { // Arrange var barData = new BarDataModel(); // Act // Assert var ex = Assert.Throws <ArgumentNullException>(() => barData.RemoveBarsOutsideRadius(null)); }
public void BarDataModel_RemoveBarsOutsideRadius_InvalidRadius([Values(-1, 999999.0)] double radius) { // Arrange var barData = new BarDataModel(); // Act var ex = Assert.Throws <ArgumentsForProvidersException>(() => barData.RemoveBarsOutsideRadius(radius)); // now we can test the exception itself Assert.That(ex.InvalidArguments == "radius"); }
public static async Task <BarDataModel> RequestBarsAroundCoords(double latitude, double longitude, double radius) { var result = new BarDataModel(); var failedToConnectCounter = 0; var providerCount = _providerList.Count; foreach (IBeerable provider in _providerList) { try { var barsFromProvider = await CollectBarsFromProvider(provider, latitude, longitude, radius); if (barsFromProvider != null) { result.AddRange(barsFromProvider); } } catch (HttpRequestException) { if (++failedToConnectCounter == providerCount) { throw; } } catch (WebException) { Console.Write("Provider \"{0}\" is down\n", provider.ProviderName); // Provider is down, lets just ignore it } } var dbManager = new DatabaseManager(); dbManager.SaveBars(result); result.AddRange(dbManager.GetAllBarData(result.Select(x => x.BarId))); result.RemoveBarsOutsideRadius(radius); result.RemoveDuplicates(); return(result); }
public void BarDataModel_RemoveBarsOutsideRadius_RemoveBarsOutside([Random(_numberOfBarsToStay, _maximumRadius, 2)] double radius) { // Arrange var barData = new BarDataModel(); for (var i = 0; i < _numberOfBarsToStay; i++) { barData.Add(new BarData { DistanceToCurrentLocation = radius - i }); } for (var i = 1; i <= _numberOfBarsToRemove; i++) { barData.Add(new BarData { DistanceToCurrentLocation = radius + i }); } // Act barData.RemoveBarsOutsideRadius(radius); // Assert Assert.AreEqual(_numberOfBarsToStay, barData.Count); }
private async void GoButton_Click(object sender, EventArgs e) { var latitude = GetLatitude(); var longitude = GetLongitude(); var radius = GetRadius(); var failedToConnectCounter = 0; var providerCount = _providerList.Count; try { var barsFromProvider = new List <BarData>(); var progressStep = 100 / providerCount; var result = new BarDataModel(); var currentProgressValue = 0; GoButton.Enabled = false; InitiateProgressBars(); UpdateProgressBars(currentProgressValue); foreach (IBeerable provider in _providerList) { try { barsFromProvider = await CollectBarsFromProvider(provider, latitude, longitude, radius); } catch (HttpRequestException) { if (++failedToConnectCounter == providerCount) { MessageBox.Show("Check your internet connection, it seems to be down."); } } catch (WebException) { MessageBox.Show("Failed connecting to: " + provider.ProviderName); } result.AddRange(barsFromProvider); currentProgressValue += progressStep; UpdateProgressBars(currentProgressValue); } result.RemoveDuplicates(); result.RemoveBarsOutsideRadius(radius); await Task.Run(() => result = (BarDataModel)WebApiAccess.GetAllBarData(result)); HideProgressBars(); // Display _barRating.BarsData = result; var currentLocation = GetCurrentLocation(); if (result != null) { foreach (var bar in _barRating.BarsData) { bar.DistanceToCurrentLocation = currentLocation.GetDistanceTo(new GeoCoordinate(bar.Latitude, bar.Longitude)); } SortList(CompareType.Distance); } } catch (ArgumentsForProvidersException) { MessageBox.Show("Please enter the required data correctly. Erroneus data is painted red."); } finally { HideProgressBars(); GoButton.Enabled = true; } }