Esempio n. 1
0
        public void SetsAzureEnvironment()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();
            string name = "Katal";

            testProfile.AddEnvironment(new WindowsAzureEnvironment {
                Name = name, PublishSettingsFileUrl = "publish file url"
            });

            SetAzureEnvironmentCommand cmdlet = new SetAzureEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "KATaL",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint        = "endpoint.net",
                ManagementPortalUrl    = "management portal url",
                StorageEndpoint        = "endpoint.net",
                GalleryEndpoint        = "galleryendpoint"
            };

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <WindowsAzureEnvironment>()), Times.Once());
            WindowsAzureEnvironment env = WindowsAzureProfile.Instance.Environments["KaTaL"];

            Assert.AreEqual(env.Name.ToLower(), cmdlet.Name.ToLower());
            Assert.AreEqual(env.PublishSettingsFileUrl, cmdlet.PublishSettingsFileUrl);
            Assert.AreEqual(env.ServiceEndpoint, cmdlet.ServiceEndpoint);
            Assert.AreEqual(env.ManagementPortalUrl, cmdlet.ManagementPortalUrl);
            Assert.AreEqual(env.StorageBlobEndpointFormat, "{0}://{1}.blob.endpoint.net/");
            Assert.AreEqual(env.StorageQueueEndpointFormat, "{0}://{1}.queue.endpoint.net/");
            Assert.AreEqual(env.StorageTableEndpointFormat, "{0}://{1}.table.endpoint.net/");
            Assert.AreEqual(env.GalleryEndpoint, "galleryendpoint");
        }
        public void RemovesAzureEnvironment()
        {
            var          commandRuntimeMock = new Mock <ICommandRuntime>();
            const string name = "test";

            testProfile.AddEnvironment(new WindowsAzureEnvironment
            {
                Name = name,
                PublishSettingsFileUrl = "test url"
            });

            var cmdlet = new RemoveAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name           = name
            };

            cmdlet.ExecuteCmdlet();
            Assert.IsFalse(WindowsAzureProfile.Instance.Environments.ContainsKey(name));
        }
        public void SavingWritesProfileDataToStore()
        {
            var         storeMock = new Mock <IProfileStore>();
            ProfileData savedData = null;

            storeMock.Setup(s => s.Save(It.IsAny <ProfileData>()))
            .Callback((ProfileData data) => { savedData = data; });

            var profile   = new WindowsAzureProfile(storeMock.Object);
            var sourceEnv = testProfileData.Environments.First();

            profile.AddEnvironment(new WindowsAzureEnvironment
            {
                ManagementPortalUrl = sourceEnv.ManagementPortalUrl,
                Name = sourceEnv.Name,
                PublishSettingsFileUrl                   = sourceEnv.PublishSettingsFileUrl,
                ServiceEndpoint                          = sourceEnv.ServiceEndpoint,
                ActiveDirectoryEndpoint                  = sourceEnv.AdTenantUrl,
                ActiveDirectoryCommonTenantId            = sourceEnv.CommonTenantId,
                StorageEndpointSuffix                    = sourceEnv.StorageEndpointSuffix,
                GalleryEndpoint                          = sourceEnv.GalleryEndpoint,
                ActiveDirectoryServiceEndpointResourceId = sourceEnv.ActiveDirectoryServiceEndpointResourceId,
                SqlDatabaseDnsSuffix                     = sourceEnv.SqlDatabaseDnsSuffix,
            });

            var locator = typeof(ResourceLocator);

            profile.ImportPublishSettings(locator.Assembly
                                          .GetManifestResourceStream(locator, "Azure.publishsettings"));

            // Should save twice, one for environment, one for subscription import
            storeMock.Verify(s => s.Save(It.IsAny <ProfileData>()), Times.Exactly(2));

            // Validate that the saved data looks right
            Assert.AreEqual(1, savedData.Environments.Count());
            Assert.AreEqual(EnvironmentName.AzureCloud, savedData.DefaultEnvironmentName);
            AssertEqual(sourceEnv, savedData.Environments.First());
            Assert.AreEqual(3, savedData.Subscriptions.Count());
        }