Example #1
0
        public static T GetServiceClient <T>() where T : class
        {
            var factory         = (TestEnvironmentFactory) new CSMTestEnvironmentFactory();
            var testEnvironment = factory.GetTestEnvironment();

            ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler;

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

            if (testEnvironment.UsesCustomUri())
            {
                client = new RecoveryServicesNS.RecoveryServicesManagementClient(
                    "Microsoft.RecoveryServices",
                    credentials,
                    testEnvironment.BaseUri);
            }
            else
            {
                client = new RecoveryServicesNS.RecoveryServicesManagementClient(
                    "Microsoft.RecoveryServices",
                    credentials);
            }
            return(GetServiceClient <T>(factory, client));
        }
Example #2
0
        public static T GetServiceClient <T>(
            TestEnvironmentFactory factory,
            RecoveryServicesNS.RecoveryServicesManagementClient 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)0);
                    property2.SetValue((object)obj2, (object)0);
                }
            }
            return(obj2);
        }