public void OperationCheckNameNotAvailableValidateMessage()
        {
            var checknameResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                                                'nameAvailable': false,
                                                'reason': 'The name is not available.',
                                                'message': 'The name is not available in the region.'
                                            }")
            };

            checknameResponse.Headers.Add("x-ms-request-id", "1");

            // all accounts under sub and empty next link
            var handler = new RecordedDelegatingHandler(checknameResponse)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            var result = client.Servers.CheckNameAvailability("West US", new CheckServerNameAvailabilityParameters("azsdktest", "Microsoft.AnalysisServices/servers"));

            // Validate headers
            Assert.Equal(HttpMethod.Post, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            Assert.False(result.NameAvailable);
            Assert.NotEmpty(result.Message);
            Assert.NotEmpty(result.Reason);
        }
        public void OperationStatusesValidateMessage()
        {
            var opearationStatusesResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                                                'id': '/subscriptions/id/locations/westus/operationstatuses/testoperationid',
                                                'name': 'testoperationid',
                                                'startTime': '2017-01-01T13:13:13.933Z',
                                                'status': 'Running'
                                            }")
            };

            opearationStatusesResponse.Headers.Add("x-ms-request-id", "1");

            // all accounts under sub and empty next link
            var handler = new RecordedDelegatingHandler(opearationStatusesResponse)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            var result = client.Servers.ListOperationStatuses("West US", "/subscriptions/id/locations/westus/operationstatuses/testoperationid");

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            Assert.Equal("/subscriptions/id/locations/westus/operationstatuses/testoperationid", result.Id);
            Assert.NotEmpty(result.Name);
            Assert.NotEmpty(result.StartTime);
            Assert.NotEmpty(result.Status);
        }
        public void ServerGetDetailsThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            Assert.Throws <ValidationException>(() => client.Servers.GetDetails("foo", null));
            Assert.Throws <ValidationException>(() => client.Servers.GetDetails(null, "bar"));
            Assert.Throws <ValidationException>(() => client.Servers.GetDetails("invalid+", "server"));
            Assert.Throws <ValidationException>(() => client.Servers.GetDetails("rg", "invalid%"));
            Assert.Throws <ValidationException>(() => client.Servers.GetDetails("rg", "/invalid"));
        }
        public void ServerUpdateThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            Assert.Throws <ValidationException>(() => client.Servers.Update(null, "bar", new AnalysisServicesServerUpdateParameters()));
            Assert.Throws <ValidationException>(() => client.Servers.Update("foo", null, new AnalysisServicesServerUpdateParameters()));
            Assert.Throws <ValidationException>(() => client.Servers.Update("foo", "bar", null));
            Assert.Throws <ValidationException>(() => client.Servers.Update("rg", "invalid%", new AnalysisServicesServerUpdateParameters()));
            Assert.Throws <ValidationException>(() => client.Servers.Update("rg", "/invalid", new AnalysisServicesServerUpdateParameters()));
            Assert.Throws <ValidationException>(() => client.Servers.Update("rg", "s", new AnalysisServicesServerUpdateParameters()));
            Assert.Throws <ValidationException>(() => client.Servers.Update("rg", "server_name_that_is_too_long", new AnalysisServicesServerUpdateParameters()));
        }
        public void ServerDeleteValidateMessage()
        {
            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"")
            };

            var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { okResponse });

            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            client.Servers.Delete("resGroup", "server");

            // Validate headers
            Assert.Equal(HttpMethod.Delete, handler.Requests[0].Method);
        }
        public void ServerDeleteNoContentValidateMessage()
        {
            var noContentResponse = new HttpResponseMessage(HttpStatusCode.NoContent)
            {
                Content = new StringContent(@"")
            };

            noContentResponse.Headers.Add("x-ms-request-id", "1");

            var handler = new RecordedDelegatingHandler(noContentResponse);

            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            client.Servers.Delete("resGroup", "server");

            // Validate headers
            Assert.Equal(HttpMethod.Delete, handler.Requests[0].Method);
        }
        public void ServerDeleteNotFoundValidateMessage()
        {
            var notFoundResponse = new HttpResponseMessage(HttpStatusCode.NotFound)
            {
                Content = new StringContent(@"")
            };

            var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { notFoundResponse });

            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            var result = Assert.Throws <CloudException>(() => Task.Factory.StartNew(() =>
                                                                                    client.Servers.DeleteWithHttpMessagesAsync(
                                                                                        "resGroup",
                                                                                        "server")).Unwrap().GetAwaiter().GetResult());

            // Validate headers
            Assert.Equal(HttpMethod.Delete, handler.Requests[0].Method);
            Assert.Equal(HttpStatusCode.NotFound, result.Response.StatusCode);
        }
        public void ServerCreateSyncValidateMessage()
        {
            var acceptedResponse = new HttpResponseMessage(HttpStatusCode.Created)
            {
                Content = new StringContent(AnalysisServicesTestUtilities.GetDefaultCreatedResponse("Provisioning", "Provisioning"))
            };

            acceptedResponse.Headers.Add("x-ms-request-id", "1");
            acceptedResponse.Headers.Add("Location", @"http://someLocationURL");

            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(AnalysisServicesTestUtilities.GetDefaultCreatedResponse("Succeeded", "Succeeded"))
            };

            var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { acceptedResponse, okResponse });

            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);
            AnalysisServicesServer           analysisServicesResource = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource();

            var result = client.Servers.Create(
                AnalysisServicesTestUtilities.DefaultResourceGroup,
                AnalysisServicesTestUtilities.DefaultServerName,
                analysisServicesResource
                );

            // Validate headers - User-Agent for certs, Authorization for tokens
            Assert.Equal(HttpMethod.Put, handler.Requests[0].Method);
            Assert.NotNull(handler.Requests[0].Headers.GetValues("User-Agent"));

            // Validate result
            Assert.Equal(result.Location, AnalysisServicesTestUtilities.DefaultLocation);
            Assert.NotEmpty(result.ServerFullName);
            Assert.Equal("Succeeded", result.ProvisioningState);
            Assert.Equal("Succeeded", result.State);
            Assert.Equal(2, result.Tags.Count);
            Assert.Equal(result.BackupBlobContainerUri, AnalysisServicesTestUtilities.DefaultBackupBlobContainerUri);
        }
        public void OperationResultRunningValidateMessage()
        {
            var acceptedResponse = new HttpResponseMessage(HttpStatusCode.Accepted)
            {
                Content = new StringContent(@"")
            };

            acceptedResponse.Headers.Add("x-ms-request-id", "1");

            // all accounts under sub and empty next link
            var handler = new RecordedDelegatingHandler(acceptedResponse)
            {
                StatusCodeToReturn = HttpStatusCode.Accepted
            };
            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            client.Servers.ListOperationResults("West US", "/subscriptions/id/locations/westus/operationstatuses/testoperationid");

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            Assert.Equal(HttpStatusCode.Accepted, handler.StatusCodeToReturn);
        }
        public void ServerUpdateValidateMessage()
        {
            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(AnalysisServicesTestUtilities.GetDefaultCreatedResponse("Succeeded", "Succeeded"))
            };

            var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { okResponse });

            AnalysisServicesManagementClient       client           = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);
            AnalysisServicesServerUpdateParameters updateParameters = new AnalysisServicesServerUpdateParameters()
            {
                Sku                    = AnalysisServicesTestUtilities.DefaultSku,
                Tags                   = AnalysisServicesTestUtilities.DefaultTags,
                AsAdministrators       = new ServerAdministrators(AnalysisServicesTestUtilities.DefaultAdministrators),
                BackupBlobContainerUri = AnalysisServicesTestUtilities.DefaultBackupBlobContainerUri
            };

            var result = client.Servers.Update(
                AnalysisServicesTestUtilities.DefaultResourceGroup,
                AnalysisServicesTestUtilities.DefaultServerName,
                updateParameters
                );

            // Validate headers - User-Agent for certs, Authorization for tokens
            Assert.Equal(new HttpMethod("PATCH"), handler.Requests[0].Method);
            Assert.NotNull(handler.Requests[0].Headers.GetValues("User-Agent"));

            // Validate result
            Assert.Equal(result.Location, AnalysisServicesTestUtilities.DefaultLocation);
            Assert.NotEmpty(result.ServerFullName);
            Assert.Equal("Succeeded", result.ProvisioningState);
            Assert.Equal("Succeeded", result.State);
            Assert.Equal(2, result.Tags.Count);
            Assert.Equal(result.BackupBlobContainerUri, AnalysisServicesTestUtilities.DefaultBackupBlobContainerUri);
        }
Beispiel #11
0
        public void CreateServerWithGatewayTest()
        {
            string executingAssemblyPath = typeof(AnalysisServices.Tests.ScenarioTests.ServerOperationsTests).GetTypeInfo().Assembly.Location;

            HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords");

            using (var context = MockContext.Start(this.GetType()))
            {
                var client = this.GetAnalysisServicesClient(context);

                AnalysisServicesServer analysisServicesServer = AnalysisServicesTestUtilities.GetAnalysisServicesResourceWithGateway();
                AnalysisServicesServer resultCreate           = null;
                try
                {
                    // Create a test server
                    resultCreate =
                        client.Servers.Create(
                            AnalysisServicesTestUtilities.DefaultResourceGroup,
                            AnalysisServicesTestUtilities.DefaultServerName,
                            analysisServicesServer);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Assert.Equal("Succeeded", resultCreate.ProvisioningState);
                Assert.Equal("Succeeded", resultCreate.State);

                // get the server and ensure that all the values are properly set.
                var resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // validate the server creation process
                Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name);
                Assert.NotEmpty(resultGet.ServerFullName);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(1, resultGet.AsAdministrators.Members.Count);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultBackupBlobContainerUri.Split('?')[0], resultGet.BackupBlobContainerUri);
                Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type);

                // Confirm that the server creation did succeed
                Assert.True(resultGet.ProvisioningState == "Succeeded");
                Assert.True(resultGet.State == "Succeeded");

                // List gateway status.
                var listGatewayStatus = client.Servers.ListGatewayStatus(AnalysisServicesTestUtilities.DefaultResourceGroup,
                                                                         AnalysisServicesTestUtilities.DefaultServerName);

                Assert.Equal(Status.Live, listGatewayStatus.Status);

                // Dissociate gateway.
                client.Servers.DissociateGateway(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // List gateway status again.
                try
                {
                    listGatewayStatus = client.Servers.ListGatewayStatus(AnalysisServicesTestUtilities.DefaultResourceGroup,
                                                                         AnalysisServicesTestUtilities.DefaultServerName);
                }
                catch (GatewayListStatusErrorException gatewayException)
                {
                    Assert.Equal(HttpStatusCode.BadRequest, gatewayException.Response.StatusCode);
                    var errorResponse   = gatewayException.Body.Error;
                    var expectedMessage = string.Format("A unified gateway is not associated with server {0}.", AnalysisServicesTestUtilities.DefaultServerName);
                    Assert.Equal("GatewayNotAssociated", errorResponse.Code);
                    Assert.Equal(expectedMessage, errorResponse.Message);
                }

                // delete the server with its old name, which should also succeed.
                client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // test that the server is gone
                // now list by resource group:
                var listResponse = client.Servers.ListByResourceGroup(AnalysisServicesTestUtilities.DefaultResourceGroup);

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Count() >= 0);
            }
        }
Beispiel #12
0
        public void FirewallTest()
        {
            string executingAssemblyPath = typeof(AnalysisServices.Tests.ScenarioTests.ServerOperationsTests).GetTypeInfo().Assembly.Location;

            HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords");
            var s1SKU = "S1";
            var sampleIPV4FirewallSetting = new IPv4FirewallSettings()
            {
                EnablePowerBIService = "True",
                FirewallRules        = new List <IPv4FirewallRule>()
                {
                    new IPv4FirewallRule()
                    {
                        FirewallRuleName = "rule1",
                        RangeStart       = "0.0.0.0",
                        RangeEnd         = "255.255.255.255"
                    },
                    new IPv4FirewallRule()
                    {
                        FirewallRuleName = "rule2",
                        RangeStart       = "7.7.7.7",
                        RangeEnd         = "8.8.8.8"
                    },
                }
            };

            using (var context = MockContext.Start(this.GetType()))
            {
                var client = this.GetAnalysisServicesClient(context);

                AnalysisServicesServer             analysisServicesServer = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource();
                SkuEnumerationForNewResourceResult skusListForNew         = client.Servers.ListSkusForNew();
                analysisServicesServer.Sku = skusListForNew.Value.Where((s) => s.Name == s1SKU).First();
                analysisServicesServer.IpV4FirewallSettings = sampleIPV4FirewallSetting;

                AnalysisServicesServer resultCreate = null;
                try
                {
                    Console.Out.Write(analysisServicesServer.Sku.Capacity);
                    // Create a test server
                    resultCreate =
                        client.Servers.Create(
                            AnalysisServicesTestUtilities.DefaultResourceGroup,
                            AnalysisServicesTestUtilities.DefaultServerName,
                            analysisServicesServer);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Assert.Equal("Succeeded", resultCreate.ProvisioningState);
                Assert.Equal("Succeeded", resultCreate.State);

                // get the server and ensure that all the values are properly set.
                var resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // validate the server creation process
                Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name);
                Assert.NotEmpty(resultGet.ServerFullName);
                Assert.Equal(analysisServicesServer.Sku.Name, resultGet.Sku.Name);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(2, resultGet.AsAdministrators.Members.Count);
                Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type);
                Assert.Equal(sampleIPV4FirewallSetting.EnablePowerBIService, resultGet.IpV4FirewallSettings.EnablePowerBIService);
                Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.Count(), resultGet.IpV4FirewallSettings.FirewallRules.Count());
                Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().FirewallRuleName, resultGet.IpV4FirewallSettings.FirewallRules.First().FirewallRuleName);
                Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().RangeStart, resultGet.IpV4FirewallSettings.FirewallRules.First().RangeStart);
                Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().RangeEnd, resultGet.IpV4FirewallSettings.FirewallRules.First().RangeEnd);

                // Confirm that the server creation did succeed
                Assert.True(resultGet.ProvisioningState == "Succeeded");
                Assert.True(resultGet.State == "Succeeded");

                // Update firewall and verify
                ResourceSku newSku = resultGet.Sku;
                sampleIPV4FirewallSetting.EnablePowerBIService = "False";
                sampleIPV4FirewallSetting.FirewallRules        = new List <IPv4FirewallRule>()
                {
                    new IPv4FirewallRule()
                    {
                        FirewallRuleName = "rule3",
                        RangeStart       = "6.6.6.6",
                        RangeEnd         = "255.255.255.255"
                    }
                };

                AnalysisServicesServerUpdateParameters updateParameters = new AnalysisServicesServerUpdateParameters()
                {
                    IpV4FirewallSettings = sampleIPV4FirewallSetting
                };

                var resultUpdate = client.Servers.Update(
                    AnalysisServicesTestUtilities.DefaultResourceGroup,
                    AnalysisServicesTestUtilities.DefaultServerName,
                    updateParameters);

                Assert.Equal("Succeeded", resultUpdate.ProvisioningState);
                Assert.Equal("Succeeded", resultUpdate.State);

                // get the server and ensure that all the values are properly set.
                resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // validate the server creation process
                Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name);
                Assert.NotEmpty(resultGet.ServerFullName);
                Assert.Equal(newSku.Name, resultGet.Sku.Name);
                Assert.Equal(newSku.Tier, resultGet.Sku.Tier);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(2, resultGet.AsAdministrators.Members.Count);
                Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type);
                Assert.Equal(1, resultGet.Sku.Capacity);
                Assert.Equal(sampleIPV4FirewallSetting.EnablePowerBIService, resultGet.IpV4FirewallSettings.EnablePowerBIService);
                Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.Count(), resultGet.IpV4FirewallSettings.FirewallRules.Count());
                Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().FirewallRuleName, resultGet.IpV4FirewallSettings.FirewallRules.First().FirewallRuleName);
                Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().RangeStart, resultGet.IpV4FirewallSettings.FirewallRules.First().RangeStart);
                Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().RangeEnd, resultGet.IpV4FirewallSettings.FirewallRules.First().RangeEnd);

                // delete the server with its old name, which should also succeed.
                client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);
            }
        }
Beispiel #13
0
        public void ScaleOutTest()
        {
            string executingAssemblyPath = typeof(AnalysisServices.Tests.ScenarioTests.ServerOperationsTests).GetTypeInfo().Assembly.Location;

            HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords");
            var defaultScaleOutCap = 2;
            var s1SKU = "S1";

            using (var context = MockContext.Start(this.GetType()))
            {
                var client = this.GetAnalysisServicesClient(context);

                AnalysisServicesServer             analysisServicesServer = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource();
                SkuEnumerationForNewResourceResult skusListForNew         = client.Servers.ListSkusForNew();
                analysisServicesServer.Sku          = skusListForNew.Value.Where((s) => s.Name == s1SKU).First();
                analysisServicesServer.Sku.Capacity = defaultScaleOutCap;

                AnalysisServicesServer resultCreate = null;
                try
                {
                    // Create a test server
                    resultCreate =
                        client.Servers.Create(
                            AnalysisServicesTestUtilities.DefaultResourceGroup,
                            AnalysisServicesTestUtilities.DefaultServerName,
                            analysisServicesServer);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Assert.Equal("Succeeded", resultCreate.ProvisioningState);
                Assert.Equal("Succeeded", resultCreate.State);

                // get the server and ensure that all the values are properly set.
                var resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // validate the server creation process
                Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name);
                Assert.NotEmpty(resultGet.ServerFullName);
                Assert.Equal(analysisServicesServer.Sku.Name, resultGet.Sku.Name);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(2, resultGet.AsAdministrators.Members.Count);
                Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type);
                Assert.Equal(2, resultGet.Sku.Capacity);

                // Confirm that the server creation did succeed
                Assert.True(resultGet.ProvisioningState == "Succeeded");
                Assert.True(resultGet.State == "Succeeded");

                // Scale in the server and verify
                ResourceSku newSku = resultGet.Sku;
                newSku.Capacity = 1;

                AnalysisServicesServerUpdateParameters updateParameters = new AnalysisServicesServerUpdateParameters()
                {
                    Sku = newSku
                };

                var resultUpdate = client.Servers.Update(
                    AnalysisServicesTestUtilities.DefaultResourceGroup,
                    AnalysisServicesTestUtilities.DefaultServerName,
                    updateParameters);

                Assert.Equal("Succeeded", resultUpdate.ProvisioningState);
                Assert.Equal("Succeeded", resultUpdate.State);
                Assert.Equal(1, resultUpdate.Sku.Capacity);

                // get the server and ensure that all the values are properly set.
                resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // validate the server creation process
                Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name);
                Assert.NotEmpty(resultGet.ServerFullName);
                Assert.Equal(newSku.Name, resultGet.Sku.Name);
                Assert.Equal(newSku.Tier, resultGet.Sku.Tier);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(2, resultGet.AsAdministrators.Members.Count);
                Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type);
                Assert.Equal(1, resultGet.Sku.Capacity);

                // delete the server with its old name, which should also succeed.
                client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);
            }
        }
Beispiel #14
0
        public void CreateGetUpdateDeleteTest()
        {
            string executingAssemblyPath = typeof(AnalysisServices.Tests.ScenarioTests.ServerOperationsTests).GetTypeInfo().Assembly.Location;

            HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords");

            using (var context = MockContext.Start(this.GetType()))
            {
                var client = this.GetAnalysisServicesClient(context);

                AnalysisServicesServer analysisServicesServer = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource();
                AnalysisServicesServer resultCreate           = null;
                try
                {
                    // Create a test server
                    resultCreate =
                        client.Servers.Create(
                            AnalysisServicesTestUtilities.DefaultResourceGroup,
                            AnalysisServicesTestUtilities.DefaultServerName,
                            analysisServicesServer);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Assert.Equal("Succeeded", resultCreate.ProvisioningState);
                Assert.Equal("Succeeded", resultCreate.State);

                // get the server and ensure that all the values are properly set.
                var resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // validate the server creation process
                Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name);
                Assert.NotEmpty(resultGet.ServerFullName);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(2, resultGet.AsAdministrators.Members.Count);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultBackupBlobContainerUri.Split('?')[0], resultGet.BackupBlobContainerUri);
                Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type);

                // Confirm that the server creation did succeed
                Assert.True(resultGet.ProvisioningState == "Succeeded");
                Assert.True(resultGet.State == "Succeeded");

                // List gateway status of the provisioned server will return error since no gateway is configured on the server.
                try
                {
                    var listGatewayStatus = client.Servers.ListGatewayStatus(AnalysisServicesTestUtilities.DefaultResourceGroup,
                                                                             AnalysisServicesTestUtilities.DefaultServerName);
                }
                catch (GatewayListStatusErrorException gatewayException)
                {
                    Assert.Equal(HttpStatusCode.BadRequest, gatewayException.Response.StatusCode);
                    var errorResponse   = gatewayException.Body.Error;
                    var expectedMessage = string.Format("A unified gateway is not associated with server {0}.", AnalysisServicesTestUtilities.DefaultServerName);
                    Assert.Equal("GatewayNotAssociated", errorResponse.Code);
                    Assert.Equal(expectedMessage, errorResponse.Message);
                }

                // List gateway status of non-existing server will return error since resource not found.
                const string notexistingServerName = "notexistingserver";
                try
                {
                    var listGatewayStatus = client.Servers.ListGatewayStatus(AnalysisServicesTestUtilities.DefaultResourceGroup, notexistingServerName);
                }
                catch (GatewayListStatusErrorException gatewayException)
                {
                    Assert.Equal(HttpStatusCode.NotFound, gatewayException.Response.StatusCode);
                    var errorResponse   = gatewayException.Body.Error;
                    var expectedMessage = string.Format("The Resource 'Microsoft.AnalysisServices/servers/{0}' under resource group '{1}' was not found.",
                                                        notexistingServerName, AnalysisServicesTestUtilities.DefaultResourceGroup);
                    Assert.Equal("ResourceNotFound", errorResponse.Code);
                    Assert.Equal(expectedMessage, errorResponse.Message);
                }

                // Update the server and confirm the updates make it in.
                Dictionary <string, string> updatedTags = new Dictionary <string, string>
                {
                    { "updated1", "value1" }
                };

                var updatedAdministrators = AnalysisServicesTestUtilities.DefaultAdministrators;
                updatedAdministrators.Add("*****@*****.**");

                AnalysisServicesServerUpdateParameters updateParameters = new AnalysisServicesServerUpdateParameters()
                {
                    Sku                    = resultGet.Sku,
                    Tags                   = updatedTags,
                    AsAdministrators       = new ServerAdministrators(updatedAdministrators),
                    BackupBlobContainerUri = AnalysisServicesTestUtilities.UpdatedBackupBlobContainerUri
                };

                AnalysisServicesServer resultUpdate = null;
                try
                {
                    resultUpdate =
                        client.Servers.Update(
                            AnalysisServicesTestUtilities.DefaultResourceGroup,
                            AnalysisServicesTestUtilities.DefaultServerName,
                            updateParameters);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Assert.Equal("Succeeded", resultUpdate.ProvisioningState);
                Assert.Equal("Succeeded", resultUpdate.State);

                // get the server and ensure that all the values are properly set.
                resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // validate the server creation process
                Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name);
                Assert.Equal(1, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("updated1"));
                Assert.Equal(3, resultGet.AsAdministrators.Members.Count);
                Assert.Equal(AnalysisServicesTestUtilities.UpdatedBackupBlobContainerUri.Split('?')[0], resultGet.BackupBlobContainerUri);

                // Create another server and ensure that list account returns both
                var secondServer = AnalysisServicesTestUtilities.DefaultServerName + '2';
                resultCreate = client.Servers.Create(
                    AnalysisServicesTestUtilities.DefaultResourceGroup,
                    secondServer,
                    analysisServicesServer);

                resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer);

                var listResponse = client.Servers.List();

                // Assert that there are at least two servers in the list
                Assert.True(listResponse.Count() >= 2);

                // now list by resource group:
                listResponse = client.Servers.ListByResourceGroup(AnalysisServicesTestUtilities.DefaultResourceGroup);

                // Assert that there are at least two servers in the list
                Assert.True(listResponse.Count() >= 2);

                // Suspend the server and confirm that it is deleted.
                client.Servers.Suspend(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer);

                // get the server and ensure that all the values are properly set.
                resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer);

                Assert.Equal("Paused", resultGet.ProvisioningState);
                Assert.Equal("Paused", resultGet.State);

                // Suspend the server and confirm that it is deleted.
                client.Servers.Resume(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer);

                // get the server and ensure that all the values are properly set.
                resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer);

                Assert.Equal("Succeeded", resultGet.ProvisioningState);
                Assert.Equal("Succeeded", resultGet.State);

                // Delete the server and confirm that it is deleted.
                client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer);

                // delete the server again and make sure it continues to result in a succesful code.
                client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer);

                // delete the server with its old name, which should also succeed.
                client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName);

                // test that the server is gone
                // now list by resource group:
                listResponse = client.Servers.ListByResourceGroup(AnalysisServicesTestUtilities.DefaultResourceGroup);

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Count() >= 0);
            }
        }
        private static void VerifyServerCreationSuccess(AnalysisServicesServer createdResource)
        {
            AnalysisServicesServer defaultResource = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource();

            VerifyServersEqual(createdResource, defaultResource);
        }
        public void ServerListByResourceGroupValidateMessage()
        {
            var serverDetailsResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                                'value': [
                                {
                                    'id': '/subscriptions/613192d9-5973f-477a-9cfe-4efc3ee2bd60/resourceGroups/TestRG/providers/Microsoft.AnalysisServices/servers/server1',
                                    'name': 'server1',
                                    'type': 'Microsoft.AnalysisServices/servers',
                                    'location': 'West US',
                                    'sku': {
                                        'name': 'S1',
                                        'tier': 'Standard'
                                    },
                                    'tags': {
                                        'Key1': 'Value1',
                                        'Key2': 'Value2'
                                    },
                                    'properties': {
                                        'state': 'Succeeded',
                                        'provisioningState': 'Succeeded',
                                        'serverFullName': 'asazure://stabletest.asazure-int.windows.net/server1',
                                        'asAdministrators': {
                                            'members': [
                                                '*****@*****.**',
                                                '*****@*****.**'
                                            ]
                                        },
                                        'backupBlobContainerUri' : 'https://aassdk1.blob.core.windows.net/azsdktest?dummykey1'
                                    }
                                },
                                {
                                    'id': '/subscriptions/613192d9-5973f-477a-9cfe-4efc3ee2bd60/resourceGroups/TestRG/providers/Microsoft.AnalysisServices/servers/server2',
                                    'name': 'server2',
                                    'type': 'Microsoft.AnalysisServices/servers',
                                    'location': 'West US',
                                    'sku': {
                                        'name': 'S1',
                                        'tier': 'Standard'
                                    },
                                    'tags': {
                                        'Key1': 'Value1',
                                        'Key2': 'Value2'
                                    },
                                    'properties': {
                                        'state': 'Succeeded',
                                        'provisioningState': 'Succeeded',
                                        'serverFullName': 'asazure://stabletest.asazure-int.windows.net/server2',
                                        'asAdministrators': {
                                            'members': [
                                                '*****@*****.**',
                                                '*****@*****.**'
                                            ]
                                        },
                                        'backupBlobContainerUri' : 'https://aassdk1.blob.core.windows.net/azsdktest2?dummykey2'
                                    }
                                }
                                ]
                            }")
            };

            serverDetailsResponse.Headers.Add("x-ms-request-id", "1");

            // all accounts under sub and empty next link
            var handler = new RecordedDelegatingHandler(serverDetailsResponse)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler);

            var result = client.Servers.ListByResourceGroup(AnalysisServicesTestUtilities.DefaultResourceGroup);

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // Validate result
            Assert.Equal(2, result.Count());

            var server1 = result.ElementAt(0);

            Assert.Equal("West US", server1.Location);
            Assert.Equal("server1", server1.Name);
            Assert.Equal("/subscriptions/613192d9-5973f-477a-9cfe-4efc3ee2bd60/resourceGroups/TestRG/providers/Microsoft.AnalysisServices/servers/server1", server1.Id);
            Assert.NotEmpty(server1.ServerFullName);
            Assert.True(server1.Tags.ContainsKey("Key1"));

            var server2 = result.ElementAt(1);

            Assert.Equal("West US", server1.Location);
            Assert.Equal("server1", server1.Name);
            Assert.Equal("/subscriptions/613192d9-5973f-477a-9cfe-4efc3ee2bd60/resourceGroups/TestRG/providers/Microsoft.AnalysisServices/servers/server2", server2.Id);
            Assert.NotEmpty(server2.ServerFullName);
            Assert.True(server2.Tags.ContainsKey("Key1"));
        }