Inheritance: Microsoft.WindowsAzure.Commands.ScenarioTest.Common.TestEnvironmentFactory
Exemple #1
0
        private void SetupAzureEnvironmentFromEnvironmentVariables()
        {
            ServiceManagementTestEnvironmentFactory serviceManagementTestEnvironmentFactory = new ServiceManagementTestEnvironmentFactory();
            TestEnvironment rdfeEnvironment = serviceManagementTestEnvironmentFactory.GetTestEnvironment();
            ResourceManagerTestEnvironmentFactory resourceManagerTestEnvironmentFactory = new ResourceManagerTestEnvironmentFactory();
            TestEnvironment csmEnvironment = resourceManagerTestEnvironmentFactory.GetTestEnvironment();
            string          jwtToken       = csmEnvironment.Credentials != null ?
                                             ((TokenCloudCredentials)csmEnvironment.Credentials).Token : null;

            WindowsAzureProfile.Instance.TokenProvider = new FakeAccessTokenProvider(jwtToken, csmEnvironment.UserName);

            WindowsAzureProfile.Instance.CurrentEnvironment = WindowsAzureProfile.Instance.Environments[testEnvironmentName];

            WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint =
                csmEnvironment.ActiveDirectoryEndpoint.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint =
                csmEnvironment.GalleryUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint =
                csmEnvironment.BaseUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint =
                rdfeEnvironment.BaseUri.AbsoluteUri;

            var newSubscription = new WindowsAzureSubscription(false, false)
            {
                SubscriptionId          = csmEnvironment.SubscriptionId,
                ActiveDirectoryEndpoint =
                    WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint,
                ActiveDirectoryUserId     = csmEnvironment.UserName,
                SubscriptionName          = csmEnvironment.SubscriptionId,
                ServiceEndpoint           = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint),
                ResourceManagerEndpoint   = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint),
                TokenProvider             = WindowsAzureProfile.Instance.TokenProvider,
                GalleryEndpoint           = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint),
                CurrentStorageAccountName = csmEnvironment.StorageAccount,
                IsDefault = true
            };

            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                newSubscription.SetAccessToken(new FakeAccessToken
                {
                    AccessToken = "123",
                    UserId      = csmEnvironment.UserName
                });
            }
            else
            {
                newSubscription.SetAccessToken(WindowsAzureProfile.Instance.TokenProvider.GetNewToken(WindowsAzureProfile.Instance.CurrentEnvironment));
            }

            WindowsAzureProfile.Instance.AddSubscription(newSubscription);
            WindowsAzureProfile.Instance.Save();
        }
        private void SetupAzureEnvironmentFromEnvironmentVariables()
        {
            ServiceManagementTestEnvironmentFactory serviceManagementTestEnvironmentFactory = new ServiceManagementTestEnvironmentFactory();
            TestEnvironment rdfeEnvironment = serviceManagementTestEnvironmentFactory.GetTestEnvironment();
            ResourceManagerTestEnvironmentFactory resourceManagerTestEnvironmentFactory = new ResourceManagerTestEnvironmentFactory();
            TestEnvironment csmEnvironment = resourceManagerTestEnvironmentFactory.GetTestEnvironment();
            string jwtToken = csmEnvironment.Credentials != null ? 
                ((TokenCloudCredentials)csmEnvironment.Credentials).Token : null;

            WindowsAzureProfile.Instance.TokenProvider = new FakeAccessTokenProvider(jwtToken, csmEnvironment.UserName);

            WindowsAzureProfile.Instance.CurrentEnvironment = WindowsAzureProfile.Instance.Environments[testEnvironmentName];

            WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint =
                csmEnvironment.ActiveDirectoryEndpoint.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint =
                csmEnvironment.GalleryUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint =
                csmEnvironment.BaseUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint =
                rdfeEnvironment.BaseUri.AbsoluteUri;

            var newSubscription = new WindowsAzureSubscription(false, false)
            {
                SubscriptionId = csmEnvironment.SubscriptionId,
                ActiveDirectoryEndpoint =
                    WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint,
                ActiveDirectoryUserId = csmEnvironment.UserName,
                SubscriptionName = csmEnvironment.SubscriptionId,
                ServiceEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint),
                ResourceManagerEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint),
                TokenProvider = WindowsAzureProfile.Instance.TokenProvider,
                GalleryEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint),
                CurrentStorageAccountName = csmEnvironment.StorageAccount,
                IsDefault = true
            };
            if (recordingMode == HttpRecorderMode.Playback)
            {
                newSubscription.SetAccessToken(new FakeAccessToken
                    {
                        AccessToken = "123",
                        UserId = csmEnvironment.UserName
                    });
            }
            else
            {
                newSubscription.SetAccessToken(WindowsAzureProfile.Instance.TokenProvider.GetNewToken(WindowsAzureProfile.Instance.CurrentEnvironment));
            }

            WindowsAzureProfile.Instance.AddSubscription(newSubscription);
            WindowsAzureProfile.Instance.Save();
        }
Exemple #3
0
        public override void TestSetup()
        {
            base.TestSetup();
            this.mockServers = new List <HttpMockServer>();
            WindowsAzureSubscription.OnClientCreated += OnClientCreated;
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
            {
                return(true);
            };

            ServiceManagementTestEnvironmentFactory serviceManagementTestEnvironmentFactory = new ServiceManagementTestEnvironmentFactory();
            TestEnvironment rdfeEnvironment = serviceManagementTestEnvironmentFactory.GetTestEnvironment();
            ResourceManagerTestEnvironmentFactory resourceManagerTestEnvironmentFactory = new ResourceManagerTestEnvironmentFactory();
            TestEnvironment csmEnvironment = resourceManagerTestEnvironmentFactory.GetTestEnvironment();
            string          jwtToken       = ((TokenCloudCredentials)csmEnvironment.Credentials).Token;

            WindowsAzureProfile.Instance.TokenProvider = new FakeAccessTokenProvider(jwtToken, csmEnvironment.UserName);

            userName = csmEnvironment.UserName;

            CreateTestAzureEnvironment(csmEnvironment, rdfeEnvironment);
        }
        private void SetupAzureEnvironmentFromEnvironmentVariables()
        {
            ServiceManagementTestEnvironmentFactory serviceManagementTestEnvironmentFactory = new ServiceManagementTestEnvironmentFactory();
            TestEnvironment rdfeEnvironment = serviceManagementTestEnvironmentFactory.GetTestEnvironment();
            ResourceManagerTestEnvironmentFactory resourceManagerTestEnvironmentFactory = new ResourceManagerTestEnvironmentFactory();
            TestEnvironment csmEnvironment = resourceManagerTestEnvironmentFactory.GetTestEnvironment();
            string jwtToken;
            
            if (_moduleMode == AzureModule.AzureResourceManager) 
            {
                jwtToken = csmEnvironment.Credentials != null ? 
                ((TokenCloudCredentials)csmEnvironment.Credentials).Token : null;
            } else if (_moduleMode == AzureModule.AzureServiceManagement) 
            {
                jwtToken = rdfeEnvironment.Credentials != null ?
                ((TokenCloudCredentials)rdfeEnvironment.Credentials).Token : null;
            } else 
            {
                throw new ArgumentException("Invalid module mode.");
            }

            WindowsAzureProfile.Instance.TokenProvider = new FakeAccessTokenProvider(jwtToken, csmEnvironment.UserName);
            
            WindowsAzureProfile.Instance.CurrentEnvironment = WindowsAzureProfile.Instance.Environments[testEnvironmentName];

            WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint =
                csmEnvironment.ActiveDirectoryEndpoint.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint =
                csmEnvironment.GalleryUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint =
                csmEnvironment.BaseUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint =
                rdfeEnvironment.BaseUri.AbsoluteUri;

            testSubscrption = new WindowsAzureSubscription(false, false)
            {
                SubscriptionId = csmEnvironment.SubscriptionId,
                ActiveDirectoryEndpoint =
                    WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint,
                ActiveDirectoryUserId = csmEnvironment.UserName,
                SubscriptionName = csmEnvironment.SubscriptionId,
                ServiceEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint),
                ResourceManagerEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint),
                TokenProvider = WindowsAzureProfile.Instance.TokenProvider,
                GalleryEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint),
                SqlDatabaseDnsSuffix = WindowsAzureProfile.Instance.CurrentEnvironment.SqlDatabaseDnsSuffix,
                CurrentStorageAccountName = csmEnvironment.StorageAccount,
                IsDefault = true
            };

            testEnvironment = csmEnvironment;
            if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback)
            {
                testSubscrption.SetAccessToken(new FakeAccessToken
                {
                    AccessToken = "123",
                    UserId = testEnvironment.UserName
                });
            }
            else
            {
                testSubscrption.SetAccessToken(WindowsAzureProfile.Instance.TokenProvider.GetNewToken(WindowsAzureProfile.Instance.CurrentEnvironment));
            }

            WindowsAzureProfile.Instance.AddSubscription(testSubscrption);
            WindowsAzureProfile.Instance.Save();
        }