public async Task <IActionResult> GetPermissionScopes([FromQuery] string scopeType  = "DelegatedWork",
                                                              [FromQuery] string requestUrl = null,
                                                              [FromQuery] string method     = null,
                                                              [FromQuery] string org        = null,
                                                              [FromQuery] string branchName = null)
        {
            try
            {
                string localeCode = RequestHelper.GetPreferredLocaleLanguage(Request) ?? Constants.DefaultLocale;

                List <ScopeInformation> result = null;

                if (!string.IsNullOrEmpty(org) && !string.IsNullOrEmpty(branchName))
                {
                    // Fetch permissions descriptions file from Github
                    result = await _permissionsStore.GetScopesAsync(scopeType : scopeType,
                                                                    locale : localeCode,
                                                                    requestUrl : requestUrl,
                                                                    method : method,
                                                                    org : org,
                                                                    branchName : branchName);
                }
                else
                {
                    // Fetch the files from Azure Blob
                    result = await _permissionsStore.GetScopesAsync(scopeType : scopeType,
                                                                    locale : localeCode,
                                                                    requestUrl : requestUrl,
                                                                    method : method);
                }

                return(result == null?NotFound() : (IActionResult)Ok(result));
            }
            catch (InvalidOperationException invalidOpsException)
            {
                return(new JsonResult(invalidOpsException.Message)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
            catch (ArgumentNullException argNullException)
            {
                return(new JsonResult(argNullException.Message)
                {
                    StatusCode = StatusCodes.Status400BadRequest
                });
            }
            catch (Exception exception)
            {
                return(new JsonResult(exception.Message)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
        public async Task <IActionResult> GetPermissionScopes([FromQuery] string scopeType  = "DelegatedWork",
                                                              [FromQuery] string requestUrl = null,
                                                              [FromQuery] string method     = null)
        {
            try
            {
                string localeCode = RequestHelper.GetPreferredLocaleLanguage(Request);

                List <ScopeInformation> result = null;
                result = await _permissionsStore.GetScopesAsync(scopeType, localeCode, requestUrl, method);

                return(result == null?NotFound() : (IActionResult)Ok(result));
            }
            catch (InvalidOperationException invalidOpsException)
            {
                return(new JsonResult(invalidOpsException.Message)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
            catch (ArgumentNullException argNullException)
            {
                return(new JsonResult(argNullException.Message)
                {
                    StatusCode = StatusCodes.Status400BadRequest
                });
            }
            catch (Exception exception)
            {
                return(new JsonResult(exception.Message)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
        public void GetRequiredPermissionScopesGivenAnExistingRequestUrl()
        {
            // Act
            List <ScopeInformation> result = _permissionsStore.GetScopesAsync(requestUrl: "/security/alerts/{alert_id}", method: "GET")
                                             .GetAwaiter().GetResult();

            // Assert
            Assert.Collection(result,
                              item =>
            {
                Assert.Equal("SecurityEvents.Read.All", item.ScopeName);
                Assert.Equal("Read your organization's security events", item.DisplayName);
                Assert.Equal("Allows the app to read your organization's security events on your behalf.", item.Description);
                Assert.True(item.IsAdmin);
            },
                              item =>
            {
                Assert.Equal("SecurityEvents.ReadWrite.All", item.ScopeName);
                Assert.Equal("Read and update your organization's security events", item.DisplayName);
                Assert.Equal("Allows the app to read your organization's security events on your behalf. Also allows you to update editable properties in security events.", item.Description);
                Assert.True(item.IsAdmin);
            });
        }