public void GivenCertificateSpecifiedInConfig_ItSetsPropertiesFromIt(StoreLocation location)
            {
                // Arrange
                var cert = new NuGetCertificate(
                    name: "name",
                    purpose: CommonCertificatePurposes.AzureManagement,
                    environment: "test",
                    target: "Foo[abc]",
                    x509: null);
                var certs = new Mock <CertificatesHub>()
                {
                    CallBase = false
                };

                certs
                .Setup(c => c.GetCertificateFromConfigSetting(AzureHub.ConfigSetting, StoreName.My, location))
                .Returns(cert);

                // Act
                var azure = new AzureHub(certs.Object);

                // Assert
                Assert.Same(cert, azure.ManagementCertificate);
                Assert.Equal("Foo", azure.SubscriptionName);
                Assert.Equal("abc", azure.SubscriptionId);
            }
            public void GivenMultipleCertificatesSpecifiedByPurpose_ItSelectsFirstOne(StoreLocation location)
            {
                // Arrange
                var firstCert = new NuGetCertificate(
                    name: "first",
                    purpose: CommonCertificatePurposes.AzureManagement,
                    environment: "test",
                    target: "First[abc]",
                    x509: null);
                var secondCert = new NuGetCertificate(
                    name: "second",
                    purpose: CommonCertificatePurposes.AzureManagement,
                    environment: "test",
                    target: "Second[def]",
                    x509: null);
                var certs = new Mock <CertificatesHub>()
                {
                    CallBase = false
                };

                certs
                .Setup(c => c.GetCertificatesByPurpose(CommonCertificatePurposes.AzureManagement, StoreName.My, location))
                .Returns(new[] { firstCert, secondCert });

                // Act
                var azure = new AzureHub(certs.Object);

                // Assert
                Assert.Same(firstCert, azure.ManagementCertificate);
                Assert.Equal("First", azure.SubscriptionName);
                Assert.Equal("abc", azure.SubscriptionId);
            }
            public void GivenCertificateWithInvalidTarget_ItThrowsConfigurationException()
            {
                // Arrange
                var cert = new NuGetCertificate(
                    name: "name",
                    purpose: CommonCertificatePurposes.AzureManagement,
                    environment: "test",
                    target: "nope! Not valid!",
                    x509: null);
                var certs = new Mock<CertificatesHub>() { CallBase = false };
                certs
                    .Setup(c => c.GetCertificateFromConfigSetting(AzureHub.ConfigSetting, StoreName.My, StoreLocation.LocalMachine))
                    .Returns(cert);

                // Act/Assert
                var ex = Assert.Throws<ConfigurationException>(() => new AzureHub(certs.Object));
                Assert.Equal(Strings.AzureHub_MissingSubscription, ex.Message);
            }
            public void GivenCertificateSpecifiedInConfig_ItSetsPropertiesFromIt(StoreLocation location)
            {
                // Arrange
                var cert = new NuGetCertificate(
                    name: "name",
                    purpose: CommonCertificatePurposes.AzureManagement,
                    environment: "test",
                    target: "Foo[abc]",
                    x509: null);
                var certs = new Mock<CertificatesHub>() { CallBase = false };
                certs
                    .Setup(c => c.GetCertificateFromConfigSetting(AzureHub.ConfigSetting, StoreName.My, location))
                    .Returns(cert);

                // Act
                var azure = new AzureHub(certs.Object);

                // Assert
                Assert.Same(cert, azure.ManagementCertificate);
                Assert.Equal("Foo", azure.SubscriptionName);
                Assert.Equal("abc", azure.SubscriptionId);
            }
            public void GivenCertificateWithInvalidTarget_ItThrowsConfigurationException()
            {
                // Arrange
                var cert = new NuGetCertificate(
                    name: "name",
                    purpose: CommonCertificatePurposes.AzureManagement,
                    environment: "test",
                    target: "nope! Not valid!",
                    x509: null);
                var certs = new Mock <CertificatesHub>()
                {
                    CallBase = false
                };

                certs
                .Setup(c => c.GetCertificateFromConfigSetting(AzureHub.ConfigSetting, StoreName.My, StoreLocation.LocalMachine))
                .Returns(cert);

                // Act/Assert
                var ex = Assert.Throws <ConfigurationException>(() => new AzureHub(certs.Object));

                Assert.Equal(Strings.AzureHub_MissingSubscription, ex.Message);
            }
            public void GivenMultipleCertificatesSpecifiedByPurpose_ItSelectsFirstOne(StoreLocation location)
            {
                // Arrange
                var firstCert = new NuGetCertificate(
                    name: "first",
                    purpose: CommonCertificatePurposes.AzureManagement,
                    environment: "test",
                    target: "First[abc]",
                    x509: null);
                var secondCert = new NuGetCertificate(
                    name: "second",
                    purpose: CommonCertificatePurposes.AzureManagement,
                    environment: "test",
                    target: "Second[def]",
                    x509: null);
                var certs = new Mock<CertificatesHub>() { CallBase = false };
                certs
                    .Setup(c => c.GetCertificatesByPurpose(CommonCertificatePurposes.AzureManagement, StoreName.My, location))
                    .Returns(new[] { firstCert, secondCert });

                // Act
                var azure = new AzureHub(certs.Object);

                // Assert
                Assert.Same(firstCert, azure.ManagementCertificate);
                Assert.Equal("First", azure.SubscriptionName);
                Assert.Equal("abc", azure.SubscriptionId);
            }