public void NewAzureIPTagTestSimple() { string ipTagType = "FirstPartyUsage"; string value = "InfrastructureTenants"; var cmdlet = new NewAzureIPTagCommand() { CommandRuntime = mockCommandRuntime, IPTagType = ipTagType, Value = value }; // Execute Cmdlet IEnumerable objs = cmdlet.Invoke(); foreach (var x in objs) { ; } Assert.Equal(1, mockCommandRuntime.OutputPipeline.Count); IPTag iptag = (IPTag)mockCommandRuntime.OutputPipeline[0]; Assert.Equal(ipTagType, iptag.IPTagType); Assert.Equal(value, iptag.Value); }
public void TestReserveIPWithIPTagsNegative() { using (var undoContext = AZT.UndoContext.Current) { undoContext.Start(); using (NetworkTestBase _testFixture = new NetworkTestBase()) { var managementClient = _testFixture.ManagementClient; bool storageAccountCreated = false; string storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower(); string reserveIpName = HttpMockServer.GetAssetName("res", "testresIPtagNegative").ToLower(); string location = managementClient.GetDefaultLocation("Storage", "Compute"); // Create an IPTag Value that doesn't exist IPTag iptag = new IPTag(); iptag.IPTagType = "FirstPartyUsage"; iptag.Value = "MyVip"; List <IPTag> iptags = new List <IPTag>(); iptags.Add(iptag); try { _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated); NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters { Name = reserveIpName, Label = "TestResTagNegLabel", Location = location, IPTags = iptags }; OperationStatusResponse reserveIpCreate = _testFixture.NetworkClient.ReservedIPs.Create(reservedIpCreatePars); } catch (Exception ex) { Console.WriteLine("TestReserveIPWithIPTagsNegative test did not succeed with error being ," + ex.Message); Assert.NotNull(ex); } finally { if (storageAccountCreated) { _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName); } } } } }
public void NewAzureReservedIPWithIPTags() { IPTag iptag = new IPTag(); iptag.IPTagType = "FirstPartyUsage"; iptag.Value = "InfrastructureTenants"; List <IPTag> iptags = new List <IPTag>(); iptags.Add(iptag); NewAzureReservedIPCmdlet cmdlet = new NewAzureReservedIPCmdlet(testClientProvider) { ReservedIPName = ReservedIPName, Location = "WestUS", Label = ReservedIPLabel, CommandRuntime = mockCommandRuntime, IPTagList = iptags }; cmdlet.SetParameterSet(NewAzureReservedIPCmdlet.ReserveNewIPParamSet); // Action cmdlet.ExecuteCmdlet(); networkingClientMock.Verify( c => c.ReservedIPs.CreateAsync( It.Is <NetworkReservedIPCreateParameters>( p => string.Equals(p.Name, ReservedIPName) && string.IsNullOrEmpty(p.ServiceName) && string.IsNullOrEmpty(p.VirtualIPName) && string.IsNullOrEmpty(p.DeploymentName) && p.IPTags == iptags), It.IsAny <CancellationToken>()), Times.Once()); Assert.Equal("Succeeded", ((ManagementOperationContext)mockCommandRuntime.OutputPipeline[0]).OperationStatus); }
public void TestReserveIPWithIPTagsSimple() { using (var undoContext = AZT.UndoContext.Current) { undoContext.Start(); using (NetworkTestBase _testFixture = new NetworkTestBase()) { var managementClient = _testFixture.ManagementClient; bool storageAccountCreated = false; string storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower(); string reserveIpName = HttpMockServer.GetAssetName("res", "testresIPtag").ToLower(); string location = "West Central US"; bool reservedIpCreated = false; IPTag iptag = new IPTag(); iptag.IPTagType = "FirstPartyUsage"; iptag.Value = "/tagTypes/SystemService/operators/Microsoft/platforms/Azure/services/Microsoft.AzureAD"; List <IPTag> iptags = new List <IPTag>(); iptags.Add(iptag); try { _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated); NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters { Name = reserveIpName, Label = "TestResTagLabel", Location = location, IPTags = iptags }; OperationStatusResponse reserveIpCreate = _testFixture.NetworkClient.ReservedIPs.Create(reservedIpCreatePars); Assert.True(reserveIpCreate.StatusCode == HttpStatusCode.OK); reservedIpCreated = true; NetworkReservedIPGetResponse reserveIpCreationResponse = _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName); Assert.True(reserveIpCreationResponse.StatusCode == HttpStatusCode.OK); Assert.True(reserveIpCreationResponse.IPTags.Count == iptags.Count); foreach (var iptag1 in iptags) { Assert.True(reserveIpCreationResponse.IPTags.Any(x => x.IPTagType == iptag1.IPTagType && x.Value == iptag1.Value)); } } catch (Exception ex) { Console.WriteLine("TestReserveIPWithIPTagsSimple test did not succeed with error being ," + ex.Message); throw; } finally { if (storageAccountCreated) { _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName); } if (reservedIpCreated) { _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName); } } } } }
internal static PublicIPPrefixData DeserializePublicIPPrefixData(JsonElement element) { Optional <Models.ExtendedLocation> extendedLocation = default; Optional <PublicIPPrefixSku> sku = default; Optional <ETag> etag = default; Optional <IList <string> > zones = default; Optional <ResourceIdentifier> id = default; Optional <string> name = default; Optional <ResourceType> type = default; Optional <AzureLocation> location = default; Optional <IDictionary <string, string> > tags = default; Optional <IPVersion> publicIPAddressVersion = default; Optional <IList <IPTag> > ipTags = default; Optional <int> prefixLength = default; Optional <string> ipPrefix = default; Optional <IReadOnlyList <SubResource> > publicIPAddresses = default; Optional <WritableSubResource> loadBalancerFrontendIpConfiguration = default; Optional <WritableSubResource> customIPPrefix = default; Optional <Guid> resourceGuid = default; Optional <NetworkProvisioningState> provisioningState = default; Optional <NatGatewayData> natGateway = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("extendedLocation")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } extendedLocation = Models.ExtendedLocation.DeserializeExtendedLocation(property.Value); continue; } if (property.NameEquals("sku")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } sku = PublicIPPrefixSku.DeserializePublicIPPrefixSku(property.Value); continue; } if (property.NameEquals("etag")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } etag = new ETag(property.Value.GetString()); continue; } if (property.NameEquals("zones")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetString()); } zones = array; continue; } if (property.NameEquals("id")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("location")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } location = new AzureLocation(property.Value.GetString()); continue; } if (property.NameEquals("tags")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("publicIPAddressVersion")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } publicIPAddressVersion = new IPVersion(property0.Value.GetString()); continue; } if (property0.NameEquals("ipTags")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <IPTag> array = new List <IPTag>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(IPTag.DeserializeIPTag(item)); } ipTags = array; continue; } if (property0.NameEquals("prefixLength")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } prefixLength = property0.Value.GetInt32(); continue; } if (property0.NameEquals("ipPrefix")) { ipPrefix = property0.Value.GetString(); continue; } if (property0.NameEquals("publicIPAddresses")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <SubResource> array = new List <SubResource>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(JsonSerializer.Deserialize <SubResource>(item.ToString())); } publicIPAddresses = array; continue; } if (property0.NameEquals("loadBalancerFrontendIpConfiguration")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } loadBalancerFrontendIpConfiguration = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("customIPPrefix")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } customIPPrefix = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("resourceGuid")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } resourceGuid = property0.Value.GetGuid(); continue; } if (property0.NameEquals("provisioningState")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } provisioningState = new NetworkProvisioningState(property0.Value.GetString()); continue; } if (property0.NameEquals("natGateway")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } natGateway = NatGatewayData.DeserializeNatGatewayData(property0.Value); continue; } } continue; } } return(new PublicIPPrefixData(id.Value, name.Value, Optional.ToNullable(type), Optional.ToNullable(location), Optional.ToDictionary(tags), extendedLocation.Value, sku.Value, Optional.ToNullable(etag), Optional.ToList(zones), Optional.ToNullable(publicIPAddressVersion), Optional.ToList(ipTags), Optional.ToNullable(prefixLength), ipPrefix.Value, Optional.ToList(publicIPAddresses), loadBalancerFrontendIpConfiguration, customIPPrefix, Optional.ToNullable(resourceGuid), Optional.ToNullable(provisioningState), natGateway.Value)); }
internal static PublicIPAddressData DeserializePublicIPAddressData(JsonElement element) { Optional <Models.ExtendedLocation> extendedLocation = default; Optional <PublicIPAddressSku> sku = default; Optional <ETag> etag = default; Optional <IList <string> > zones = default; Optional <ResourceIdentifier> id = default; Optional <string> name = default; Optional <ResourceType> type = default; Optional <AzureLocation> location = default; Optional <IDictionary <string, string> > tags = default; Optional <IPAllocationMethod> publicIPAllocationMethod = default; Optional <IPVersion> publicIPAddressVersion = default; Optional <IPConfiguration> ipConfiguration = default; Optional <PublicIPAddressDnsSettings> dnsSettings = default; Optional <DdosSettings> ddosSettings = default; Optional <IList <IPTag> > ipTags = default; Optional <string> ipAddress = default; Optional <WritableSubResource> publicIPPrefix = default; Optional <int> idleTimeoutInMinutes = default; Optional <Guid> resourceGuid = default; Optional <NetworkProvisioningState> provisioningState = default; Optional <PublicIPAddressData> servicePublicIPAddress = default; Optional <NatGatewayData> natGateway = default; Optional <PublicIPAddressMigrationPhase> migrationPhase = default; Optional <PublicIPAddressData> linkedPublicIPAddress = default; Optional <DeleteOptions> deleteOption = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("extendedLocation")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } extendedLocation = Models.ExtendedLocation.DeserializeExtendedLocation(property.Value); continue; } if (property.NameEquals("sku")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } sku = PublicIPAddressSku.DeserializePublicIPAddressSku(property.Value); continue; } if (property.NameEquals("etag")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } etag = new ETag(property.Value.GetString()); continue; } if (property.NameEquals("zones")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetString()); } zones = array; continue; } if (property.NameEquals("id")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("location")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } location = new AzureLocation(property.Value.GetString()); continue; } if (property.NameEquals("tags")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("publicIPAllocationMethod")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } publicIPAllocationMethod = new IPAllocationMethod(property0.Value.GetString()); continue; } if (property0.NameEquals("publicIPAddressVersion")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } publicIPAddressVersion = new IPVersion(property0.Value.GetString()); continue; } if (property0.NameEquals("ipConfiguration")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } ipConfiguration = IPConfiguration.DeserializeIPConfiguration(property0.Value); continue; } if (property0.NameEquals("dnsSettings")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } dnsSettings = PublicIPAddressDnsSettings.DeserializePublicIPAddressDnsSettings(property0.Value); continue; } if (property0.NameEquals("ddosSettings")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } ddosSettings = DdosSettings.DeserializeDdosSettings(property0.Value); continue; } if (property0.NameEquals("ipTags")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <IPTag> array = new List <IPTag>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(IPTag.DeserializeIPTag(item)); } ipTags = array; continue; } if (property0.NameEquals("ipAddress")) { ipAddress = property0.Value.GetString(); continue; } if (property0.NameEquals("publicIPPrefix")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } publicIPPrefix = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("idleTimeoutInMinutes")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } idleTimeoutInMinutes = property0.Value.GetInt32(); continue; } if (property0.NameEquals("resourceGuid")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } resourceGuid = property0.Value.GetGuid(); continue; } if (property0.NameEquals("provisioningState")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } provisioningState = new NetworkProvisioningState(property0.Value.GetString()); continue; } if (property0.NameEquals("servicePublicIPAddress")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } servicePublicIPAddress = DeserializePublicIPAddressData(property0.Value); continue; } if (property0.NameEquals("natGateway")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } natGateway = NatGatewayData.DeserializeNatGatewayData(property0.Value); continue; } if (property0.NameEquals("migrationPhase")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } migrationPhase = new PublicIPAddressMigrationPhase(property0.Value.GetString()); continue; } if (property0.NameEquals("linkedPublicIPAddress")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } linkedPublicIPAddress = DeserializePublicIPAddressData(property0.Value); continue; } if (property0.NameEquals("deleteOption")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } deleteOption = new DeleteOptions(property0.Value.GetString()); continue; } } continue; } } return(new PublicIPAddressData(id.Value, name.Value, Optional.ToNullable(type), Optional.ToNullable(location), Optional.ToDictionary(tags), extendedLocation.Value, sku.Value, Optional.ToNullable(etag), Optional.ToList(zones), Optional.ToNullable(publicIPAllocationMethod), Optional.ToNullable(publicIPAddressVersion), ipConfiguration.Value, dnsSettings.Value, ddosSettings.Value, Optional.ToList(ipTags), ipAddress.Value, publicIPPrefix, Optional.ToNullable(idleTimeoutInMinutes), Optional.ToNullable(resourceGuid), Optional.ToNullable(provisioningState), servicePublicIPAddress.Value, natGateway.Value, Optional.ToNullable(migrationPhase), linkedPublicIPAddress.Value, Optional.ToNullable(deleteOption))); }