public void GetEnvironmentLocationsAsyncSuccess()
        {
            string expectedRequestUri = "https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/locations?api-version=2016-11-01";
            Dictionary <string, string> expectedLocations = new Dictionary <string, string>()
            {
                { "name1", "unitedstates" },
                { "displayName1", "United States" },
                { "code1", "NA" },
                { "name2", "europe" },
                { "displayName2", "Europe" },
                { "code2", "EMEA" },
                { "name3", "asia" },
                { "displayName3", "Asia" },
                { "code3", "APAC" },
            };
            string responseFilePath = @"./data/templates/responses/powerApps/getLocations.json";

            HttpRequestMessage expectedRequest = TestHelper.CreateHttpRequest(
                HttpMethod.Get,
                expectedRequestUri);

            _httpClient.RegisterExpectedRequest(new ExpectedRequest(expectedRequest));

            HttpResponseMessage expectedResponse = TestHelper.CreateHttpResponse(
                HttpStatusCode.OK,
                null,
                responseFilePath,
                "application/json",
                expectedLocations);

            _httpClient.RegisterExpectedResponse(
                expectedRequestUri,
                new ExpectedResponse(expectedResponse));

            IPowerAppsClient client = new PowerAppsClient(_tokenProvider);

            GetPowerAppsEnvironmentLocationsResponse response = client.GetEnvironmentLocationsAsync().Result;

            Assert.IsNotNull(response, "The response should not be null!");
            Assert.IsNotNull(response.Value, "The response Value member should not be null!");
            Assert.AreEqual(3, response.Value.Length, $"Unexpected number of locations ('3' != '{response.Value.Length}')!");
            Assert.AreEqual(expectedLocations["name1"], response.Value[0].Name, $"Unexpected name for location 1 ('{expectedLocations["name1"]}' != '{response.Value[0].Name}')");
            Assert.IsNotNull(response.Value[0].Properties, "The response Value Properties member should not be null for location 1!");
            Assert.AreEqual(expectedLocations["code1"], response.Value[0].Properties.Code, $"Unexpected name for location 1 ('{expectedLocations["code1"]}' != '{response.Value[0].Name}')");
            Assert.AreEqual(expectedLocations["displayName1"], response.Value[0].Properties.DisplayName, $"Unexpected display name for location 1 ('{expectedLocations["displayName1"]}' != '{response.Value[0].Properties.DisplayName}')");
            Assert.AreEqual(expectedLocations["name2"], response.Value[1].Name, $"Unexpected name for location 2 ('{expectedLocations["name2"]}' != '{response.Value[1].Name}')");
            Assert.IsNotNull(response.Value[1].Properties, "The response Value Properties member should not be null for location 2!");
            Assert.AreEqual(expectedLocations["code2"], response.Value[1].Properties.Code, $"Unexpected name for location 2 ('{expectedLocations["code2"]}' != '{response.Value[1].Name}')");
            Assert.AreEqual(expectedLocations["displayName2"], response.Value[1].Properties.DisplayName, $"Unexpected display name for location 2 ('{expectedLocations["displayName2"]}' != '{response.Value[1].Properties.DisplayName}')");
            Assert.AreEqual(expectedLocations["name3"], response.Value[2].Name, $"Unexpected name for location 3 ('{expectedLocations["name3"]}' != '{response.Value[2].Name}')");
            Assert.IsNotNull(response.Value[2].Properties, "The response Value Properties member should not be null for location 3!");
            Assert.AreEqual(expectedLocations["code3"], response.Value[2].Properties.Code, $"Unexpected name for location 3 ('{expectedLocations["code3"]}' != '{response.Value[2].Name}')");
            Assert.AreEqual(expectedLocations["displayName3"], response.Value[2].Properties.DisplayName, $"Unexpected display name for location 3 ('{expectedLocations["displayName3"]}' != '{response.Value[2].Properties.DisplayName}')");
        }
        private void RunGetPowerAppsEnvironmentLocationsOperation()
        {
            Task.Run(() =>
            {
                OperationRunner singleRunner = new OperationRunner(
                    null,
                    this,
                    WizardContext.LogFileStream);
                singleRunner.IndeterminateOps = true;
                singleRunner.OnLog           += WriteLog;

                singleRunner.Operations.Enqueue(new Operation()
                {
                    Name = "GetPowerAppsEnvironmentLocations",
                    OperationFunction = GetPowerAppsEnvironmentLocationsAsync,
                    ValidateFunction  = (context) =>
                    {
                        return(context.LastOperationStatusCode == 0);
                    },
                    OperationCompletedHandler = (result) =>
                    {
                        GetPowerAppsEnvironmentLocationsResponse response = (GetPowerAppsEnvironmentLocationsResponse)result;

                        DataModel.InstallationConfiguration.PowerApps.Locations = response.Value.Select(x => x.Name).ToList();

                        string defaultLocation = DataModel.InstallationConfiguration.PowerApps.Locations.Where(x => string.Compare(x, _defaultLocation, StringComparison.Ordinal) == 0).FirstOrDefault();

                        DataModel.InstallationConfiguration.PowerApps.SelectedLocation =
                            defaultLocation != null ?
                            defaultLocation :
                            DataModel.InstallationConfiguration.PowerApps.Locations.FirstOrDefault();
                    },
                    ExceptionHandler = (ex) =>
                    {
                        DataModel.StatusMessage = "Failed to acquire PowerApps environment locations!";
                    },
                });

                singleRunner.RunOperations();
            });
        }
        /// <summary>
        /// Gets available environment locations.
        /// </summary>
        /// <returns>Information regarding the available environment locations.</returns>
        public async Task <GetPowerAppsEnvironmentLocationsResponse> GetEnvironmentLocationsAsync()
        {
            LogInformation("Acquiring access token...");
            IHttpClient httpClient = TokenProvider.GetHttpClient(Audience);

            LogInformation("Acquiring PowerApps environment locations...");
            HttpResponseMessage response = await httpClient.GetAsync(_getEnvironmentLocationsUri);

            GetPowerAppsEnvironmentLocationsResponse result = null;

            if (response.IsSuccessStatusCode)
            {
                result = JsonConvert.DeserializeObject <GetPowerAppsEnvironmentLocationsResponse>(await response.Content.ReadAsStringAsync());
            }
            else
            {
                LogError($"ERROR: ({response.StatusCode}) {response.ReasonPhrase}");
                throw new RequestException(response);
            }

            return(result);
        }