public async Task <IActionResult> UpdateWorker(string providerId, string id, [FromBody] ProviderWorkerBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrors())); } var(result, outcomeAction, error) = await _providerWorkerRepository.PatchAllButProviderWorkerImageStoreAsync( providerId, new ProviderWorker { Id = id, Email = model.Email, Name = model.Name, LastName = model.LastName, Status = model.Status, PhoneNumber = model.PhoneNumber, DeviceId = model.DeviceId, LastKnownLocation = model.LastKnownLocation }); return(this.FromRepositoryOutcome(outcomeAction, error, MapToProviderWorkerViewModel(result))); }
public async Task TestPatchAllButProviderWorkerImageStoreAsyncPatchesProviderWorker() { // arrange var providerId = Guid.NewGuid().ToString("n"); var id = Guid.NewGuid().ToString("n"); var provider = new Provider { Id = providerId, City = "Springfield", State = "Illinois", Name = "TowNow!", Email = "*****@*****.**", ZipCode = "2342", ProviderImageBucketKey = new ImageBucketKey { Store = "some-store", Bucket = Guid.NewGuid().ToString("n") }, Address = "742 Evergreen Terrace", }; var providerWorker = new ProviderWorker { Id = id, ProviderId = providerId, Name = "Homer", LastName = "Simpson", ProviderWorkerImageBucketKey = new ImageBucketKey { Store = Constants.WORKER_IMAGES_STORE, Bucket = Guid.NewGuid().ToString("n") } }; var updatedProviderWorker = new ProviderWorker { Id = id, ProviderId = providerId, Name = "Bart", LastName = "Simpson", ProviderWorkerImageBucketKey = new ImageBucketKey { Store = Constants.WORKER_IMAGES_STORE, Bucket = Guid.NewGuid().ToString("n") } }; _dataStore.EnsureProvider(provider); _dataStore.EnsureProviderWorker(providerWorker); // act var(providerWorkerResult, outcomeAction, error) = await _providerWorkerRepository.PatchAllButProviderWorkerImageStoreAsync(providerId, updatedProviderWorker); // assert Assert.NotNull(providerWorkerResult); Assert.Equal(RepositoryOutcomeAction.OkUpdated, outcomeAction); Assert.Null(error); Assert.Equal(updatedProviderWorker.Id, providerWorkerResult.Id); Assert.Equal(updatedProviderWorker.ProviderId, providerWorkerResult.ProviderId); Assert.Equal(updatedProviderWorker.LastKnownLocation, providerWorkerResult.LastKnownLocation); Assert.Equal(updatedProviderWorker.LastName, providerWorkerResult.LastName); Assert.Equal(updatedProviderWorker.Name, providerWorkerResult.Name); Assert.Equal(updatedProviderWorker.PhoneNumber, providerWorkerResult.PhoneNumber); Assert.Equal(updatedProviderWorker.Status, providerWorkerResult.Status); // we must test that ProviderWorkerImageBucketKey is not changed Assert.Equal(providerWorker.ProviderWorkerImageBucketKey?.Store, providerWorkerResult.ProviderWorkerImageBucketKey?.Store); Assert.Equal(providerWorker.ProviderWorkerImageBucketKey?.Bucket, providerWorkerResult.ProviderWorkerImageBucketKey?.Bucket); Assert.True( _dataStore .TestProviderWorker(_ => _.Id == updatedProviderWorker.Id && _.ProviderId == updatedProviderWorker.ProviderId && _.LastKnownLocation == updatedProviderWorker.LastKnownLocation && _.LastName == updatedProviderWorker.LastName && _.Name == updatedProviderWorker.Name && _.PhoneNumber == updatedProviderWorker.PhoneNumber && _.Status == updatedProviderWorker.Status && ( _.ProviderWorkerImageBucketKey != null && providerWorker.ProviderWorkerImageBucketKey != null && _.ProviderWorkerImageBucketKey.Store == providerWorker.ProviderWorkerImageBucketKey.Store && _.ProviderWorkerImageBucketKey.Bucket == providerWorker.ProviderWorkerImageBucketKey.Bucket ))); }