Example #1
0
        public void AddsAzureEnvironment()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name           = "Katal"
            };
            var dict = new Dictionary <string, object>
            {
                { "PublishSettingsFileUrl", "http://microsoft.com" },
                { "ServiceEndpoint", "https://endpoint.net" },
                { "ManagementPortalUrl", "http://management.portal.url" },
                { "StorageEndpoint", "http://endpoint.net" },
                { "GalleryEndpoint", "http://galleryendpoint.com" },
            };

            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("Name");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            var profileClient     = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl), dict["PublishSettingsFileUrl"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement), dict["ServiceEndpoint"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.ManagementPortalUrl), dict["ManagementPortalUrl"]);
            Assert.Equal("http://galleryendpoint.com", env.GetEndpoint(AzureEnvironment.Endpoint.Gallery));
        }
        public void AddsAzureEnvironmentUsingAPublicRMEndpoint()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name           = "Katal",
                ARMEndpoint    = "https://management.azure.com/"
            };

            Mock <EnvironmentHelper> envHelperMock = new Mock <EnvironmentHelper>();

            envHelperMock.Setup(f => f.RetrieveMetaDataEndpoints(It.IsAny <string>())).ReturnsAsync(null);
            envHelperMock.Setup(f => f.RetrieveDomain(It.IsAny <string>())).Returns("domain");
            cmdlet.EnvHelper = envHelperMock.Object;
            cmdlet.SetParameterSet("ARMEndpoint");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.GetEnvironment("Katal");
            var oracle            = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(oracle.ResourceManagerUrl, env.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager));
            Assert.Equal(oracle.ActiveDirectoryAuthority, env.GetEndpoint(AzureEnvironment.Endpoint.ActiveDirectory));
            Assert.Equal(oracle.ActiveDirectoryServiceEndpointResourceId, env.GetEndpoint(AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId));
            envHelperMock.Verify(f => f.RetrieveDomain(It.IsAny <string>()), Times.Never);
            envHelperMock.Verify(f => f.RetrieveMetaDataEndpoints(It.IsAny <string>()), Times.Never);
        }
Example #3
0
        public void CreateEnvironmentWithTrailingSlashInActiveDirectory()
        {
            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 = "https://ActiveDirectoryEndpoint/"
            };

            var dict = new Dictionary <string, object>();

            dict["ActiveDirectoryEndpoint"] = "https://ActiveDirectoryEndpoint/";
            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("Name");

            SetupConfirmation(commandRuntimeMock);
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            Assert.Equal(cmdlet.ActiveDirectoryEndpoint, actual.ActiveDirectoryAuthority, StringComparer.OrdinalIgnoreCase);
        }
Example #4
0
        public void AddsEnvironmentWithStorageEndpoint()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            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.SetParameterSet("Name");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.GetEnvironment("KaTaL");

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix), actual.StorageEndpointSuffix);
        }
Example #5
0
        public void AddsEnvironmentWithMinimumInformation()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime           = commandRuntimeMock.Object,
                Name                     = "Katal",
                EnableAdfsAuthentication = true
            };

            var dict = new Dictionary <string, object>();

            dict["EnableAdfsAuthentication"] = true;
            dict["PublishSettingsFileUrl"]   = "http://microsoft.com";
            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("Name");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.GetEnvironment("KaTaL");

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.True(env.OnPremise);
            Assert.Equal("http://microsoft.com", env.GetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl));
        }
        public void AddsAzureEnvironmentUsingARMEndpoint()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name           = "Stack",
                ARMEndpoint    = "https://management.local.azurestack.external/"
            };

            Mock <EnvironmentHelper> envHelperMock     = new Mock <EnvironmentHelper>();
            MetadataResponse         metadataEndpoints = new MetadataResponse
            {
                GalleryEndpoint = "https://galleryendpoint",
                GraphEndpoint   = "https://graphendpoint",
                PortalEndpoint  = "https://portalendpoint",
                authentication  = new Authentication
                {
                    Audiences     = new[] { "audience1", "audience2" },
                    LoginEndpoint = "https://loginendpoint"
                }
            };

            envHelperMock.Setup(f => f.RetrieveMetaDataEndpoints(It.IsAny <string>())).ReturnsAsync(metadataEndpoints);
            envHelperMock.Setup(f => f.RetrieveDomain(It.IsAny <string>())).Returns("domain");
            cmdlet.EnvHelper = envHelperMock.Object;
            cmdlet.SetParameterSet("ARMEndpoint");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            var profileClient     = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.GetEnvironment("Stack");

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(cmdlet.ARMEndpoint, env.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager));
            Assert.Equal("https://loginendpoint/", env.GetEndpoint(AzureEnvironment.Endpoint.ActiveDirectory));
            Assert.Equal("audience1", env.GetEndpoint(AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId));
            Assert.Equal("https://graphendpoint", env.GetEndpoint(AzureEnvironment.Endpoint.GraphEndpointResourceId));
            envHelperMock.Verify(f => f.RetrieveDomain(It.IsAny <string>()), Times.Once);
            envHelperMock.Verify(f => f.RetrieveMetaDataEndpoints(It.IsAny <string>()), Times.Once);
        }
        public void ThrowsForInvalidUrl()
        {
            var 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",
                ARMEndpoint    = "foobar.com"
            };

            SetupConfirmation(commandRuntimeMock);
            cmdlet.SetParameterSet("ARMEndpoint");

            Assert.Throws <ArgumentException>(() => cmdlet.ExecuteCmdlet());
        }
Example #8
0
        public void SetEnvironmentForMultipleContexts()
        {
            // Add new environment
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                ARMEndpoint            = "https://management.azure.com/",
                AzureKeyVaultDnsSuffix = "vault.local.azurestack.external",
                AzureKeyVaultServiceEndpointResourceId = "https://vault.local.azurestack.external"
            };
            var dict = new Dictionary <string, object>
            {
                { "ARMEndpoint", "https://management.azure.com/" },
                { "AzureKeyVaultDnsSuffix", "vault.local.azurestack.external" },
                { "AzureKeyVaultServiceEndpointResourceId", "https://vault.local.azurestack.external" }
            };

            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("ARMEndpoint");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            var profileClient     = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);

            // Create contexts using the new environment
            var    profile = new AzureRmProfile();
            string contextName1;
            var    context1 = (new AzureContext {
                Environment = env
            })
                              .WithAccount(new AzureAccount {
                Id = "*****@*****.**"
            })
                              .WithTenant(new AzureTenant {
                Id = Guid.NewGuid().ToString(), Directory = "contoso.com"
            })
                              .WithSubscription(new AzureSubscription {
                Id = Guid.NewGuid().ToString(), Name = "Contoso Subscription 1"
            });

            profile.TryAddContext(context1, out contextName1);
            string contextName2;
            var    context2 = (new AzureContext {
                Environment = env
            })
                              .WithAccount(new AzureAccount {
                Id = "*****@*****.**"
            })
                              .WithTenant(new AzureTenant {
                Id = Guid.NewGuid().ToString(), Directory = "contoso.cn"
            })
                              .WithSubscription(new AzureSubscription {
                Id = Guid.NewGuid().ToString(), Name = "Contoso Subscription 2"
            });

            profile.TryAddContext(context2, out contextName2);
            profile.TrySetDefaultContext(context1);
            AzureRmProfileProvider.Instance.Profile = profile;

            // Update the environment with new endpoints
            commandRuntimeMock = new Mock <ICommandRuntime>();
            SetupConfirmation(commandRuntimeMock);
            var cmdlet2 = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                ARMEndpoint            = "https://management.azure.com/",
                AzureKeyVaultDnsSuffix = "adminvault.local.azurestack.external",
                AzureKeyVaultServiceEndpointResourceId = "https://adminvault.local.azurestack.external"
            };

            dict.Clear();
            dict = new Dictionary <string, object>
            {
                { "ARMEndpoint", "https://management.azure.com/" },
                { "AzureKeyVaultDnsSuffix", "adminvault.local.azurestack.external" },
                { "AzureKeyVaultServiceEndpointResourceId", "https://adminvault.local.azurestack.external" }
            };

            cmdlet2.SetBoundParameters(dict);
            cmdlet2.SetParameterSet("ARMEndpoint");
            cmdlet2.InvokeBeginProcessing();
            cmdlet2.ExecuteCmdlet();
            cmdlet2.InvokeEndProcessing();

            profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            env           = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);

            // Validate that the endpoints were updated in the contexts
            profile = (AzureRmProfile)AzureRmProfileProvider.Instance.Profile;
            Assert.NotNull(profile);
            Assert.NotNull(profile.Contexts);
            Assert.NotEmpty(profile.Contexts);
            foreach (var context in profile.Contexts.Values)
            {
                Assert.NotNull(context);
                Assert.NotNull(context.Environment);
                Assert.Equal(context.Environment.Name, env.Name);
                Assert.Equal(context.Environment.AzureKeyVaultDnsSuffix, env.AzureKeyVaultDnsSuffix);
                Assert.Equal(context.Environment.AzureKeyVaultServiceEndpointResourceId, env.AzureKeyVaultServiceEndpointResourceId);
            }
        }
Example #9
0
        public void AddEnvironmentUpdatesContext()
        {
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock,
                Name                   = "Katal",
                ARMEndpoint            = "https://management.azure.com/",
                AzureKeyVaultDnsSuffix = "vault.local.azurestack.external",
                AzureKeyVaultServiceEndpointResourceId = "https://vault.local.azurestack.external"
            };
            var dict = new Dictionary <string, object>
            {
                { "ARMEndpoint", "https://management.azure.com/" },
                { "AzureKeyVaultDnsSuffix", "vault.local.azurestack.external" },
                { "AzureKeyVaultServiceEndpointResourceId", "https://vault.local.azurestack.external" }
            };

            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("ARMEndpoint");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock = new MockCommandRuntime();
            var profileClient     = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);

            var cmdlet1 = new ConnectAzureRmAccountCommand();

            cmdlet1.CommandRuntime = commandRuntimeMock;
            cmdlet1.Environment    = "Katal";

            dict.Clear();
            dict = new Dictionary <string, object>
            {
                { "Environment", cmdlet1.Environment }
            };

            cmdlet1.SetBoundParameters(dict);
            cmdlet1.InvokeBeginProcessing();
            cmdlet1.ExecuteCmdlet();
            cmdlet1.InvokeEndProcessing();
            commandRuntimeMock = new MockCommandRuntime();

            Assert.NotNull(AzureRmProfileProvider.Instance.Profile.DefaultContext);
            Assert.Equal(AzureRmProfileProvider.Instance.Profile.DefaultContext.Environment.Name, cmdlet1.Environment);

            var cmdlet2 = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock,
                Name                   = "Katal",
                ARMEndpoint            = "https://management.azure.com/",
                AzureKeyVaultDnsSuffix = "adminvault.local.azurestack.external",
                AzureKeyVaultServiceEndpointResourceId = "https://adminvault.local.azurestack.external"
            };

            dict.Clear();
            dict = new Dictionary <string, object>
            {
                { "ARMEndpoint", "https://management.azure.com/" },
                { "AzureKeyVaultDnsSuffix", "adminvault.local.azurestack.external" },
                { "AzureKeyVaultServiceEndpointResourceId", "https://adminvault.local.azurestack.external" }
            };

            cmdlet2.SetBoundParameters(dict);
            cmdlet2.SetParameterSet("ARMEndpoint");
            cmdlet2.InvokeBeginProcessing();
            cmdlet2.ExecuteCmdlet();
            cmdlet2.InvokeEndProcessing();

            profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            env           = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);

            var context = AzureRmProfileProvider.Instance.Profile.DefaultContext;

            Assert.NotNull(context);
            Assert.NotNull(context.Environment);
            Assert.Equal(context.Environment.Name, env.Name);
            Assert.Equal(context.Environment.AzureKeyVaultDnsSuffix, env.AzureKeyVaultDnsSuffix);
            Assert.Equal(context.Environment.AzureKeyVaultServiceEndpointResourceId, env.AzureKeyVaultServiceEndpointResourceId);
        }
Example #10
0
        public void CanCreateEnvironmentWithAllProperties()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            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 = "https://ActiveDirectoryEndpoint",
                AdTenant                = "AdTenant",
                AzureKeyVaultDnsSuffix  = "AzureKeyVaultDnsSuffix",
                ActiveDirectoryServiceEndpointResourceId = "https://ActiveDirectoryServiceEndpointResourceId",
                AzureKeyVaultServiceEndpointResourceId   = "https://AzureKeyVaultServiceEndpointResourceId",
                EnableAdfsAuthentication = true,
                GalleryEndpoint          = "https://GalleryEndpoint",
                GraphEndpoint            = "https://GraphEndpoint",
                ManagementPortalUrl      = "https://ManagementPortalUrl",
                PublishSettingsFileUrl   = "https://PublishSettingsFileUrl",
                ResourceManagerEndpoint  = "https://ResourceManagerEndpoint",
                ServiceEndpoint          = "https://ServiceEndpoint",
                StorageEndpoint          = "https://StorageEndpoint",
                SqlDatabaseDnsSuffix     = "SqlDatabaseDnsSuffix",
                TrafficManagerDnsSuffix  = "TrafficManagerDnsSuffix",
                GraphAudience            = "GaraphAudience",
                BatchEndpointResourceId  = "BatchResourceId",
                DataLakeAudience         = "DataLakeAudience",
                AzureOperationalInsightsEndpointResourceId = "AzureOperationalInsightsEndpointResourceId",
                AzureOperationalInsightsEndpoint           = "https://AzureOperationalInsights",
                AzureAttestationServiceEndpointResourceId  = "AzureAttestationServiceEndpointResourceId",
                AzureAttestationServiceEndpointSuffix      = "https://AzureAttestationService",
                AzureSynapseAnalyticsEndpointResourceId    = "AzureSynapseAnalyticsEndpointResourceId",
                AzureSynapseAnalyticsEndpointSuffix        = "https://AzureSynapseAnalytics",
            };

            var dict = new Dictionary <string, object>();

            dict["ActiveDirectoryEndpoint"] = "https://ActiveDirectoryEndpoint";
            dict["AdTenant"] = "AdTenant";
            dict["AzureKeyVaultDnsSuffix"] = "AzureKeyVaultDnsSuffix";
            dict["ActiveDirectoryServiceEndpointResourceId"] = "https://ActiveDirectoryServiceEndpointResourceId";
            dict["AzureKeyVaultServiceEndpointResourceId"]   = "https://AzureKeyVaultServiceEndpointResourceId";
            dict["EnableAdfsAuthentication"] = true;
            dict["GalleryEndpoint"]          = "https://GalleryEndpoint";
            dict["GraphEndpoint"]            = "https://GraphEndpoint";
            dict["ManagementPortalUrl"]      = "https://ManagementPortalUrl";
            dict["PublishSettingsFileUrl"]   = "https://PublishSettingsFileUrl";
            dict["ResourceManagerEndpoint"]  = "https://ResourceManagerEndpoint";
            dict["ServiceEndpoint"]          = "https://ServiceEndpoint";
            dict["StorageEndpoint"]          = "https://StorageEndpoint";
            dict["SqlDatabaseDnsSuffix"]     = "SqlDatabaseDnsSuffix";
            dict["TrafficManagerDnsSuffix"]  = "TrafficManagerDnsSuffix";
            dict["GraphAudience"]            = "GaraphAudience";
            dict["BatchEndpointResourceId"]  = "BatchResourceId";
            dict["DataLakeAudience"]         = "DataLakeAudience";
            dict["AzureOperationalInsightsEndpointResourceId"] = "AzureOperationalInsightsEndpointResourceId";
            dict["AzureOperationalInsightsEndpoint"]           = "https://AzureOperationalInsights";
            dict["AzureAttestationServiceEndpointResourceId"]  = "AzureAttestationServiceEndpointResourceId";
            dict["AzureAttestationServiceEndpointSuffix"]      = "https://AzureAttestationService";
            dict["AzureSynapseAnalyticsEndpointResourceId"]    = "AzureSynapseAnalyticsEndpointResourceId";
            dict["AzureSynapseAnalyticsEndpointSuffix"]        = "https://AzureSynapseAnalytics";
            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("Name");

            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, StringComparer.OrdinalIgnoreCase);
            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);
            Assert.Equal(cmdlet.GraphAudience, actual.GraphEndpointResourceId);
            Assert.Equal(cmdlet.BatchEndpointResourceId, actual.BatchEndpointResourceId);
            Assert.Equal(cmdlet.DataLakeAudience, actual.DataLakeEndpointResourceId);
            Assert.Equal(cmdlet.AzureOperationalInsightsEndpointResourceId, actual.AzureOperationalInsightsEndpointResourceId);
            Assert.Equal(cmdlet.AzureOperationalInsightsEndpoint, actual.AzureOperationalInsightsEndpoint);
            Assert.Equal(cmdlet.AzureAttestationServiceEndpointResourceId, actual.AzureAttestationServiceEndpointResourceId);
            Assert.Equal(cmdlet.AzureAttestationServiceEndpointSuffix, actual.AzureAttestationServiceEndpointSuffix);
            Assert.Equal(cmdlet.AzureSynapseAnalyticsEndpointResourceId, actual.AzureSynapseAnalyticsEndpointResourceId);
            Assert.Equal(cmdlet.AzureSynapseAnalyticsEndpointSuffix, actual.AzureSynapseAnalyticsEndpointSuffix);
            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.GetEnvironment("KaTaL");

            Assert.Equal(env.Name, cmdlet.Name);
        }
Example #11
0
        public void AddsEnvironmentMultipleTimes()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime           = commandRuntimeMock.Object,
                Name                     = "Katal",
                PublishSettingsFileUrl   = "http://microsoft.com",
                EnableAdfsAuthentication = true,
            };

            var dict = new Dictionary <string, object>();

            dict["PublishSettingsFileUrl"]   = "http://microsoft.com";
            dict["EnableAdfsAuthentication"] = true;
            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("Name");

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

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.GetEnvironment("KaTaL");

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.True(env.OnPremise);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl), cmdlet.PublishSettingsFileUrl);

            // Execute the same without PublishSettingsFileUrl and make sure the first value is preserved
            var cmdlet2 = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime           = commandRuntimeMock.Object,
                Name                     = "Katal",
                EnableAdfsAuthentication = true,
            };

            dict.Clear();
            dict["EnableAdfsAuthentication"] = true;
            cmdlet2.SetBoundParameters(dict);
            cmdlet2.SetParameterSet("Name");

            cmdlet2.InvokeBeginProcessing();
            cmdlet2.ExecuteCmdlet();
            cmdlet2.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Exactly(2));
            IAzureEnvironment env2 = AzureRmProfileProvider.Instance.Profile.GetEnvironment("KaTaL");

            Assert.Equal(env2.Name, cmdlet2.Name);
            Assert.True(env2.OnPremise);
            Assert.Equal(env2.GetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl), cmdlet.PublishSettingsFileUrl);

            var cmdlet3 = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name           = "Katal",
            };

            dict.Clear();
            cmdlet3.SetBoundParameters(dict);
            cmdlet3.SetParameterSet("Name");

            cmdlet3.InvokeBeginProcessing();
            cmdlet3.ExecuteCmdlet();
            cmdlet3.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Exactly(3));
            IAzureEnvironment env3 = AzureRmProfileProvider.Instance.Profile.GetEnvironment("KaTaL");

            Assert.Equal(env3.Name, cmdlet3.Name);
            Assert.Equal(env3.GetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl), cmdlet.PublishSettingsFileUrl);
        }