Example #1
0
        public async Task DeleteMachineAsync_WhenMachineNotFound_DoesNotThrow()
        {
            _machineRepositoryMock.Setup(m => m.DeleteItemAsync(It.IsAny <Guid>(), It.IsAny <QueryOptions>(), It.IsAny <CancellationToken>()))
            .Throws(new DocumentNotFoundException());

            await _controller.DeleteMachineAsync(Guid.NewGuid(), Guid.NewGuid());
        }
        private async Task <object> DeleteMachineAsync(dynamic input, CancellationToken cancellationToken)
        {
            Guid machineId = input.id;

            try
            {
                var tenantId = await _machinesController.GetMachineTenantIdAsync(machineId, NullableTenantId, cancellationToken);

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

                await _machinesController.DeleteMachineAsync(machineId, tenantId, cancellationToken);

                return(Response.NoContent("Machine has been deleted"));
            }
            catch (RouteExecutionEarlyExitException)
            {
                throw;
            }
            catch (ValidationFailedException ex)
            {
                Logger.Debug("Validation failed for DeleteMachine", ex);
                return(Response.BadRequestValidationFailed(ex.Errors));
            }
            catch (Exception ex)
            {
                Logger.Error($"An unhandled exception was encountered while deleting machine '{machineId}'", ex);
                return(Response.InternalServerError(ResponseReasons.InternalServerErrorGetMachine));
            }
        }