Skip to content

Commit

Permalink
Merge pull request #1 from t-alguer/ignite_team
Browse files Browse the repository at this point in the history
Filtering and Pagination
  • Loading branch information
vladca committed Apr 3, 2015
2 parents 7c5772d + 8e191cc commit 9a23cc1
Show file tree
Hide file tree
Showing 15 changed files with 1,875 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
<Compile Include="ScenarioTests\ZoneTests.cs" />
<Compile Include="ScenarioTests\RecordsTests.cs" />
<Compile Include="ScenarioTests\DnsTestsBase.cs" />
<Compile Include="UnitTests\GetAzureDnsRecordSetTests.cs" />
<Compile Include="UnitTests\GetAzureDnsZoneTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common\Commands.ScenarioTests.Common\Commands.ScenarioTests.Common.csproj">
Expand Down Expand Up @@ -194,6 +196,7 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetCrudWithPiping.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetEtagMismatch.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetGet.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetGetWithEndsWith.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetMX.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetNS.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetRemoveRecordTypeMismatch.json" />
Expand All @@ -202,6 +205,7 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneCrud.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneCrudWithPiping.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneList.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneListWithEndsWith.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneRemoveEtagMismatch.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneRemoveNotFound.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneSetEtagMismatch.json" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,12 @@ public void TestRecordSetGet()
{
RunPowerShellTest("Test-RecordSetGet");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestRecordSetGetWithEndsWith()
{
RunPowerShellTest("Test-RecordSetGetWithEndsWith");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function Test-RecordSetSRV
$record = $record | Add-AzureDnsRecordConfig -Port 53 -Priority 1 -Target ns1.example.com -Weight 5
$record = $record | Add-AzureDnsRecordConfig -Port 53 -Priority 2 -Target ns2.example.com -Weight 10
$record = $record | Remove-AzureDnsRecordConfig -Port 53 -Priority 2 -Target ns2.example.com -Weight 10
$record = $record | Remove-AzureDnsRecordConfig -Port 42 -Priority 2435435 -Target ns5.example.com -Weight 1600
$record = $record | Remove-AzureDnsRecordConfig -Port 42 -Priority 999 -Target ns5.example.com -Weight 1600

$record | Set-AzureDnsRecordSet
$getResult = Get-AzureDnsRecordSet -Name $recordName -ZoneName $zoneName -ResourceGroupName $resourceGroup.ResourceGroupName -RecordType SRV
Expand Down Expand Up @@ -518,7 +518,7 @@ function Test-RecordSetRemoveRecordTypeMismatch

<#
.SYNOPSIS
Zone CRUD with piping
Record Set Etag Mismatch
#>
function Test-RecordSetEtagMismatch
{
Expand All @@ -543,7 +543,7 @@ function Test-RecordSetEtagMismatch

<#
.SYNOPSIS
Zone CRUD with piping
Record Set Get
#>
function Test-RecordSetGet
{
Expand Down Expand Up @@ -582,5 +582,51 @@ function Test-RecordSetGet
$zone | Remove-AzureDnsRecordSet -Name $recordName2 -RecordType AAAA -Force
$zone | Remove-AzureDnsRecordSet -Name $recordName3 -RecordType MX -Force

$zone | Remove-AzureDnsZone -Force -IgnoreEtag
}

<#
.SYNOPSIS
Record Set Get using EndsWith parameter
#>
function Test-RecordSetGetWithEndsWith
{
$rootRecordName = "@"
$recordSuffix = ".com"
$anotherSuffix = ".con"

$zoneName = getAssetname

$recordName1 = (getAssetname) + $recordSuffix
$recordName2 = (getAssetname) + $anotherSuffix
$recordName3 = (getAssetname) + $recordSuffix

$zone = TestSetup-CreateResourceGroup | New-AzureDnsZone -Name $zoneName

# test for root records
$rootRecords = $zone | Get-AzureDnsRecordSet -EndsWith $rootRecordName

Assert-AreEqual 2 $rootRecords.Count -Message ("Expected 2 root records. Actual: " + $rootRecords.Count)

New-AzureDnsRecordSet -Zone $zone -Name $recordName1 -Ttl 100 -RecordType AAAA
New-AzureDnsRecordSet -Zone $zone -Name $recordName2 -Ttl 1200 -RecordType AAAA
New-AzureDnsRecordSet -Zone $zone -Name $recordName3 -Ttl 1500 -RecordType MX

# test for records within type
$aaaaRecords = $zone | Get-AzureDnsRecordSet -RecordType AAAA -EndsWith $recordSuffix
$mxRecords = $zone | Get-AzureDnsRecordSet -RecordType MX -EndsWith $recordSuffix

Assert-AreEqual 1 $aaaaRecords.Count -Message ("Expected 1 AAAA record. Actual: " + $aaaaRecords.Count)
Assert-AreEqual 1 $mxRecords.Count -Message ("Expected 1 MX record. Actual: " + $mxRecords.Count)

# all records
$allRecords = $zone | Get-AzureDnsRecordSet -EndsWith $recordSuffix

Assert-AreEqual 2 $allRecords.Count -Message ("Expected 2 records across types. Actual: " + $allRecords.Count)

$zone | Remove-AzureDnsRecordSet -Name $recordName1 -RecordType AAAA -Force
$zone | Remove-AzureDnsRecordSet -Name $recordName2 -RecordType AAAA -Force
$zone | Remove-AzureDnsRecordSet -Name $recordName3 -RecordType MX -Force

$zone | Remove-AzureDnsZone -Force -IgnoreEtag
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public void TestZoneList()
{
RunPowerShellTest("Test-ZoneList");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestZoneListWithEndsWith()
{
RunPowerShellTest("Test-ZoneListWithEndsWith");
}

[Fact(Skip = "Service does not yet support this")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,30 @@ function Test-ZoneList
Assert-NotNull $resourceGroup.ResourceGroupName $result[1].ResourceGroupName
Assert-AreEqual 0 $result[1].Tags.Count

$result | Remove-AzureDnsZone -PassThru -Force
}

<#
.SYNOPSIS
Zone List With EndsWith
#>
function Test-ZoneListWithEndsWith
{
$suffix = ".com"
$suffixWithDot = ".com."
$zoneName1 = getAssetname
$zoneName2 = $zoneName1 + $suffix
$resourceGroup = TestSetup-CreateResourceGroup
$createdZone1 = $resourceGroup | New-AzureDnsZone -Name $zoneName1
$createdZone2 = $resourceGroup | New-AzureDnsZone -Name $zoneName2

$result = Get-AzureDnsZone -ResourceGroupName $resourceGroup.ResourceGroupName -EndsWith $suffixWithDot

Assert-AreEqual 1 $result.Count

Assert-AreEqual $createdZone2.Etag $result[0].Etag
Assert-AreEqual $createdZone2.Name $result[0].Name
Assert-NotNull $resourceGroup.ResourceGroupName $result[0].ResourceGroupName

$result | Remove-AzureDnsZone -PassThru -Force
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Dns.Test.UnitTests
{
using System.Management.Automation;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

public class GetAzureDnsRecordSetTests
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetAzureDnsRecordSetThrowsExceptionWhenUsingNameAndEndsWith()
{
var cmdlet = new GetAzureDnsRecordSet
{
Name = "record",
ZoneName = "zone.com",
ResourceGroupName = "resourceGroup",
Zone = new DnsZone
{
Name = "zone.com",
ResourceGroupName = "resourceGroup"
},
RecordType = "A",
EndsWith = ".com."
};

Assert.Throws<PSArgumentException>(() => cmdlet.ExecuteCmdlet());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Dns.Test.UnitTests
{
using System.Management.Automation;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

public class GetAzureDnsZoneTests
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetAzureDnsZoneThrowsExceptionWhenUsingNameAndEndsWith()
{
var cmdlet = new GetAzureDnsZone
{
Name = "record",
ResourceGroupName = "resourceGroup",
EndsWith = ".com."
};

Assert.Throws<PSArgumentException>(() => cmdlet.ExecuteCmdlet());
}
}
}
27 changes: 21 additions & 6 deletions src/ResourceManager/Dns/Commands.Dns/Models/DnsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ public DnsZone GetDnsZone(string name, string resourceGroupName)
};
}

public List<DnsZone> ListDnsZones(string resourceGroupName)
public List<DnsZone> ListDnsZones(string resourceGroupName, string endsWith)
{
ZoneListResponse getResponse = this.DnsManagementClient.Zones.List(resourceGroupName);
ZoneListParameters zoneListParameters = new ZoneListParameters
{
Filter = endsWith == null ? null : string.Format("endswith(Name,'{0}')", endsWith)
};

ZoneListResponse getResponse = this.DnsManagementClient.Zones.List(resourceGroupName, zoneListParameters);
return getResponse.Zones.Select(zoneInResponse => new DnsZone
{
Name = zoneInResponse.Name,
Expand Down Expand Up @@ -229,18 +234,28 @@ public DnsRecordSet GetDnsRecordSet(string name, string zoneName, string resourc
return GetPowerShellRecordSet(zoneName, resourceGroupName, getResponse.RecordSet);
}

public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupName, RecordType recordType)
public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupName, RecordType recordType, string endsWith)
{
RecordListResponse listResponse = this.DnsManagementClient.Records.List(resourceGroupName, zoneName, recordType);
RecordListParameters recordListParameters = new RecordListParameters
{
Filter = endsWith == null ? null : string.Format("endswith(Name,'{0}')", endsWith)
};

RecordListResponse listResponse = this.DnsManagementClient.Records.List(resourceGroupName, zoneName, recordType, recordListParameters);
return listResponse
.RecordSets
.Select(recordSetInResponse => GetPowerShellRecordSet(zoneName, resourceGroupName, recordSetInResponse))
.ToList();
}

public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupName)
public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupName, string endsWith)
{
RecordListResponse listResponse = this.DnsManagementClient.Records.ListAll(resourceGroupName, zoneName);
RecordListParameters recordListParameters = new RecordListParameters
{
Filter = endsWith == null ? null : string.Format("endswith(Name,'{0}')", endsWith)
};

RecordListResponse listResponse = this.DnsManagementClient.Records.ListAll(resourceGroupName, zoneName, recordListParameters);
return listResponse
.RecordSets
.Select(recordSetInResponse => GetPowerShellRecordSet(zoneName, resourceGroupName, recordSetInResponse))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<data name="Error_EtagNotSpecified" xml:space="preserve">
<value>The ETag property of the {0} object is empty or "*". In order to perform this operation with optimistic concurrency checks, please set the Etag property (you may need to Get the {0} first). In order to perform the operation without optimistic concurrency checks, please specify the -IgnoreEtag switch. </value>
</data>
<data name="Error_NameAndEndsWith" xml:space="preserve">
<value>Name parameter cannot be used with EndsWith.</value>
</data>
<data name="Error_RemoveRecordTypeMismatch" xml:space="preserve">
<value>Cannot remove a record of type {0} from a record set of type {1}. The types must match.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public class GetAzureDnsRecordSet : DnsBaseCmdlet
[ValidateNotNullOrEmpty]
public string RecordType { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The single or multiple label suffix to search in the relative name.")]
[ValidateNotNullOrEmpty]
public string EndsWith { get; set; }

public override void ExecuteCmdlet()
{
RecordType recordType = default(RecordType);
Expand All @@ -72,7 +76,11 @@ public override void ExecuteCmdlet()
resourceGroupName = this.Zone.ResourceGroupName;
}

if (this.Name != null)
if (this.Name != null && this.EndsWith != null)
{
throw new PSArgumentException(ProjectResources.Error_NameAndEndsWith);
}
else if (this.Name != null)
{
if (this.RecordType == null)
{
Expand All @@ -87,11 +95,11 @@ public override void ExecuteCmdlet()
List<DnsRecordSet> result = null;
if (this.RecordType == null)
{
result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName);
result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, this.EndsWith);
}
else
{
result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, recordType);
result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, recordType, this.EndsWith);
}

this.WriteObject(result);
Expand Down
Loading

0 comments on commit 9a23cc1

Please sign in to comment.