Exemplo n.º 1
0
        protected void SetupManagementClients()
        {
            BackupVaultServicesMgmtClient = GetBackupVaultServicesManagementClient();
            BackupServicesMgmtClient      = GetBackupServicesManagementClient();

            helper.SetupSomeOfManagementClients(BackupVaultServicesMgmtClient, BackupServicesMgmtClient);
        }
        public static T GetServiceClient <T>() where T : class
        {
            var factory = (TestEnvironmentFactory) new CSMTestEnvironmentFactory();

            var testEnvironment = factory.GetTestEnvironment();

            ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler;

            var credentials = new SubscriptionCredentialsAdapter(
                testEnvironment.AuthorizationContext.TokenCredentials[TokenAudience.Management],
                testEnvironment.SubscriptionId);

            if (typeof(T) == typeof(BackupVaultServicesManagementClient))
            {
                BackupVaultServicesManagementClient client;

                if (testEnvironment.UsesCustomUri())
                {
                    client = new BackupVaultServicesManagementClient(
                        credentials,
                        testEnvironment.BaseUri);
                }

                else
                {
                    client = new BackupVaultServicesManagementClient(
                        credentials);
                }

                return(GetServiceClient <T>(factory, client));
            }
            else
            {
                BackupServicesManagementClient client;

                if (testEnvironment.UsesCustomUri())
                {
                    client = new BackupServicesManagementClient(
                        credentials,
                        testEnvironment.BaseUri);
                }

                else
                {
                    client = new BackupServicesManagementClient(
                        credentials);
                }

                return(GetVaultServiceClient <T>(factory, client));
            }
        }
Exemplo n.º 3
0
        public static T GetServiceClient <T>() where T : class
        {
            var factory = (TestEnvironmentFactory) new CSMTestEnvironmentFactory();

            var testEnvironment = factory.GetTestEnvironment();

            ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler;

            if (typeof(T) == typeof(BackupVaultServicesManagementClient))
            {
                BackupVaultServicesManagementClient client;

                if (testEnvironment.UsesCustomUri())
                {
                    client = new BackupVaultServicesManagementClient(
                        testEnvironment.Credentials as SubscriptionCloudCredentials,
                        testEnvironment.BaseUri);
                }

                else
                {
                    client = new BackupVaultServicesManagementClient(
                        testEnvironment.Credentials as SubscriptionCloudCredentials);
                }

                return(GetServiceClient <T>(factory, client));
            }
            else
            {
                BackupServicesManagementClient client;

                if (testEnvironment.UsesCustomUri())
                {
                    client = new BackupServicesManagementClient(
                        testEnvironment.Credentials as SubscriptionCloudCredentials,
                        testEnvironment.BaseUri);
                }

                else
                {
                    client = new BackupServicesManagementClient(
                        testEnvironment.Credentials as SubscriptionCloudCredentials);
                }

                return(GetVaultServiceClient <T>(factory, client));
            }
        }
        void ListContainersByFriendlyNameAndStatusReturnsValidResponse()
        {
            using (UndoContext undoContext = UndoContext.Current)
            {
                undoContext.Start();

                BackupServicesManagementClient client = GetServiceClient <BackupServicesManagementClient>();

                string containerId           = ConfigurationManager.AppSettings["BMSContainerId"];
                string friendlyName          = ConfigurationManager.AppSettings["BMSContainerFriendlyName"];
                string name                  = ConfigurationManager.AppSettings["BMSContainerName"];
                string containerType         = ConfigurationManager.AppSettings["BMSContainerType"];
                string containerStatus       = ConfigurationManager.AppSettings["BMSContainerStatus"];
                string containerHealthStatus = ConfigurationManager.AppSettings["BMSContainerHealthStatus"];
                string containerParentId     = ConfigurationManager.AppSettings["BMSContainerParentId"];

                ContainerQueryParameters parameters = new ContainerQueryParameters();
                parameters.ContainerType = containerType;
                parameters.FriendlyName  = friendlyName;
                parameters.Status        = containerStatus;

                CSMContainerListOperationResponse response = client.Container.List(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, parameters, GetCustomRequestHeaders());

                // Response Validation
                Assert.NotNull(response);
                Assert.True(response.StatusCode == HttpStatusCode.OK, "Status code should be OK");
                Assert.NotNull(response.CSMContainerListResponse);

                // Basic Validation
                Assert.True(response.CSMContainerListResponse.Value.Any(container =>
                {
                    return(container.Id == containerId &&
                           string.Equals(container.Name, name, StringComparison.OrdinalIgnoreCase) &&
                           container.Properties != null &&
                           container.Properties.ContainerType == containerType &&
                           string.Equals(container.Properties.FriendlyName, friendlyName, StringComparison.OrdinalIgnoreCase) &&
                           container.Properties.HealthStatus == containerHealthStatus &&
                           container.Properties.ParentContainerId == containerParentId &&
                           container.Properties.Status == containerStatus);
                }), "Obtained container list doesn't contain the input container");
            }
        }
Exemplo n.º 5
0
        public static T GetVaultServiceClient <T>(TestEnvironmentFactory factory, BackupServicesManagementClient client) where T : class
        {
            TestEnvironment testEnvironment = factory.GetTestEnvironment();

            HttpMockServer instance;

            try
            {
                instance = HttpMockServer.CreateInstance();
            }
            catch (ApplicationException)
            {
                HttpMockServer.Initialize("TestEnvironment", "InitialCreation");
                instance = HttpMockServer.CreateInstance();
            }
            T obj2 = typeof(T).GetMethod("WithHandler", new Type[1]
            {
                typeof(DelegatingHandler)
            }).Invoke((object)client, new object[1]
            {
                (object)instance
            }) as T;

            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                HttpMockServer.Variables[TestEnvironment.SubscriptionIdKey] = testEnvironment.SubscriptionId;
            }

            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                PropertyInfo property1 = typeof(T).GetProperty("LongRunningOperationInitialTimeout", typeof(int));
                PropertyInfo property2 = typeof(T).GetProperty("LongRunningOperationRetryTimeout", typeof(int));
                if (property1 != (PropertyInfo)null && property2 != (PropertyInfo)null)
                {
                    property1.SetValue((object)obj2, (object)-1);
                    property2.SetValue((object)obj2, (object)-1);
                }
            }
            return(obj2);
        }