Skip to content

Commit 8b8eded

Browse files
author
unknown
committed
added more mocks
1 parent ca5afb8 commit 8b8eded

File tree

18 files changed

+4860
-4819
lines changed

18 files changed

+4860
-4819
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Network/AddAzureVirtualIP.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Network
2424
[Cmdlet(VerbsCommon.Add, "AzureVirtualIP"), OutputType(typeof(ManagementOperationContext))]
2525
public class AddAzureVirtualIP : ServiceManagementBaseCmdlet
2626
{
27+
public AddAzureVirtualIP()
28+
{
29+
}
30+
31+
public AddAzureVirtualIP(IClientProvider provider) : base(provider)
32+
{
33+
}
34+
2735
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = false)]
2836
[ValidateNotNullOrEmpty]
2937
public string ServiceName { get; set; }

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Network/RemoveAzureReservedIP.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
2323
[Cmdlet(VerbsCommon.Remove, ReservedIPConstants.CmdletNoun, DefaultParameterSetName = RemoveReservedIPParamSet), OutputType(typeof(ManagementOperationContext))]
2424
public class RemoveAzureReservedIPCmdlet : ServiceManagementBaseCmdlet
2525
{
26+
public RemoveAzureReservedIPCmdlet()
27+
{
28+
}
29+
30+
public RemoveAzureReservedIPCmdlet(IClientProvider provider)
31+
: base(provider)
32+
{
33+
}
34+
2635
protected const string RemoveReservedIPParamSet = "RemoveReservedIP";
2736

2837
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, HelpMessage = "Reserved IP Name.")]
@@ -32,7 +41,7 @@ public class RemoveAzureReservedIPCmdlet : ServiceManagementBaseCmdlet
3241
[Parameter(Position = 1, HelpMessage = "Do not confirm deletion of deployment")]
3342
public SwitchParameter Force { get; set; }
3443

35-
protected override void OnProcessRecord()
44+
public override void ExecuteCmdlet()
3645
{
3746
ServiceManagementProfile.Initialize();
3847

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Network/SetAzureReservedIPAssociation.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
2626
[Cmdlet(VerbsCommon.Set, ReservedIPConstants.AssociationCmdletNoun), OutputType(typeof(ManagementOperationContext))]
2727
public class SetAzureReservedIPAssociationCmdlet : ServiceManagementBaseCmdlet
2828
{
29+
public SetAzureReservedIPAssociationCmdlet()
30+
{
31+
}
32+
33+
public SetAzureReservedIPAssociationCmdlet(IClientProvider provider)
34+
: base(provider)
35+
{
36+
}
37+
2938
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, HelpMessage = "Reserved IP Name.")]
3039
[ValidateNotNullOrEmpty]
3140
public string ReservedIPName
@@ -58,7 +67,7 @@ public string Slot
5867
set;
5968
}
6069

61-
protected override void OnProcessRecord()
70+
public override void ExecuteCmdlet()
6271
{
6372
ServiceManagementProfile.Initialize();
6473

src/ServiceManagement/Compute/Commands.ServiceManagement/RemoveAzureVirtualIP.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
14+
1415
using System.Management.Automation;
1516
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1617
using Microsoft.WindowsAzure.Management.Network;
@@ -23,6 +24,15 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
2324
[Cmdlet(VerbsCommon.Remove, "AzureVirtualIP"), OutputType(typeof(ManagementOperationContext))]
2425
public class RemoveAzureVirtualIP : ServiceManagementBaseCmdlet
2526
{
27+
public RemoveAzureVirtualIP()
28+
{
29+
}
30+
31+
public RemoveAzureVirtualIP(IClientProvider provider)
32+
: base(provider)
33+
{
34+
}
35+
2636
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = false)]
2737
[ValidateNotNullOrEmpty]
2838
public string ServiceName { get; set; }

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@
149149
<ItemGroup>
150150
<Compile Include="IPForwarding\GetIPForwardingTests.cs" />
151151
<Compile Include="IPForwarding\SetIPForwardingTests.cs" />
152+
<Compile Include="Multivip\MultivipTests.cs" />
152153
<Compile Include="NetworkSecurityGroups\GetNetworkSecurityGroupAssociationTests.cs" />
153154
<Compile Include="NetworkSecurityGroups\RemoveNetworkSecurityGroupAssociationTests.cs" />
154155
<Compile Include="NetworkSecurityGroups\SetNetworkSecurityGroupAssociationTests.cs" />
155156
<Compile Include="Properties\AssemblyInfo.cs" />
156-
<Compile Include="ReservedIP\NewAzureReservedIPTest.cs" />
157+
<Compile Include="ReservedIP\ReservedIPTest.cs" />
157158
<Compile Include="Routes\GetEffectiveRouteTests.cs" />
158159
<Compile Include="Routes\GetRouteTableTests.cs" />
159160
<Compile Include="Routes\GetSubnetRouteTableTests.cs" />
@@ -231,6 +232,9 @@
231232
<None Include="ScenarioTests\ReservedIPs\ReservedIPTests.ps1">
232233
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
233234
</None>
235+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.ScenarioTests.MultiVip.MultiVipScenarioTests\AdditionalVipLifecycle.json">
236+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
237+
</None>
234238
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.ScenarioTests.MultiVip.MultiVipScenarioTests\AdditionalVipMobility.json">
235239
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
236240
</None>
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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.Threading;
16+
using System.Threading.Tasks;
17+
using Microsoft.Azure;
18+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS;
21+
using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Network;
22+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.TestInterfaces;
23+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24+
using Microsoft.WindowsAzure.Management.Compute;
25+
using Microsoft.WindowsAzure.Management.Network;
26+
using Moq;
27+
using Microsoft.WindowsAzure.Management.Compute.Models;
28+
using Microsoft.WindowsAzure.Management;
29+
using Microsoft.WindowsAzure.Management.Storage;
30+
using Xunit;
31+
using Assert = Xunit.Assert;
32+
33+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.Multivip
34+
{
35+
public class MultivipTests
36+
{
37+
private Mock<NetworkManagementClient> networkingClientMock;
38+
private Mock<ComputeManagementClient> computeClientMock;
39+
private Mock<ManagementClient> managementClientMock;
40+
private Mock<StorageManagementClient> storageClientMock;
41+
private IClientProvider testClientProvider;
42+
private MockCommandRuntime mockCommandRuntime;
43+
public const string ServiceName = "ServiceName";
44+
public const string DeploymentName = "DeploymentName";
45+
public const string VipName = "VipName";
46+
47+
public MultivipTests()
48+
{
49+
this.networkingClientMock = new Mock<NetworkManagementClient>();
50+
this.computeClientMock = new Mock<ComputeManagementClient>();
51+
this.managementClientMock = new Mock<ManagementClient>();
52+
this.storageClientMock = new Mock<StorageManagementClient>();
53+
this.mockCommandRuntime = new MockCommandRuntime();
54+
testClientProvider = new TestClientProvider(this.managementClientMock.Object, this.computeClientMock.Object,
55+
this.storageClientMock.Object, this.networkingClientMock.Object);
56+
57+
testClientProvider = new TestClientProvider(this.managementClientMock.Object,
58+
this.computeClientMock.Object, this.storageClientMock.Object, this.networkingClientMock.Object);
59+
60+
this.computeClientMock
61+
.Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
62+
.Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
63+
{
64+
Name = DeploymentName
65+
}));
66+
67+
this.networkingClientMock
68+
.Setup(c => c.VirtualIPs.AddAsync(
69+
ServiceName,
70+
DeploymentName,
71+
VipName,
72+
It.IsAny<CancellationToken>()))
73+
.Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
74+
{
75+
Status = OperationStatus.Succeeded
76+
}));
77+
78+
79+
this.networkingClientMock
80+
.Setup(c => c.VirtualIPs.RemoveAsync(
81+
ServiceName,
82+
DeploymentName,
83+
VipName,
84+
It.IsAny<CancellationToken>()))
85+
.Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
86+
{
87+
Status = OperationStatus.Succeeded
88+
}));
89+
}
90+
91+
[Fact]
92+
[Trait(Category.Service, Category.Network)]
93+
[Trait(Category.AcceptanceType, Category.CheckIn)]
94+
public void AddAzureVirtualIP()
95+
{
96+
AddAzureVirtualIP cmdlet = new AddAzureVirtualIP(testClientProvider)
97+
{
98+
ServiceName = ServiceName,
99+
VirtualIPName = VipName,
100+
CommandRuntime = mockCommandRuntime,
101+
};
102+
103+
// Action
104+
cmdlet.ExecuteCmdlet();
105+
106+
// Assert
107+
computeClientMock.Verify(
108+
c => c.Deployments.GetBySlotAsync(
109+
ServiceName,
110+
DeploymentSlot.Production,
111+
It.IsAny<CancellationToken>()),
112+
Times.Once);
113+
114+
networkingClientMock.Verify(
115+
c => c.VirtualIPs.AddAsync(
116+
ServiceName,
117+
DeploymentName,
118+
VipName,
119+
It.IsAny<CancellationToken>()),
120+
Times.Once());
121+
122+
Assert.Equal(1, mockCommandRuntime.OutputPipeline.Count);
123+
Assert.Equal("Succeeded", ((ManagementOperationContext)mockCommandRuntime.OutputPipeline[0]).OperationStatus);
124+
}
125+
126+
[Fact]
127+
[Trait(Category.Service, Category.Network)]
128+
[Trait(Category.AcceptanceType, Category.CheckIn)]
129+
public void RemoveAzureVirtualIP()
130+
{
131+
RemoveAzureVirtualIP cmdlet = new RemoveAzureVirtualIP(testClientProvider)
132+
{
133+
ServiceName = ServiceName,
134+
VirtualIPName = VipName,
135+
CommandRuntime = mockCommandRuntime,
136+
};
137+
138+
// Action
139+
cmdlet.ExecuteCmdlet();
140+
141+
// Assert
142+
computeClientMock.Verify(
143+
c => c.Deployments.GetBySlotAsync(
144+
ServiceName,
145+
DeploymentSlot.Production,
146+
It.IsAny<CancellationToken>()),
147+
Times.Once);
148+
149+
networkingClientMock.Verify(
150+
c => c.VirtualIPs.RemoveAsync(
151+
ServiceName,
152+
DeploymentName,
153+
VipName,
154+
It.IsAny<CancellationToken>()),
155+
Times.Once());
156+
157+
Assert.Equal(1, mockCommandRuntime.OutputPipeline.Count);
158+
Assert.Equal("Succeeded", ((ManagementOperationContext)mockCommandRuntime.OutputPipeline[0]).OperationStatus);
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)