Esempio n. 1
0
        public async Task GetTenantMachinesAsync_WhenSuccessful_ReturnsRepositoryQueryResults()
        {
            var validTenantId = Guid.NewGuid();
            var expectedData  = Enumerable.Range(0, 10)
                                .Select(_ => new Machine {
                Id = Guid.NewGuid(), TenantId = validTenantId
            })
                                .ToList();

            _machineRepositoryMock.SetupCreateItemQuery(o => expectedData);

            var result = await _controller.GetTenantMachinesAsync(validTenantId);

            Assert.Equal <Machine>(expectedData, result);
        }
        private async Task <object> GetTenantMachinesAsync(dynamic input, CancellationToken cancellationToken)
        {
            await RequiresAccess()
            .ExecuteAsync(cancellationToken);

            try
            {
                return(await _machinesController.GetTenantMachinesAsync(TenantId, cancellationToken));
            }
            catch (ValidationFailedException ex)
            {
                Logger.Debug("Validation failed for GetTenantMachines", ex);
                return(Response.BadRequestValidationFailed(ex.Errors));
            }
            catch (Exception ex)
            {
                Logger.Error("Unhandled exception encountered while attempting to Get Tenant Machines", ex);
                return(Response.InternalServerError(ResponseReasons.InternalServerErrorGetMachine));
            }
        }