public async void ImportSelectedLocations_ShouldSucceed()
        {
            // Arrange
            SetUp();
            List <Location> locationsToBeImported = null;
            var             selectedLocations     = new List <Location>
            {
                new Location {
                    Id = 1
                },
                new Location {
                    Id = 2
                }
            };

            _dataSourceGovernor.GetCurrentDataSourceTypeAsync()
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <DataSourceType>();
                tcs.SetResult(DataSourceType.Local);
                return(tcs.Task);
            });
            _connectivityService.IsWebApiAvailableAsync()
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <bool>();
                tcs.SetResult(true);
                return(tcs.Task);
            });
            _locationDataImporter.ImportAsync(Arg.Any <List <Location> >(), Arg.Any <CancellationToken>())
            .Returns(_ =>
            {
                locationsToBeImported = _.Arg <IEnumerable <Location> >().ToList();
                return(Task.CompletedTask);
            });

            // Act
            var sit = CreateViewModel();

            sit.SelectedLocations = selectedLocations;
            await sit.ImportSelectedLocations();

            // Assert
            Assert.Equal(selectedLocations, locationsToBeImported);
        }
Exemple #2
0
        public async Task ImportSelectedLocations()
        {
            if ((await _dataSourceGovernor.GetCurrentDataSourceTypeAsync()) == DataSourceType.Remote)
            {
                await _dialogService.ShowAsync("You are currently using the LocationCapture web API as a data source.\r\nPlease switch to the local data source to synchronize locations.");

                return;
            }

            if (SelectedLocations.Count == 0)
            {
                await _dialogService.ShowAsync("Please select at least one location.");

                return;
            }

            IsBusy = true;
            if (!(await _connectivityService.IsWebApiAvailableAsync()))
            {
                await _dialogService.ShowAsync("The LocationCapture web API is not available. Synchronization failed.");

                IsBusy = false;
                return;
            }

            IsImportInProgress = true;

            _importCancellationTokenSource = new CancellationTokenSource();
            await _locationDataImporter.ImportAsync(SelectedLocations, _importCancellationTokenSource.Token);

            _importCancellationTokenSource.Dispose();
            SetDefaultView();

            IsBusy             = false;
            IsImportInProgress = false;
        }