コード例 #1
0
        public PsApiManagement(ApiServiceResource apiServiceResource)
            : this()
        {
            if (apiServiceResource == null)
            {
                throw new ArgumentNullException("apiServiceResource");
            }

            Id = apiServiceResource.Id;
            Name = apiServiceResource.Name;
            Location = apiServiceResource.Location;
            Sku = Mapper.Map<SkuType, PsApiManagementSku>(apiServiceResource.Properties.SkuProperties.SkuType);
            Capacity = apiServiceResource.Properties.SkuProperties.Capacity ?? 1;
            ProvisioningState = apiServiceResource.Properties.ProvisioningState;
            RuntimeUrl = apiServiceResource.Properties.ProxyEndpoint;
            PortalUrl = apiServiceResource.Properties.ManagementPortalEndpoint;
            StaticIPs = apiServiceResource.Properties.StaticIPs.ToArray();

            if (apiServiceResource.Properties.AdditionalRegions != null)
            {
                AdditionalRegions =
                    apiServiceResource.Properties.AdditionalRegions
                        .Select(region => new PsApiManagementRegion(region))
                        .ToList();
            }

            if (apiServiceResource.Properties.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(apiServiceResource.Properties.VirtualNetworkConfiguration);
            }

            if (apiServiceResource.Properties.HostnameConfigurations != null)
            {
                var portalHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Portal);
                if (portalHostnameResource != null)
                {
                    PortalHostnameConfiguration = new PsApiManagementHostnameConfiguration(portalHostnameResource);
                }

                var proxyHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Proxy);
                if (proxyHostnameResource != null)
                {
                    ProxyHostnameConfiguration = new PsApiManagementHostnameConfiguration(proxyHostnameResource);
                }
            }

            if (apiServiceResource.Tags != null)
            {
                Tags = apiServiceResource.Tags;
            }
        }
コード例 #2
0
        public void TestCtor()
        {
            // arrange
            var resource = new ApiServiceResource
            {
                ETag = "etag",
                Id = "id",
                Location = "location",
                Name = "name",
                Type = "resource type",
                Tags = new Dictionary<string, string>()
                {
                    {"tagkey1", "tagvalue1" },
                    {"tagkey2", "tagvalue2" }
                },
                Properties = new ApiServiceProperties
                {
                    AdditionalRegions = new List<AdditionalRegion>()
                    {
                        new AdditionalRegion
                        {
                            Location = "region location",
                            SkuType = SkuType.Premium,
                            SkuUnitCount = 2,
                            StaticIPs = new List<string>() { "192.168.1.1", "192.168.1.1" },
                            VirtualNetworkConfiguration = new VirtualNetworkConfiguration
                            {
                                Location = "region vpn location",
                                SubnetName = "region vpn subnet name",
                                VnetId = Guid.NewGuid()
                            }
                        }
                    },
                    AddresserEmail = "*****@*****.**",
                    CreatedAtUtc = DateTime.UtcNow,
                    CustomProperties = new Dictionary<string, string>()
                    {
                        { "cpkey1", "cpvalue1" },
                        { "cpkey2", "cpvalue2" }
                    },
                    HostnameConfigurations = new List<HostnameConfiguration>()
                    {
                        new HostnameConfiguration
                        {
                            Type = HostnameType.Portal,
                            Certificate = new CertificateInformation
                            {
                                Expiry = DateTime.UtcNow.AddDays(5),
                                Subject = "portal cert subject",
                                Thumbprint = "portal cert thumbprint"
                            },
                            Hostname = "portal hostname"
                        },
                        new HostnameConfiguration
                        {
                            Type = HostnameType.Proxy,
                            Certificate = new CertificateInformation
                            {
                                Expiry = DateTime.UtcNow.AddDays(10),
                                Subject = "proxy cert subject",
                                Thumbprint = "proxy cert thumbprint"
                            },
                            Hostname = "proxy hostname"
                        }
                    },
                    ManagementPortalEndpoint = "http://management.portal.endpoint",
                    ProvisioningState = "Active",
                    ProxyEndpoint = "http://proxy.endpoint",
                    PublisherEmail = "*****@*****.**",
                    PublisherName = "publisher name",
                    SkuProperties = new ApiServiceSkuProperties
                    {
                        Capacity = 3,
                        SkuType = SkuType.Premium
                    },
                    StaticIPs = new[] { "192.168.0.1", "192.168.0.2" },
                    VirtualNetworkConfiguration = new VirtualNetworkConfiguration
                    {
                        Location = "vpn location",
                        SubnetName = "vpn subnet name",
                        VnetId = Guid.NewGuid()
                    }
                }
            };

            // act
            var result = new PsApiManagement(resource);

            // assert
            Assert.Equal(resource.Id, result.Id);
            Assert.Equal(resource.Location, result.Location);
            Assert.Equal(resource.Name, result.Name);
            Assert.Equal(resource.Tags.Count, result.Tags.Count);
            foreach (var tagKey in resource.Tags.Keys)
            {
                Assert.Equal(resource.Tags[tagKey], result.Tags[tagKey]);
            }

            Assert.Equal(resource.Properties.AdditionalRegions.Count, result.AdditionalRegions.Count);
            var resourceRegion = resource.Properties.AdditionalRegions[0];
            var resultRegion = result.AdditionalRegions[0];
            Assert.Equal(resourceRegion.Location, resultRegion.Location);
            Assert.Equal(resourceRegion.SkuType.ToString(), resultRegion.Sku.ToString());
            Assert.Equal(resourceRegion.SkuUnitCount, resultRegion.Capacity);
            for (int i = 0; i < resourceRegion.StaticIPs.Count; i++)
            {
                Assert.Equal(resourceRegion.StaticIPs[i], resultRegion.StaticIPs[i]);
            }
            Assert.Equal(resourceRegion.VirtualNetworkConfiguration.Location, resultRegion.VirtualNetwork.Location);
            Assert.Equal(resourceRegion.VirtualNetworkConfiguration.SubnetName, resultRegion.VirtualNetwork.SubnetName);
            Assert.Equal(resourceRegion.VirtualNetworkConfiguration.VnetId, resultRegion.VirtualNetwork.VnetId);

            var portalHostname = resource.Properties.HostnameConfigurations.Single(h => h.Type == HostnameType.Portal);
            Assert.Equal(portalHostname.Hostname, result.PortalHostnameConfiguration.Hostname);
            Assert.Equal(portalHostname.Certificate.Expiry, result.PortalHostnameConfiguration.HostnameCertificate.Expiry);
            Assert.Equal(portalHostname.Certificate.Subject, result.PortalHostnameConfiguration.HostnameCertificate.Subject);
            Assert.Equal(portalHostname.Certificate.Thumbprint, result.PortalHostnameConfiguration.HostnameCertificate.Thumbprint);

            var proxyHostname = resource.Properties.HostnameConfigurations.Single(h => h.Type == HostnameType.Proxy);
            Assert.Equal(proxyHostname.Hostname, result.ProxyHostnameConfiguration.Hostname);
            Assert.Equal(proxyHostname.Certificate.Expiry, result.ProxyHostnameConfiguration.HostnameCertificate.Expiry);
            Assert.Equal(proxyHostname.Certificate.Subject, result.ProxyHostnameConfiguration.HostnameCertificate.Subject);
            Assert.Equal(proxyHostname.Certificate.Thumbprint, result.ProxyHostnameConfiguration.HostnameCertificate.Thumbprint);

            Assert.Equal(resource.Properties.VirtualNetworkConfiguration.Location, result.VirtualNetwork.Location);
            Assert.Equal(resource.Properties.VirtualNetworkConfiguration.SubnetName, result.VirtualNetwork.SubnetName);
            Assert.Equal(resource.Properties.VirtualNetworkConfiguration.VnetId, result.VirtualNetwork.VnetId);

            Assert.Equal(resource.Properties.ManagementPortalEndpoint, result.PortalUrl);
            Assert.Equal(resource.Properties.ProxyEndpoint, result.RuntimeUrl);
            Assert.Equal(resource.Properties.ProvisioningState, result.ProvisioningState);
            Assert.Equal(resource.Properties.SkuProperties.SkuType.ToString(), result.Sku.ToString());
            Assert.Equal(resource.Properties.SkuProperties.Capacity, result.Capacity);
        }