Example #1
0
        private object CreatePowerAppsCdsDatabaseAsync(OperationRunner context)
        {
            PowerAppsClient client = new PowerAppsClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.CreateCdsDatabase(
                       DataModel.InstallationConfiguration.PowerApps.SelectedEnvironment.EnvironmentName,
                       new CreatePowerAppsCdsDatabaseRequest()
            {
                BaseLanguage = DataModel.InstallationConfiguration.PowerApps.SelectedLanguage.LanguageName,
                Currency = new PowerAppsCdsDatabaseCurrencyMinimal()
                {
                    Code = DataModel.InstallationConfiguration.PowerApps.SelectedCurrency.CurrencyName,
                },
            }));
        }
        public void CreateCdsDatabaseSuccess()
        {
            string expectedEnvironmentName     = Guid.NewGuid().ToString();
            string expectedOperationId         = Guid.NewGuid().ToString();
            string expectedBaseLanguage        = "1033";
            string expectedCurrency            = "USD";
            string expectedLocation            = "unitedstates";
            string expectedDisplayName         = "TestEnvironment";
            string expectedResourceId          = Guid.NewGuid().ToString();
            string expectedFriendlyName        = "TestEnvironment";
            string expectedUniqueName          = "orgtest4";
            string expectedDomainName          = "orgtest5";
            string expectedRequestUri          = $"https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/scopes/admin/environments/{expectedEnvironmentName}?$expand=permissions&api-version=2016-11-01";
            string expectedRequestUri2         = $"https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments/{expectedEnvironmentName}/provisionInstance?api-version=2018-01-01";
            string expectedOperationRequestUri = $"https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments/{expectedEnvironmentName}/provisionOperations/{expectedOperationId}?api-version=2018-01-01";
            string responseFilePath            = @"./data/templates/responses/powerApps/environmentNoCds.json";
            string responseFilePath2           = @"./data/templates/responses/powerApps/environment.json";

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

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

            _httpClient.RegisterExpectedRequest(new ExpectedRequest(expectedRequest2));
            HttpRequestMessage expectedRequest3 = TestHelper.CreateHttpRequest(
                HttpMethod.Get,
                expectedOperationRequestUri);

            _httpClient.RegisterExpectedRequest(new ExpectedRequest(expectedRequest3));
            _httpClient.RegisterExpectedRequest(new ExpectedRequest(expectedRequest3));

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

            _httpClient.RegisterExpectedResponse(
                expectedRequestUri,
                new ExpectedResponse(expectedResponse));
            _httpClient.RegisterExpectedResponse(
                expectedRequestUri,
                new ExpectedResponse(expectedResponse));
            HttpResponseMessage expectedResponse2 = TestHelper.CreateHttpResponse(
                HttpStatusCode.Accepted,
                new Dictionary <string, string>()
            {
                { "Location", expectedOperationRequestUri },
            },
                responseFilePath2,
                "application/json",
                new Dictionary <string, string>()
            {
                { "environmentName", expectedEnvironmentName },
                { "location", expectedLocation },
                { "displayName", expectedDisplayName },
                { "crmResourceId", string.Empty },
                { "crmFriendlyName", string.Empty },
                { "crmUniqueName", string.Empty },
                { "crmDomainName", string.Empty },
            });

            _httpClient.RegisterExpectedResponse(
                expectedRequestUri2,
                new ExpectedResponse(expectedResponse2));
            _httpClient.RegisterExpectedResponse(
                expectedOperationRequestUri,
                new ExpectedResponse(expectedResponse2));
            HttpResponseMessage expectedResponse3 = TestHelper.CreateHttpResponse(
                HttpStatusCode.OK,
                null,
                responseFilePath2,
                "application/json",
                new Dictionary <string, string>()
            {
                { "environmentName", expectedEnvironmentName },
                { "location", expectedLocation },
                { "displayName", expectedDisplayName },
                { "crmResourceId", expectedResourceId },
                { "crmFriendlyName", expectedFriendlyName },
                { "crmUniqueName", expectedUniqueName },
                { "crmDomainName", expectedDomainName },
            });

            _httpClient.RegisterExpectedResponse(
                expectedOperationRequestUri,
                new ExpectedResponse(expectedResponse3));

            IPowerAppsClient client = new PowerAppsClient(_tokenProvider);

            CreatePowerAppsCdsDatabaseRequest cdsDatabase = new CreatePowerAppsCdsDatabaseRequest()
            {
                BaseLanguage = expectedBaseLanguage,
                Currency     = new PowerAppsCdsDatabaseCurrencyMinimal()
                {
                    Code = expectedCurrency,
                },
            };

            PowerAppsEnvironment response = client.CreateCdsDatabase(
                expectedEnvironmentName,
                cdsDatabase);

            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!");
            Assert.AreEqual(expectedResourceId, response.Properties.LinkedEnvironmentMetadata.ResourceId, $"Unexpected resource id ('{expectedResourceId}' != '{response.Properties.LinkedEnvironmentMetadata.ResourceId}')");
            Assert.AreEqual(expectedFriendlyName, response.Properties.LinkedEnvironmentMetadata.FriendlyName, $"Unexpected friendly name ('{expectedFriendlyName}' != '{response.Properties.LinkedEnvironmentMetadata.FriendlyName}')");
            Assert.AreEqual(expectedUniqueName, response.Properties.LinkedEnvironmentMetadata.UniqueName, $"Unexpected unique name ('{expectedUniqueName}' != '{response.Properties.LinkedEnvironmentMetadata.UniqueName}')");
            Assert.AreEqual(expectedDomainName, response.Properties.LinkedEnvironmentMetadata.DomainName, $"Unexpected domain name ('{expectedDomainName}' != '{response.Properties.LinkedEnvironmentMetadata.DomainName}')");
        }