Skip to content

Commit 44f49b6

Browse files
committed
Fixing a bug in the mock file
1 parent e7aedc8 commit 44f49b6

File tree

12 files changed

+79
-42
lines changed

12 files changed

+79
-42
lines changed

src/Common/Commands.Common.Test/Mocks/MockCommandRuntime.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,18 @@ public void WriteError(ErrorRecord errorRecord)
102102

103103
public void WriteObject(object sendToPipeline, bool enumerateCollection)
104104
{
105-
OutputPipeline.Add(sendToPipeline);
105+
System.Collections.IEnumerable enumerable = LanguagePrimitives.GetEnumerable(sendToPipeline);
106+
if (enumerable != null && enumerateCollection)
107+
{
108+
foreach (object o in enumerable)
109+
{
110+
OutputPipeline.Add(o);
111+
}
112+
}
113+
else
114+
{
115+
OutputPipeline.Add(sendToPipeline);
116+
}
106117
}
107118

108119
public void WriteObject(object sendToPipeline)

src/ServiceManagement/Services/Commands.Test/CloudService/Development/GetAzureServiceProjectRuntimesTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public void TestGetRuntimes()
5252

5353
cmdlet.GetAzureRuntimesProcess(string.Empty, manifest);
5454

55-
List<CloudRuntimePackage> actual = mockCommandRuntime.OutputPipeline[0] as List<CloudRuntimePackage>;
55+
IEnumerable<CloudRuntimePackage> actual = System.Management.Automation.LanguagePrimitives.GetEnumerable( mockCommandRuntime.OutputPipeline).Cast<CloudRuntimePackage>();
5656

57-
Assert.Equal<int>(runtimes.Count, actual.Count);
57+
Assert.Equal<int>(runtimes.Count, actual.Count());
5858
Assert.True(runtimes.All<CloudRuntimePackage>(p => actual.Any<CloudRuntimePackage>(p2 => p2.PackageUri.Equals(p.PackageUri))));
5959
}
6060
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,10 @@ public void ListAzureDedicatedCircuitLinkSuccessful()
221221
cmdlet.ExecuteCmdlet();
222222

223223
// Assert
224-
IEnumerable<AzureDedicatedCircuitLink> actual =
225-
mockCommandRuntime.OutputPipeline[0] as IEnumerable<AzureDedicatedCircuitLink>;
226-
Assert.Equal(actual.ToArray().Count(), 2);
224+
IEnumerable<AzureDedicatedCircuitLink> actual =
225+
System.Management.Automation.LanguagePrimitives.GetEnumerable(mockCommandRuntime.OutputPipeline ).Cast<AzureDedicatedCircuitLink>();
226+
227+
Assert.Equal(actual.Count(), 2);
227228
}
228229
}
229230
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ public void ListAzureDedicatedCircuitServiceProviderSuccessful()
114114
cmdlet.ExecuteCmdlet();
115115

116116
// Assert
117-
IEnumerable<AzureDedicatedCircuitServiceProvider> actual =
118-
mockCommandRuntime.OutputPipeline[0] as IEnumerable<AzureDedicatedCircuitServiceProvider>;
119-
Assert.Equal(actual.ToArray().Count(), 2);
117+
IEnumerable<AzureDedicatedCircuitServiceProvider> actual =
118+
System.Management.Automation.LanguagePrimitives.GetEnumerable(mockCommandRuntime.OutputPipeline).Cast<AzureDedicatedCircuitServiceProvider>();
119+
120+
Assert.Equal(actual.Count(), 2);
120121
}
121122
}
122123
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using Microsoft.WindowsAzure.Management.ExpressRoute.Models;
2828
using Moq;
2929
using Microsoft.Azure;
30+
using System.Management.Automation;
3031

3132
namespace Microsoft.WindowsAzure.Commands.Test.ExpressRoute
3233
{
@@ -251,9 +252,9 @@ public void ListAzureDedicatedCircuitSuccessful()
251252
cmdlet.ExecuteCmdlet();
252253

253254
// Assert
254-
IEnumerable<AzureDedicatedCircuit> actual =
255-
mockCommandRuntime.OutputPipeline[0] as IEnumerable<AzureDedicatedCircuit>;
256-
Assert.Equal(actual.ToArray().Count(), 2);
255+
IEnumerable<AzureDedicatedCircuit> actual = LanguagePrimitives.GetEnumerable(mockCommandRuntime.OutputPipeline).Cast<AzureDedicatedCircuit>();
256+
257+
Assert.Equal(actual.Count(), 2);
257258
}
258259
}
259260
}

src/ServiceManagement/Services/Commands.Test/MediaServices/GetAzureMediaServicesTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ public void ProcessGetMediaServicesTest()
7777
currentProfile.Subscriptions[new Guid(SubscriptionId)] = subscription;
7878

7979
getAzureMediaServiceCommand.ExecuteCmdlet();
80-
Assert.Equal(1, ((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.Count);
81-
IEnumerable<MediaServiceAccount> accounts = (IEnumerable<MediaServiceAccount>)((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
80+
81+
IEnumerable<MediaServiceAccount> accounts = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline).Cast<MediaServiceAccount>();
82+
8283
Assert.NotNull(accounts);
84+
Assert.Equal(2, accounts.Count());
8385
Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id1));
8486
Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id2));
8587
Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 1")));

src/ServiceManagement/Services/Commands.Test/ServiceBus/GetAzureSBLocationTest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System.Collections.Generic;
16+
using System.Linq;
1617
using Xunit;
1718
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
1819
using Microsoft.WindowsAzure.Commands.ServiceBus;
@@ -51,13 +52,15 @@ public void GetAzureSBLocationSuccessfull()
5152
cmdlet.ExecuteCmdlet();
5253

5354
// Assert
54-
List<ServiceBusLocation> actual = mockCommandRuntime.OutputPipeline[0] as List<ServiceBusLocation>;
55-
Assert.Equal<int>(expected.Count, actual.Count);
55+
IEnumerable<ServiceBusLocation> actual =
56+
System.Management.Automation.LanguagePrimitives.GetEnumerable(mockCommandRuntime.OutputPipeline).Cast<ServiceBusLocation>();
57+
58+
Assert.Equal<int>(expected.Count, actual.Count());
5659

5760
for (int i = 0; i < expected.Count; i++)
5861
{
59-
Assert.Equal<string>(expected[i].Code, actual[i].Code);
60-
Assert.Equal<string>(expected[i].FullName, actual[i].FullName);
62+
Assert.True(actual.Any((account) => account.Code == expected[i].Code));
63+
Assert.True(actual.Any((account) => account.FullName == expected[i].FullName));
6164
}
6265
}
6366
}

src/ServiceManagement/Services/Commands.Test/ServiceBus/GetAzureSBNamespaceTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using System.Linq;
1718
using Xunit;
1819
using Microsoft.WindowsAzure.Commands.Common;
1920
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
@@ -78,11 +79,13 @@ public void ListNamespacesSuccessfull()
7879
cmdlet.ExecuteCmdlet();
7980

8081
// Assert
81-
List<ExtendedServiceBusNamespace> actual = mockCommandRuntime.OutputPipeline[0] as List<ExtendedServiceBusNamespace>;
82-
Assert.Equal<int>(expected.Count, actual.Count);
82+
IEnumerable<ExtendedServiceBusNamespace> actual = System.Management.Automation.LanguagePrimitives.GetEnumerable(mockCommandRuntime.OutputPipeline).Cast<ExtendedServiceBusNamespace>();
83+
84+
Assert.NotNull(actual);
85+
Assert.Equal<int>(expected.Count, actual.Count());
8386
for (int i = 0; i < expected.Count; i++)
8487
{
85-
Assert.Equal<string>(expected[i].Name, actual[i].Name);
88+
Assert.True(actual.Any((space) => space.Name == expected[i].Name));
8689
}
8790
}
8891

src/ServiceManagement/Services/Commands.Test/Websites/GetAzureWebSiteTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ public void ProcessGetWebsiteTest()
6060
};
6161

6262
getAzureWebsiteCommand.ExecuteWithProcessing();
63-
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
64-
var sites = (IEnumerable<Site>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
63+
64+
var sites = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline).Cast<Site>();
65+
6566
Assert.NotNull(sites);
67+
Assert.NotEmpty(sites);
6668
Assert.True(sites.Any(website => (website).Name.Equals("website1") && (website).WebSpace.Equals("webspace1")));
6769
Assert.True(sites.Any(website => (website).Name.Equals("website2") && (website).WebSpace.Equals("webspace2")));
6870
}
@@ -259,8 +261,12 @@ public void GetsSlots()
259261
};
260262

261263
getAzureWebsiteCommand.ExecuteWithProcessing();
262-
IEnumerable<Site> sites = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as IEnumerable<Site>;
263264

265+
IEnumerable<Site> sites = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline).Cast<Site>();
266+
267+
Assert.NotNull(sites);
268+
Assert.NotEmpty(sites);
269+
Assert.Equal(2, sites.Count());
264270
var website1 = sites.ElementAt(0);
265271
var website2 = sites.ElementAt(1);
266272
Assert.NotNull(website1);

src/ServiceManagement/Services/Commands.Test/Websites/GetAzureWebsiteDeploymentTests.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ public void GetAzureWebsiteDeploymentTest()
8181

8282

8383
getAzureWebsiteDeploymentCommand.ExecuteCmdlet();
84-
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count);
85-
var deployments = (IEnumerable<DeployResult>)((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
84+
85+
var deployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast<DeployResult>();
86+
8687
Assert.NotNull(deployments);
8788
Assert.Equal(2, deployments.Count());
8889
}
@@ -138,8 +139,9 @@ public void GetAzureWebsiteDeploymentLogsTest()
138139
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
139140

140141
getAzureWebsiteDeploymentCommand.ExecuteCmdlet();
141-
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count);
142-
var deployments = (IEnumerable<DeployResult>)((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
142+
143+
var deployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast<DeployResult>();
144+
143145
Assert.NotNull(deployments);
144146
Assert.Equal(2, deployments.Count());
145147
Assert.NotNull(deployments.First(d => d.Id.Equals("commit1")).Logs);
@@ -195,8 +197,8 @@ public void GetsDeploymentForSlot()
195197
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
196198

197199
getAzureWebsiteDeploymentCommand.ExecuteCmdlet();
198-
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count);
199-
var deployments = (IEnumerable<DeployResult>)((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
200+
201+
var deployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast<DeployResult>();
200202
Assert.NotNull(deployments);
201203
Assert.Equal(2, deployments.Count());
202204
}

src/ServiceManagement/Services/Commands.Test/Websites/RestoreAzureWebsiteDeploymentTests.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ public void RestoreAzureWebsiteDeploymentTest()
9191
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
9292

9393
restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet();
94-
Assert.Equal(1, ((MockCommandRuntime) restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count);
95-
var responseDeployments = (IEnumerable<DeployResult>)((MockCommandRuntime) restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
94+
95+
var responseDeployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime) restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast<DeployResult>();
96+
9697
Assert.NotNull(responseDeployments);
9798
Assert.Equal(2, responseDeployments.Count());
9899
Assert.True(responseDeployments.Any(d => d.Id.Equals("id2") && d.Complete));
@@ -113,8 +114,8 @@ public void RestoreAzureWebsiteDeploymentTest()
113114
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
114115

115116
restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet();
116-
Assert.Equal(1, ((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count);
117-
responseDeployments = (IEnumerable<DeployResult>)((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
117+
118+
responseDeployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast<DeployResult>();
118119
Assert.NotNull(responseDeployments);
119120
Assert.Equal(2, responseDeployments.Count());
120121
Assert.True(responseDeployments.Any(d => d.Id.Equals("id1") && d.Complete));
@@ -183,8 +184,9 @@ public void RestoresDeploymentForSlot()
183184

184185

185186
restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet();
186-
Assert.Equal(1, ((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count);
187-
var responseDeployments = (IEnumerable<DeployResult>)((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
187+
188+
var responseDeployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast<DeployResult>();
189+
188190
Assert.NotNull(responseDeployments);
189191
Assert.Equal(2, responseDeployments.Count());
190192
Assert.True(responseDeployments.Any(d => d.Id.Equals("id2") && d.Complete));
@@ -206,8 +208,9 @@ public void RestoresDeploymentForSlot()
206208
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
207209

208210
restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet();
209-
Assert.Equal(1, ((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count);
210-
responseDeployments = (IEnumerable<DeployResult>)((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
211+
212+
responseDeployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast<DeployResult>();
213+
211214
Assert.NotNull(responseDeployments);
212215
Assert.Equal(2, responseDeployments.Count());
213216
Assert.True(responseDeployments.Any(d => d.Id.Equals("id1") && d.Complete));

src/ServiceManagement/Services/Commands.Test/Websites/WebHostingPlans/GetAzureWebHostingPlanTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ public void ListWebHostingPlansTest()
5959
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
6060

6161
command.ExecuteCmdlet();
62-
Assert.Equal(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count);
63-
var plans = (IEnumerable<WebHostingPlan>)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();
62+
63+
var plans = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)command.CommandRuntime).OutputPipeline).Cast<WebHostingPlan>();
64+
6465
Assert.NotNull(plans);
66+
Assert.Equal(2, plans.Count());
6567
Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1")));
6668
Assert.True(plans.Any(p => (p).Name.Equals("Plan2") && (p).WebSpace.Equals("webspace2")));
6769
}
@@ -90,9 +92,11 @@ public void GetAzureWebHostingPlanBasicTest()
9092
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
9193

9294
command.ExecuteCmdlet();
93-
Assert.Equal(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count);
94-
var plans = (IEnumerable<WebHostingPlan>)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();
95+
96+
var plans = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)command.CommandRuntime).OutputPipeline).Cast<WebHostingPlan>();
97+
9598
Assert.NotNull(plans);
99+
Assert.NotEmpty(plans);
96100
Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1")));
97101
}
98102
}

0 commit comments

Comments
 (0)