Inheritance: Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
        public void AddsAzureEnvironment()
        {
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint = "endpoint.net",
                ManagementPortalUrl = "management portal url",
                StorageEndpoint = "endpoint.net",
                GalleryEndpoint = "http://galleryendpoint.com",
            };
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
            AzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments["KaTaL"];
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ServiceManagement], cmdlet.ServiceEndpoint);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl], cmdlet.ManagementPortalUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.Gallery], "http://galleryendpoint.com");
        }
        public void AddsEnvironmentWithMinimumInformation()
        {
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                EnableAdfsAuthentication = true,
            };

            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
            AzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments["KaTaL"];
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.True(env.OnPremise);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
        }
 public void CanCreateEnvironmentWithAllProperties()
 {
     Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
     PSAzureEnvironment actual = null;
     commandRuntimeMock.Setup(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()))
         .Callback((object output) => actual = (PSAzureEnvironment)output);
     var cmdlet = new AddAzureRMEnvironmentCommand()
     {
         CommandRuntime = commandRuntimeMock.Object,
         Name = "Katal",
         ActiveDirectoryEndpoint = "ActiveDirectoryEndpoint",
         AdTenant = "AdTenant",
         AzureKeyVaultDnsSuffix = "AzureKeyVaultDnsSuffix",
         ActiveDirectoryServiceEndpointResourceId = "ActiveDirectoryServiceEndpointResourceId",
         AzureKeyVaultServiceEndpointResourceId = "AzureKeyVaultServiceEndpointResourceId",
         EnableAdfsAuthentication = true,
         GalleryEndpoint = "GalleryEndpoint",
         GraphEndpoint = "GraphEndpoint",
         ManagementPortalUrl = "ManagementPortalUrl",
         PublishSettingsFileUrl = "PublishSettingsFileUrl",
         ResourceManagerEndpoint = "ResourceManagerEndpoint",
         ServiceEndpoint = "ServiceEndpoint",
         StorageEndpoint = "StorageEndpoint",
         SqlDatabaseDnsSuffix = "SqlDatabaseDnsSuffix",
         TrafficManagerDnsSuffix = "TrafficManagerDnsSuffix"
     };
     
     cmdlet.InvokeBeginProcessing();
     cmdlet.ExecuteCmdlet();
     cmdlet.InvokeEndProcessing();
     Assert.Equal(cmdlet.Name, actual.Name);
     Assert.Equal(cmdlet.EnableAdfsAuthentication.ToBool(), actual.EnableAdfsAuthentication);
     Assert.Equal(cmdlet.ActiveDirectoryEndpoint, actual.ActiveDirectoryAuthority);
     Assert.Equal(cmdlet.ActiveDirectoryServiceEndpointResourceId,
         actual.ActiveDirectoryServiceEndpointResourceId);
     Assert.Equal(cmdlet.AdTenant, actual.AdTenant);
     Assert.Equal(cmdlet.AzureKeyVaultDnsSuffix, actual.AzureKeyVaultDnsSuffix);
     Assert.Equal(cmdlet.AzureKeyVaultServiceEndpointResourceId, actual.AzureKeyVaultServiceEndpointResourceId);
     Assert.Equal(cmdlet.GalleryEndpoint, actual.GalleryUrl);
     Assert.Equal(cmdlet.GraphEndpoint, actual.GraphUrl);
     Assert.Equal(cmdlet.ManagementPortalUrl, actual.ManagementPortalUrl);
     Assert.Equal(cmdlet.PublishSettingsFileUrl, actual.PublishSettingsFileUrl);
     Assert.Equal(cmdlet.ResourceManagerEndpoint, actual.ResourceManagerUrl);
     Assert.Equal(cmdlet.ServiceEndpoint, actual.ServiceManagementUrl);
     Assert.Equal(cmdlet.StorageEndpoint, actual.StorageEndpointSuffix);
     Assert.Equal(cmdlet.SqlDatabaseDnsSuffix, actual.SqlDatabaseDnsSuffix);
     Assert.Equal( cmdlet.TrafficManagerDnsSuffix , actual.TrafficManagerDnsSuffix);
     commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
     AzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments["KaTaL"];
     Assert.Equal(env.Name, cmdlet.Name);
 }
        public void AddsEnvironmentWithStorageEndpoint()
        {
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            PSAzureEnvironment actual = null;
            commandRuntimeMock.Setup(f => f.WriteObject(It.IsAny<object>()))
                .Callback((object output) => actual = (PSAzureEnvironment)output);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                StorageEndpoint = "core.windows.net",
            };

            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
            AzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments["KaTaL"];
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix], actual.StorageEndpointSuffix);
        }
        public void IgnoresAddingPublicEnvironment()
        {
            var commandRuntimeMock = new Mock<ICommandRuntime>();
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = EnvironmentName.AzureCloud,
                PublishSettingsFileUrl = "http://microsoft.com"
            };

            Assert.Throws<InvalidOperationException>(() => cmdlet.ExecuteCmdlet());
        }
        public void IgnoresAddingDuplicatedEnvironment()
        {
            var profile = new AzureSMProfile();
            var commandRuntimeMock = new Mock<ICommandRuntime>();
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint = "endpoint.net",
                ManagementPortalUrl = "management portal url",
                StorageEndpoint = "endpoint.net"
            };
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            ProfileClient client = new ProfileClient(profile);
            int count = client.Profile.Environments.Count;

            // Add again
            cmdlet.Name = "kAtAl";
            cmdlet.ExecuteCmdlet();
            AzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments["KaTaL"];
            Assert.Equal(env.Name, cmdlet.Name);
        }