Skip to content

Commit e12a122

Browse files
author
Ed Munoz
committed
Fix merge route table tests
1 parent 84aced1 commit e12a122

10 files changed

+568
-40
lines changed

src/ServiceManagement/Network/Commands.Network.Test/Commands.ServiceManagement.Network.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<Compile Include="NetworkSecurityGroups\SetNetworkSecurityGroupAssociationTests.cs" />
153153
<Compile Include="Properties\AssemblyInfo.cs" />
154154
<Compile Include="Routes\GetEffectiveRouteTests.cs" />
155+
<Compile Include="Routes\GetRouteTableTests.cs" />
155156
<Compile Include="Routes\GetSubnetRouteTableTests.cs" />
156157
<Compile Include="Routes\NewRouteTableTests.cs" />
157158
<Compile Include="Routes\RemoveRouteTableTests.cs" />

src/ServiceManagement/Network/Commands.Network.Test/Routes/GetEffectiveRouteTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,23 @@ public GetEffectiveRouteTests()
105105
[Fact]
106106
[Trait(Category.Service, Category.Network)]
107107
[Trait(Category.AcceptanceType, Category.CheckIn)]
108-
public void GetEffectiveRouteTableOnRoleSucceeds()
108+
public void GetEffectiveRouteTableOnRole()
109109
{
110110
GetEffectiveRouteTableForRoleInstance();
111111
}
112112

113113
[Fact]
114114
[Trait(Category.Service, Category.Network)]
115115
[Trait(Category.AcceptanceType, Category.CheckIn)]
116-
public void GetEffectiveRouteTableOnVMSucceeds()
116+
public void GetEffectiveRouteTableOnVM()
117117
{
118118
GetEffectiveRouteTableForVM();
119119
}
120120

121121
[Fact]
122122
[Trait(Category.Service, Category.Network)]
123123
[Trait(Category.AcceptanceType, Category.CheckIn)]
124-
public void GetEffectiveRouteTableOnVMNicSucceeds()
124+
public void GetEffectiveRouteTableOnVMNic()
125125
{
126126
GetEffectiveRouteTableForVMNic();
127127
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using System.Linq;
17+
using System.Management.Automation;
18+
using System.Threading;
19+
using System.Threading.Tasks;
20+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes;
23+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes.Model;
24+
using Microsoft.WindowsAzure.Management;
25+
using Microsoft.WindowsAzure.Management.Compute;
26+
using Microsoft.WindowsAzure.Management.Network;
27+
using Moq;
28+
using Xunit;
29+
using Models = Microsoft.WindowsAzure.Management.Network.Models;
30+
31+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.Routes
32+
{
33+
public class GetRouteTableTests
34+
{
35+
private const string RouteTableName = "routeTableName";
36+
private const string VirtualNetworkName = "virtualNetworkName";
37+
private const string SubnetName = "subnetName";
38+
private const string RouteTableLocation = "usnorth";
39+
private const string RouteTableLabel = "My Route Table label";
40+
41+
private IList<Models.Route> Routes = new List<Models.Route>()
42+
{
43+
new Models.Route()
44+
{
45+
Name = "rule1",
46+
AddressPrefix = "0.0.0.0/0",
47+
NextHop = new Models.NextHop()
48+
{
49+
Type = "VPNGateway"
50+
},
51+
State = Models.RouteState.Created
52+
},
53+
};
54+
55+
private MockCommandRuntime mockCommandRuntime;
56+
57+
private GetAzureRouteTable cmdlet;
58+
59+
private NetworkClient client;
60+
private Mock<INetworkManagementClient> networkingClientMock;
61+
private Mock<IComputeManagementClient> computeClientMock;
62+
private Mock<IManagementClient> managementClientMock;
63+
64+
public GetRouteTableTests()
65+
{
66+
this.networkingClientMock = new Mock<INetworkManagementClient>();
67+
this.computeClientMock = new Mock<IComputeManagementClient>();
68+
this.managementClientMock = new Mock<IManagementClient>();
69+
this.mockCommandRuntime = new MockCommandRuntime();
70+
this.client = new NetworkClient(
71+
networkingClientMock.Object,
72+
computeClientMock.Object,
73+
managementClientMock.Object,
74+
mockCommandRuntime);
75+
76+
this.networkingClientMock
77+
.Setup(c => c.Routes.GetRouteTableWithDetailsAsync(
78+
RouteTableName,
79+
NetworkClient.WithoutRoutesDetailLevel,
80+
It.IsAny<CancellationToken>()))
81+
.Returns(Task.Factory.StartNew(() =>
82+
new Models.GetRouteTableResponse()
83+
{
84+
RouteTable = new Models.RouteTable()
85+
{
86+
Name = RouteTableName,
87+
Location = RouteTableLocation,
88+
Label = RouteTableLabel,
89+
}
90+
}));
91+
92+
this.networkingClientMock
93+
.Setup(c => c.Routes.GetRouteTableWithDetailsAsync(
94+
RouteTableName,
95+
NetworkClient.WithRoutesDetailLevel,
96+
It.IsAny<CancellationToken>()))
97+
.Returns(Task.Factory.StartNew(() =>
98+
new Models.GetRouteTableResponse()
99+
{
100+
RouteTable = new Models.RouteTable()
101+
{
102+
Name = RouteTableName,
103+
Location = RouteTableLocation,
104+
Label = RouteTableLabel,
105+
RouteList = Routes
106+
}
107+
}));
108+
}
109+
110+
[Fact]
111+
[Trait(Category.Service, Category.Network)]
112+
[Trait(Category.AcceptanceType, Category.CheckIn)]
113+
public void GetRouteTableNoDetails()
114+
{
115+
// Setup
116+
cmdlet = new GetAzureRouteTable
117+
{
118+
Name = RouteTableName,
119+
CommandRuntime = mockCommandRuntime,
120+
Client = this.client
121+
};
122+
123+
// Action
124+
cmdlet.ExecuteCmdlet();
125+
126+
// Assert
127+
networkingClientMock.Verify(
128+
c => c.Routes.GetRouteTableWithDetailsAsync(
129+
RouteTableName,
130+
NetworkClient.WithoutRoutesDetailLevel,
131+
It.IsAny<CancellationToken>()),
132+
Times.Once);
133+
134+
Assert.Equal(1, mockCommandRuntime.OutputPipeline.Count);
135+
Assert.IsType<SimpleRouteTable>(mockCommandRuntime.OutputPipeline.Single());
136+
var routeTable = (SimpleRouteTable)(mockCommandRuntime.OutputPipeline.Single());
137+
Assert.Equal(RouteTableName, routeTable.Name);
138+
Assert.Equal(RouteTableLabel, routeTable.Label);
139+
Assert.Equal(RouteTableLocation, routeTable.Location);
140+
}
141+
142+
[Fact]
143+
[Trait(Category.Service, Category.Network)]
144+
[Trait(Category.AcceptanceType, Category.CheckIn)]
145+
public void GetRouteTableForSubnetDetails()
146+
{
147+
// Setup
148+
cmdlet = new GetAzureRouteTable
149+
{
150+
Name = RouteTableName,
151+
CommandRuntime = mockCommandRuntime,
152+
Client = this.client,
153+
Detailed = new SwitchParameter(true)
154+
};
155+
156+
// Action
157+
cmdlet.ExecuteCmdlet();
158+
159+
// Assert
160+
networkingClientMock.Verify(
161+
c => c.Routes.GetRouteTableWithDetailsAsync(
162+
RouteTableName,
163+
NetworkClient.WithRoutesDetailLevel,
164+
It.IsAny<CancellationToken>()),
165+
Times.Once);
166+
167+
Assert.Equal(1, mockCommandRuntime.OutputPipeline.Count);
168+
Assert.IsType<RouteTableWithRoutes>(mockCommandRuntime.OutputPipeline.Single());
169+
var routeTable = (RouteTableWithRoutes)(mockCommandRuntime.OutputPipeline.Single());
170+
Assert.Equal(RouteTableName, routeTable.Name);
171+
Assert.Equal(RouteTableLabel, routeTable.Label);
172+
Assert.Equal(RouteTableLocation, routeTable.Location);
173+
Assert.NotEmpty(routeTable.Routes);
174+
Assert.Equal(Routes.First().Name, routeTable.Routes.First().Name);
175+
Assert.Equal(Routes.First().AddressPrefix, routeTable.Routes.First().AddressPrefix);
176+
Assert.Equal(Routes.First().NextHop.IpAddress, routeTable.Routes.First().NextHop.IpAddress);
177+
Assert.Equal(Routes.First().NextHop.Type, routeTable.Routes.First().NextHop.Type);
178+
}
179+
}
180+
}

src/ServiceManagement/Network/Commands.Network.Test/Routes/GetSubnetRouteTableTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.Network.Routes;
16-
using Microsoft.Azure.Commands.Network.Routes.Model;
17-
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
18-
using Microsoft.WindowsAzure.Management;
19-
using Microsoft.WindowsAzure.Management.Compute;
20-
using Microsoft.WindowsAzure.Management.Network;
21-
using Moq;
2215
using System.Collections.Generic;
2316
using System.Linq;
2417
using System.Management.Automation;
2518
using System.Threading;
2619
using System.Threading.Tasks;
20+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2721
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes;
23+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes.Model;
24+
using Microsoft.WindowsAzure.Management;
25+
using Microsoft.WindowsAzure.Management.Compute;
26+
using Microsoft.WindowsAzure.Management.Network;
27+
using Moq;
2828
using Xunit;
2929
using Models = Microsoft.WindowsAzure.Management.Network.Models;
3030

31-
namespace Microsoft.Azure.Commands.Network.Test.Routes
31+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.Routes
3232
{
3333
public class GetSubnetRouteTableTests
3434
{

src/ServiceManagement/Network/Commands.Network.Test/Routes/NewRouteTableTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
using System.Linq;
1616
using System.Threading;
1717
using System.Threading.Tasks;
18-
using Microsoft.Azure.Commands.Network.Routes;
19-
using Microsoft.Azure.Commands.Network.Routes.Model;
2018
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2119
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes;
21+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes.Model;
22+
using Microsoft.WindowsAzure.Management;
2223
using Microsoft.WindowsAzure.Management.Compute;
2324
using Microsoft.WindowsAzure.Management.Network;
24-
using Moq;
25-
using Microsoft.WindowsAzure.Management;
2625
using Microsoft.WindowsAzure.Management.Network.Models;
26+
using Moq;
2727
using Xunit;
2828
using Models = Microsoft.WindowsAzure.Management.Network.Models;
2929

30-
namespace Microsoft.Azure.Commands.Network.Test.Routes
30+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.Routes
3131
{
3232
public class NewRouteTableTests
3333
{

src/ServiceManagement/Network/Commands.Network.Test/Routes/RemoveRouteTableTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System.Threading;
16+
using System.Threading.Tasks;
1517
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes;
1620
using Microsoft.WindowsAzure.Management;
1721
using Microsoft.WindowsAzure.Management.Compute;
1822
using Microsoft.WindowsAzure.Management.Network;
1923
using Moq;
20-
using System.Threading;
21-
using System.Threading.Tasks;
22-
using Microsoft.Azure.Commands.Network.Routes;
23-
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2424
using Xunit;
2525

26-
namespace Microsoft.Azure.Commands.Network.Test.Routes
26+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.Routes
2727
{
2828
public class RemoveRouteTableTests
2929
{

src/ServiceManagement/Network/Commands.Network.Test/Routes/RemoveRouteTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
using System.Linq;
1616
using System.Threading;
1717
using System.Threading.Tasks;
18-
using Microsoft.Azure.Commands.Network.Routes;
19-
using Microsoft.Azure.Commands.Network.Routes.Model;
2018
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2119
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes;
21+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Routes.Model;
22+
using Microsoft.WindowsAzure.Management;
2223
using Microsoft.WindowsAzure.Management.Compute;
2324
using Microsoft.WindowsAzure.Management.Network;
24-
using Moq;
25-
using Microsoft.WindowsAzure.Management;
2625
using Microsoft.WindowsAzure.Management.Network.Models;
26+
using Moq;
2727
using Xunit;
2828
using Models = Microsoft.WindowsAzure.Management.Network.Models;
2929

30-
namespace Microsoft.Azure.Commands.Network.Test.Routes
30+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.Routes
3131
{
3232
public class RemoveRouteTests
3333
{

0 commit comments

Comments
 (0)