private async Task <object> GetMachineByKeyAsync(dynamic input, CancellationToken cancellationToken)
        {
            string machinekey = Request.Query.machinekey;

            try
            {
                var machine = await _machinesController.GetMachineByKeyAsync(machinekey, NullableTenantId, cancellationToken);

                await RequiresAccess()
                .WithTenantIdExpansion(ctx => machine.TenantId)
                .ExecuteAsync(cancellationToken);

                return(machine);
            }
            catch (RouteExecutionEarlyExitException)
            {
                throw;
            }
            catch (ValidationFailedException ex)
            {
                Logger.Debug("Validation failed for GetMachineByKey", ex);
                return(Response.BadRequestValidationFailed(ex.Errors));
            }
            catch (NotFoundException)
            {
                return(Response.NotFound(ResponseReasons.NotFoundMachine));
            }
            catch (Exception ex)
            {
                Logger.Error("GetMachineByKey threw an unhandled exception", ex);
                return(Response.InternalServerError(ResponseReasons.InternalServerErrorGetMachine));
            }
        }
示例#2
0
        public async Task GetMachineByKeyAsync_WhenKeyMatched_ReturnsMachine()
        {
            var machineKey  = Guid.NewGuid().ToString();
            var testMachine = new Machine
            {
                MachineKey = machineKey.ToUpperInvariant(),
                TenantId   = Guid.Parse("d65bb77a-2658-4576-9b78-a6fc01a57c47")
            };

            _machineRepositoryMock.SetupCreateItemQuery(o => new List <Machine> {
                testMachine
            });

            var result = await _controller.GetMachineByKeyAsync(machineKey, Guid.Parse("d65bb77a-2658-4576-9b78-a6fc01a57c47"));

            Assert.IsType <Machine>(result);
        }