예제 #1
0
        private object CreatePowerAppsEnvironmentAsync(OperationRunner context)
        {
            PowerAppsClient client = new PowerAppsClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.CreateEnvironmentAsync(new CreatePowerAppsEnvironmentRequest()
            {
                Location = DataModel.InstallationConfiguration.PowerApps.SelectedLocation,
                Properties = new NewPowerAppsEnvironmentProperties()
                {
                    DisplayName = DataModel.InstallationConfiguration.PowerApps.EnvironmentDisplayName,
                    EnvironmentSku = DataModel.InstallationConfiguration.PowerApps.SelectedSku,
                },
            }).Result);
        }
        public void CreateEnvironmentAsyncSuccess()
        {
            string expectedEnvironmentName = Guid.NewGuid().ToString();
            string expectedLocation        = "unitedstates";
            string expectedDisplayName     = "TestEnvironment";
            string expectedSku             = "Trial";
            string expectedRequestUri      = $"https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/scopes/admin/environments?$filter=properties.displayName%20eq%20'{expectedDisplayName}'&api-version=2016-11-01";
            string expectedRequestUri2     = "https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments?api-version=2018-01-01&id=/providers/Microsoft.BusinessAppPlatform/scopes/admin/environments";
            string responseFilePath        = @"./data/templates/responses/powerApps/emptyValueResponse.json";
            string responseFilePath2       = @"./data/templates/responses/powerApps/environment.json";

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

            _httpClient.RegisterExpectedRequest(new ExpectedRequest(expectedRequest));
            HttpRequestMessage expectedRequest2 = TestHelper.CreateHttpRequest(
                HttpMethod.Post,
                expectedRequestUri2);

            _httpClient.RegisterExpectedRequest(new ExpectedRequest(expectedRequest2));

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

            _httpClient.RegisterExpectedResponse(
                expectedRequestUri,
                new ExpectedResponse(expectedResponse));
            HttpResponseMessage expectedResponse2 = TestHelper.CreateHttpResponse(
                HttpStatusCode.OK,
                null,
                responseFilePath2,
                "application/json",
                new Dictionary <string, string>()
            {
                { "environmentName", expectedEnvironmentName },
                { "location", expectedLocation },
                { "displayName", expectedDisplayName },
            });

            _httpClient.RegisterExpectedResponse(
                expectedRequestUri2,
                new ExpectedResponse(expectedResponse2));

            IPowerAppsClient client = new PowerAppsClient(_tokenProvider);

            CreatePowerAppsEnvironmentRequest powerAppsEnv = new CreatePowerAppsEnvironmentRequest()
            {
                Location   = expectedLocation,
                Properties = new NewPowerAppsEnvironmentProperties()
                {
                    DisplayName    = expectedDisplayName,
                    EnvironmentSku = expectedSku,
                },
            };

            CreatePowerAppsEnvironmentResponse response = client.CreateEnvironmentAsync(powerAppsEnv).Result;

            Assert.IsNotNull(response, "The response should not be null!");
            Assert.IsNotNull(response.Properties, "The response Properties member should not be null!");
            Assert.AreEqual(expectedEnvironmentName, response.Name, $"Unexpected name ('{expectedEnvironmentName}' != '{response.Name}')");
            Assert.AreEqual(expectedLocation, response.Location, $"Unexpected location ('{expectedLocation}' != '{response.Location}')");
            Assert.AreEqual(expectedDisplayName, response.Properties.DisplayName, $"Unexpected location ('{expectedDisplayName}' != '{response.Properties.DisplayName}')");
            Assert.AreEqual(expectedDisplayName, response.Properties.DisplayName, $"Unexpected location ('{expectedDisplayName}' != '{response.Properties.DisplayName}')");
            Assert.IsNotNull(response.Properties.LinkedEnvironmentMetadata, "The response Properties.LinkedEnvironmentMetadata member should not be null!");
        }