public async Task UpdateMachineAsync_WhenSuccessful_ReturnsUpdatedMachine() { var testMachine = new Machine { TenantId = Guid.Parse("e4ae81cb-1ddb-4d04-9c08-307a40099620"), MachineKey = "1122334455", Location = "Location" }; _machineRepositoryMock.Setup(m => m.GetItemAsync(It.IsAny <Guid>(), It.IsAny <QueryOptions>(), It.IsAny <CancellationToken>())) .ReturnsAsync(testMachine); _machineRepositoryMock.SetupCreateItemQuery(o => new List <Machine> { testMachine }); _machineRepositoryMock.Setup(m => m.UpdateItemAsync(It.IsAny <Guid>(), It.IsAny <Machine>(), It.IsAny <UpdateOptions>(), It.IsAny <CancellationToken>())) .ReturnsAsync((Guid id, Machine m, UpdateOptions o, CancellationToken t) => m); var newMachine = new Machine { Id = Guid.NewGuid(), MachineKey = "1234567890", Location = "New Location" }; var result = await _controller.UpdateMachineAsync(newMachine, CancellationToken.None); Assert.NotNull(result); }
private async Task <object> UpdateMachineAsync(dynamic input, CancellationToken cancellationToken) { Machine updateMachine; try { updateMachine = this.Bind <Machine>(); } catch (Exception ex) { Logger.Error("Binding failed while attempting to update a Machine resource", ex); return(Response.BadRequestBindingException()); } await RequiresAccess() .WithTenantIdExpansion(ctx => updateMachine.TenantId) .ExecuteAsync(cancellationToken); try { return(await _machinesController.UpdateMachineAsync(updateMachine, cancellationToken)); } catch (ValidationFailedException ex) { Logger.Debug("Validation failed for UpdateMachine", ex); return(Response.BadRequestValidationFailed(ex.Errors)); } catch (NotFoundException) { return(Response.NotFound(ResponseReasons.NotFoundMachine)); } catch (Exception ex) { Logger.Error("Unhandled exception encountered while attempting to update a Machine resource", ex); return(Response.InternalServerError(ResponseReasons.InternalServerErrorUpdateMachine)); } }