private async Task GroupByChanged() { if (IsBusy) { return; } IsBusy = true; IsViewGrouped = (GroupBy != GroupByCriteria.None); SetDefaultView(); if (GroupBy == GroupByCriteria.None) { var locations = await _locationDataService.GetAllLocationsAsync(); Locations = new ObservableCollection <Location>(locations); } else { var dataFetchOperation = _locationSnapshotDataService.ChooseGroupByOperation(GroupBy); var snapshotGroups = await dataFetchOperation(); SnapshotsGroups = new ObservableCollection <SnapshotGroup>(snapshotGroups); } IsBusy = false; }
private void SetUp() { _locations = new List <Location> { new Location { Id = 1, Name = "Barcelona" }, new Location { Id = 2, Name = "Prague" }, new Location { Id = 3, Name = "Frankfurt" } }; _snapshotGroups = new List <SnapshotGroup> { new SnapshotGroup { Name = "December 2018" }, new SnapshotGroup { Name = "March 2019" } }; Task <IEnumerable <SnapshotGroup> > dataFetchOperation() { var tcs = new TaskCompletionSource <IEnumerable <SnapshotGroup> >(); tcs.SetResult(_snapshotGroups); return(tcs.Task); }; _snapshotDataService = Substitute.For <ILocationSnapshotDataService>(); _snapshotDataService.ChooseGroupByOperation(Arg.Any <GroupByCriteria>()) .Returns(dataFetchOperation); _locationDataService = Substitute.For <ILocationDataService>(); _locationDataService.GetAllLocationsAsync() .Returns(_ => { var tcs = new TaskCompletionSource <IEnumerable <Location> >(); tcs.SetResult(_locations); return(tcs.Task); }); _dialogService = Substitute.For <IDialogService>(); _dialogService.ShowConfirmationAsync(Arg.Any <string>()) .Returns(_ => { var tcs = new TaskCompletionSource <ConfirmationAnswer>(); tcs.SetResult(ConfirmationAnswer.OK); return(tcs.Task); }); _pictureService = Substitute.For <IPictureService>(); _locationDataImporter = Substitute.For <ILocationDataImporter>(); _dataSourceGovernor = Substitute.For <IDataSourceGovernor>(); _connectivityService = Substitute.For <IConnectivityService>(); _navigationService = Substitute.For <INavigationService>(); _platformSpecificActions = Substitute.For <IPlatformSpecificActions>(); }
public async Task <IActionResult> GroupSnapshots(GroupByCriteria groupBy) { if (groupBy == GroupByCriteria.None) { _logger.LogWarning("Bad request. Invalid group by criteria."); return(BadRequest()); } var dataFetchOperation = _locationSnapshotDataService.ChooseGroupByOperation(groupBy); var snapshotGroups = await dataFetchOperation(); var result = Mapper.Map <IEnumerable <SnapshotGroup>, IEnumerable <SnapshotGroupDto> >(snapshotGroups); return(Ok(result)); }