Skip to content

Commit dffa6e4

Browse files
committed
Add new tests for legacy mode
1 parent 1dbc428 commit dffa6e4

File tree

5 files changed

+99
-10
lines changed

5 files changed

+99
-10
lines changed

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/BgpPeerings/GetAzureBGPPeering.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,4 @@ public override void ExecuteCmdlet()
4343
WriteObject(peer);
4444
}
4545
}
46-
47-
private enum LegacyMode
48-
{
49-
False = 0,
50-
True = 1
51-
}
5246
}

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/BgpPeerings/NewAzureBGPPeering.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public class NewAzureBGPPeeringCommand : ExpressRouteBaseCmdlet
3232
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Customer AS number")]
3333
public UInt32 CustomerAsn { get; set; }
3434

35-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
36-
HelpMessage = "Peer Asn")]
35+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Peer Asn")]
3736
public UInt32 PeerAsn { get; set; }
3837

3938
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Legacy Mode")]

src/ServiceManagement/Services/Commands.Test/Commands.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Compute.13.0.0\lib\net40\Microsoft.WindowsAzure.Management.Compute.dll</HintPath>
134134
</Reference>
135135
<Reference Include="Microsoft.WindowsAzure.Management.ExpressRoute">
136-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.20.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
136+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.21.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
137137
<Private>True</Private>
138138
</Reference>
139139
<Reference Include="Microsoft.WindowsAzure.Management.MediaServices">

src/ServiceManagement/Services/Commands.Test/ExpressRoute/AzureBgpPeeringTests.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,102 @@ public void NewAzureBgpPeeringSuccessful()
135135
Assert.Equal(expectedBgp.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort);
136136
}
137137

138+
[Fact]
139+
[Trait(Category.AcceptanceType, Category.CheckIn)]
140+
public void NewAzureMicrosoftBgpPeeringSuccessful()
141+
{
142+
// Setup
143+
string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead";
144+
UInt32 peerAsn = 64496;
145+
string primaryPeerSubnet = "aaa";
146+
string secondayPeerSubnet = "bbb";
147+
UInt32 azureAsn = 64494;
148+
string primaryAzurePort = "8081";
149+
string secondaryAzurePort = "8082";
150+
var state = BgpPeeringState.Enabled;
151+
uint vlanId = 2;
152+
var accessType = BgpPeeringAccessType.Microsoft;
153+
uint legacyMode = 0;
154+
string prefix = "12.2.3.4/30";
155+
156+
MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
157+
Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient();
158+
var bgpMock = new Mock<IBorderGatewayProtocolPeeringOperations>();
159+
160+
BorderGatewayProtocolPeeringGetResponse expectedBgp =
161+
new BorderGatewayProtocolPeeringGetResponse
162+
{
163+
BgpPeering = new AzureBgpPeering()
164+
{
165+
AzureAsn = azureAsn,
166+
PeerAsn = peerAsn,
167+
PrimaryAzurePort = primaryAzurePort,
168+
PrimaryPeerSubnet = primaryPeerSubnet,
169+
SecondaryAzurePort = secondaryAzurePort,
170+
SecondaryPeerSubnet = secondayPeerSubnet,
171+
State = state,
172+
VlanId = vlanId,
173+
LegacyMode = legacyMode,
174+
AdvertisedPublicPrefixes = prefix
175+
},
176+
RequestId = "",
177+
StatusCode = new HttpStatusCode()
178+
};
179+
180+
ExpressRouteOperationStatusResponse expectedStatus = new ExpressRouteOperationStatusResponse()
181+
{
182+
HttpStatusCode = HttpStatusCode.OK
183+
};
184+
185+
var tGet = new Task<BorderGatewayProtocolPeeringGetResponse>(() => expectedBgp);
186+
tGet.Start();
187+
188+
var tNew = new Task<ExpressRouteOperationStatusResponse>(() => expectedStatus);
189+
tNew.Start();
190+
191+
bgpMock.Setup(
192+
f =>
193+
f.NewAsync(It.Is<string>(x => x == serviceKey),
194+
It.Is<BgpPeeringAccessType>(
195+
y => y == accessType),
196+
It.Is<BorderGatewayProtocolPeeringNewParameters>(
197+
z =>
198+
z.PeerAutonomousSystemNumber == peerAsn && z.PrimaryPeerSubnet == primaryPeerSubnet &&
199+
z.SecondaryPeerSubnet == secondayPeerSubnet && z.VirtualLanId == vlanId),
200+
It.IsAny<CancellationToken>()))
201+
.Returns((string sKey, BgpPeeringAccessType atype, BorderGatewayProtocolPeeringNewParameters param, CancellationToken cancellation) => tNew);
202+
client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object);
203+
204+
bgpMock.Setup(
205+
f =>
206+
f.GetAsync(It.Is<string>(x => x == serviceKey),
207+
It.Is<BgpPeeringAccessType>(
208+
y => y == accessType),
209+
It.IsAny<CancellationToken>()))
210+
.Returns((string sKey, BgpPeeringAccessType atype, CancellationToken cancellation) => tGet);
211+
client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object);
212+
213+
NewAzureBGPPeeringCommand cmdlet = new NewAzureBGPPeeringCommand()
214+
{
215+
ServiceKey = Guid.Parse(serviceKey),
216+
AccessType = accessType,
217+
PeerAsn = peerAsn,
218+
PrimaryPeerSubnet = primaryPeerSubnet,
219+
SecondaryPeerSubnet = secondayPeerSubnet,
220+
SharedKey = null,
221+
VlanId = vlanId,
222+
CommandRuntime = mockCommandRuntime,
223+
ExpressRouteClient = new ExpressRouteClient(client.Object)
224+
};
225+
226+
cmdlet.ExecuteCmdlet();
227+
228+
// Assert
229+
AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering;
230+
Assert.Equal(expectedBgp.BgpPeering.State, actual.State);
231+
Assert.Equal(expectedBgp.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort);
232+
}
233+
138234
[Fact]
139235
[Trait(Category.AcceptanceType, Category.CheckIn)]
140236
public void GetAzureBgpPeeringSuccessful()

src/ServiceManagement/Services/Commands.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.0" targetFramework="net45" />
2121
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
2222
<package id="Microsoft.WindowsAzure.Management.Compute" version="13.0.0" targetFramework="net45" />
23-
<package id="Microsoft.WindowsAzure.Management.ExpressRoute" version="0.20.0-preview" targetFramework="net45" />
23+
<package id="Microsoft.WindowsAzure.Management.ExpressRoute" version="0.21.0-preview" targetFramework="net45" />
2424
<package id="Microsoft.WindowsAzure.Management.MediaServices" version="4.0.0" targetFramework="net45" />
2525
<package id="Microsoft.WindowsAzure.Management.ServiceBus" version="0.18.0-preview" targetFramework="net45" />
2626
<package id="Microsoft.WindowsAzure.Management.Storage" version="6.0.1" targetFramework="net45" />

0 commit comments

Comments
 (0)