Beispiel #1
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);
            }
        }
Beispiel #2
0
        public async Task SaveChanges()
        {
            if (string.IsNullOrEmpty(SelectedLocation.Name))
            {
                await _dialogService.ShowAsync("Location name cannot be empty.");

                return;
            }

            IsBusy = true;
            if (_editOperation == EditOperation.Add)
            {
                var newLocation = await _locationDataService.AddLocationAsync(SelectedLocation);

                Locations.Add(newLocation);
            }
            else if (_editOperation == EditOperation.Rename)
            {
                var renamedLocation = await _locationDataService.RenameLocationAsync(SelectedLocation.Id, SelectedLocation.Name);

                Locations.First(_ => _.Id == renamedLocation.Id).Name = renamedLocation.Name;
            }

            SetDefaultView();
            IsBusy = false;
        }
        public async void SaveChanges_ShouldAddLocation()
        {
            // Arrange
            SetUp();
            LocationsViewModel sit = null;
            var newLocationName    = "NewLocation";

            _locationDataService.AddLocationAsync(Arg.Any <Location>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <Location>();
                tcs.SetResult(sit.SelectedLocation);
                return(tcs.Task);
            });

            // Act
            sit = CreateViewModel();
            await sit.OnLoaded();

            sit.BeginAddLocation();
            sit.SelectedLocation.Name = newLocationName;
            await sit.SaveChanges();

            // Assert
            Assert.Equal(4, sit.Locations.Count);
            Assert.Equal(newLocationName, sit.Locations[3].Name);
        }
Beispiel #4
0
        public async Task <IActionResult> AddLocation([FromBody] LocationForCreationDto locationForCreation)
        {
            if (!ModelState.IsValid)
            {
                _logger.LogWarning("Bad request. Model state invalid: {@ModelState}", ModelState);
                return(BadRequest(ModelState));
            }

            var locationToAdd = Mapper.Map <LocationForCreationDto, Location>(locationForCreation);
            var addedLocation = await _locationDataService.AddLocationAsync(locationToAdd);

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

            return(Ok(result));
        }
        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);
        }