private async Task <object> GetMachineByIdAsync(dynamic input, CancellationToken cancellationToken) { Guid machineId = input.id; try { var machine = await _machinesController.GetMachineByIdAsync(machineId, NullableTenantId, cancellationToken); await RequiresAccess() .WithTenantIdExpansion(ctx => machine.TenantId) .ExecuteAsync(cancellationToken); return(machine); } catch (RouteExecutionEarlyExitException) { throw; } catch (NotFoundException) { return(Response.NotFound(ResponseReasons.NotFoundMachine)); } catch (ValidationFailedException ex) { Logger.Debug("Validation failed for GetMachineById", ex); return(Response.BadRequestValidationFailed(ex.Errors)); } catch (Exception ex) { Logger.Error("GetMachineById threw an unhandled exception", ex); return(Response.InternalServerError(ResponseReasons.InternalServerErrorGetMachine)); } }
public async Task GetMachineByIdAsync_WhenMachineFound_ReturnsMachine() { var machineId = Guid.NewGuid(); var testMachine = new Machine { Id = machineId, TenantId = Guid.Parse("d65bb77a-2658-4576-9b78-a6fc01a57c47") }; _machineRepositoryMock.SetupCreateItemQuery(o => new List <Machine> { testMachine }); var tenantId = Guid.Parse("d65bb77a-2658-4576-9b78-a6fc01a57c47"); var result = await _controller.GetMachineByIdAsync(machineId, tenantId); Assert.IsType <Machine>(result); }