Inheritance: Microsoft.WindowsAzure.Commands.Utilities.Profile.SubscriptionCmdletBase
        public void AddsAzureEnvironment()
        {
            var profile = new AzureProfile();
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint = "endpoint.net",
                ManagementPortalUrl = "management portal url",
                StorageEndpoint = "endpoint.net",
                GalleryEndpoint = "http://galleryendpoint.com",
                Profile = profile
            };
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
            ProfileClient client = new ProfileClient(profile);
            AzureEnvironment env = client.GetEnvironmentOrDefault("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>();
            AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com"
            };

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

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSObject>()), Times.Once());
            ProfileClient client = new ProfileClient();
            AzureEnvironment env = client.Profile.Environments["KaTaL"];
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
        }
 public void CanCreateEnvironmentWithAllProperties()
 {
     var profile = new AzureProfile();
     Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
     PSAzureEnvironment actual = null;
     commandRuntimeMock.Setup(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()))
         .Callback((object output) => actual = (PSAzureEnvironment)output);
     AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
     {
         CommandRuntime = commandRuntimeMock.Object,
         Name = "Katal",
         Profile = profile,
         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());
     ProfileClient client = new ProfileClient(profile);
     AzureEnvironment env = client.Profile.Environments["KaTaL"];
     Assert.Equal(env.Name, cmdlet.Name);
 }
        public void AddsEnvironmentWithStorageEndpoint()
        {
            var profile = new AzureProfile();
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            PSAzureEnvironment actual = null;
            commandRuntimeMock.Setup(f => f.WriteObject(It.IsAny<object>()))
                .Callback((object output) => actual = (PSAzureEnvironment)output);
            AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                StorageEndpoint = "core.windows.net",
                Profile = profile
            };

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

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

            Testing.AssertThrows<Exception>(() => cmdlet.ExecuteCmdlet());
        }
        public void IgnoresAddingDuplicatedEnvironment()
        {
            var profile = new AzureProfile();
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
            {
                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";
            Testing.AssertThrows<Exception>(() => cmdlet.ExecuteCmdlet());
        }