public void GetEndpoints1() { DefaultProfile.ClearDefaultProfile(); string regionId = "GetEndpoints.someString"; string productName = "ecs"; string productDomain = "product_domain"; List <Endpoint> endpoints; List <ProductDomain> products; DefaultProfile profile = DefaultProfile.GetProfile(); profile = DefaultProfile.GetProfile(); // 未添加endpoint前,无endpoints节点 // 使用已存在的阿里云的 productName (如ecs) , 不会初始化endpoints , endpoints为null endpoints = profile.GetEndpoints(regionId, productName); // 使用不存在的名称 , endpoints 会初始化, 会添加进endpoints节点 // 但是会把regionId作为endpoint.Name productName = "product_name"; endpoints = profile.GetEndpoints(regionId, productName); foreach (Endpoint endpoint in endpoints) { Assert.Equal(regionId, endpoint.Name); products = endpoint.ProductDomains; foreach (ProductDomain product in products) { Assert.Equal(productName, product.ProductName); Assert.Equal(productDomain, product.DomianName); } } }
public void GetEndpoints5() { DefaultProfile.ClearDefaultProfile(); Endpoint endpoint = null; var mock = new Mock <DefaultProfile>(true); mock.Setup(foo => foo.GetEndpointByIEndpoints( It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); mock.Setup(foo => foo.GetEndpointByRemoteProvider( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); DefaultProfile profile = mock.Object; List <Endpoint> endpoints = profile.GetEndpoints("cn-hangzhou", "Ess"); Assert.Throws <ClientException>( () => { profile.GetEndpoints("productNotExist", "regionId", "serviceCode", "endpointType"); } ); }
public void GetEndpoints6() { DefaultProfile.ClearDefaultProfile(); // Mock RegionIds ISet <String> regionIds = new HashSet <String>(); regionIds.Add("cn-hangzhou"); // Mock productDomains List <ProductDomain> productDomains = new List <ProductDomain>() { }; ProductDomain productDomain = new ProductDomain("Ess", "ess.aliyuncs.com"); productDomains.Add(productDomain); // Mock endpoint Endpoint endpoint = new Endpoint("cn-hangzhou", regionIds, productDomains); var mock1 = new Mock <DefaultProfile>(true); mock1.Setup(foo => foo.GetEndpointByIEndpoints( It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); mock1.Setup(foo => foo.GetEndpointByRemoteProvider( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); DefaultProfile profile = mock1.Object; // When Get endpoint is not null List <Endpoint> endpoints1 = profile.GetEndpoints("cn-hangzhou", "Ess"); Assert.NotNull(endpoints1); // When Get endpoint is null endpoint = null; mock1.Setup(foo => foo.GetEndpointByIEndpoints( It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); mock1.Setup(foo => foo.GetEndpointByRemoteProvider( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); profile = mock1.Object; List <Endpoint> endpoints2 = profile.GetEndpoints("productNotExist", "regionId", "serviceCode", "endpointType"); Assert.Equal(endpoints1, endpoints2); }
public void GetEndpoints2() { DefaultProfile.ClearDefaultProfile(); // When product = null DefaultProfile profile = DefaultProfile.GetProfile(); List <Endpoint> endpoints1 = profile.GetEndpoints(null, null); List <Endpoint> endpoints2 = profile.GetEndpoints(null, null, null, null); Assert.Equal(endpoints1, endpoints2); }
public void AddEndpoint() { DefaultProfile.ClearDefaultProfile(); string endpointName = "AddEndpoint.someString"; string regionId = "AddEndpoint.someString"; string productName = "product_name"; string productDomain = "product_domain"; List <Endpoint> endpoints; List <ProductDomain> products; DefaultProfile profile = DefaultProfile.GetProfile(); profile = DefaultProfile.GetProfile(); // 添加endpoint节点 DefaultProfile.AddEndpoint(endpointName, regionId, productName, productDomain, false); endpoints = profile.GetEndpoints(regionId, productName); Assert.NotNull(endpoints); foreach (Endpoint endpoint in endpoints) { Assert.Equal(endpointName, endpoint.Name); products = endpoint.ProductDomains; foreach (ProductDomain product in products) { Assert.Equal(productName, product.ProductName); Assert.Equal(productDomain, product.DomianName); } } DefaultProfile.ClearDefaultProfile(); DefaultProfile.AddEndpoint(endpointName, regionId, productName, productDomain); // 多条件覆盖 endpoints = profile.GetEndpoints(regionId, productName); Assert.NotNull(endpoints); foreach (Endpoint endpoint in endpoints) { Assert.Equal(endpointName, endpoint.Name); products = endpoint.ProductDomains; foreach (ProductDomain product in products) { Assert.Equal(productName, product.ProductName); Assert.Equal(productDomain, product.DomianName); } } DefaultProfile.AddEndpoint(endpointName, regionId, productName, productDomain, true); }
public void GetEndpoints3() { DefaultProfile.ClearDefaultProfile(); // Mock RegionIds ISet <String> regionIds = new HashSet <String>(); regionIds.Add("cn-hangzhou"); // Mock productDomains List <ProductDomain> productDomains = new List <ProductDomain>() { }; ProductDomain productDomain = new ProductDomain("Ess", "ess.aliyuncs.com"); productDomains.Add(productDomain); // Mock endpoint Endpoint endpoint = new Endpoint("cn-hangzhou", regionIds, productDomains); var mock = new Mock <DefaultProfile>(true); mock.Setup(foo => foo.GetEndpointByIEndpoints( It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); mock.Setup(foo => foo.GetEndpointByRemoteProvider( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() )).Returns(endpoint); DefaultProfile profile = mock.Object; profile.GetEndpoints("product", "regionId", "serviceCode", "endpointType"); }