예제 #1
0
        public async Task <IActionResult> GetAllLocations()
        {
            var locations = await _locationDataService.GetAllLocationsAsync();

            var result = Mapper.Map <IEnumerable <Location>, IEnumerable <LocationDto> >(locations);

            return(Ok(result));
        }
예제 #2
0
        public async Task ImportAsync(IEnumerable <Location> locationsToImport, CancellationToken cancellationToken)
        {
            var remoteLocations = await _locationServiceProxy.GetAllLocationsAsync();

            foreach (var locationToImport in locationsToImport)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                Location importedLocation = null;

                if (remoteLocations.All(_ => _.Name != locationToImport.Name))
                {
                    importedLocation = await _locationServiceProxy.AddLocationAsync(locationToImport);
                }
                else
                {
                    importedLocation = remoteLocations.First(_ => _.Name == locationToImport.Name);
                }

                await ImportSnapshotsAsync(locationToImport, importedLocation, cancellationToken);
            }
        }
예제 #3
0
        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 void ImportAsync_ShouldImportNewLocation()
        {
            // Arrange
            SetUp();
            _locationServiceProxy.GetAllLocationsAsync()
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <IEnumerable <Location> >();
                tcs.SetResult(new List <Location>());
                return(tcs.Task);
            });
            _locationServiceProxy.AddLocationAsync(Arg.Any <Location>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <Location>();
                tcs.SetResult(_locationToImport);
                return(tcs.Task);
            });
            _snapshotServiceProxy.GetSnapshotsByLocationIdAsync(Arg.Any <int>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <IEnumerable <LocationSnapshot> >();
                tcs.SetResult(new List <LocationSnapshot>());
                return(tcs.Task);
            });

            // Act
            var sit = new LocationDataImporter(_dataServiceFactory);
            await sit.ImportAsync(new List <Location> {
                _locationToImport
            }, new CancellationTokenSource().Token);

            // Assert
            await _locationServiceProxy.Received().AddLocationAsync(_locationToImport);

            await _snapshotServiceProxy.Received().AddSnapshotAsync(_snapshotsToImport[0]);

            await _snapshotServiceProxy.Received().AddSnapshotAsync(_snapshotsToImport[1]);

            await _pictureServiceProxy.Received().SaveSnapshotContentAsync(_snapshotsToImport[0], _pictureData);

            await _pictureServiceProxy.Received().SaveSnapshotContentAsync(_snapshotsToImport[1], _pictureData);
        }