Skip to content

Commit b1e6c75

Browse files
author
Hovsep Mkrtchyan
committed
Fixing Website tests
1 parent 5ef07b2 commit b1e6c75

File tree

7 files changed

+83
-102
lines changed

7 files changed

+83
-102
lines changed

src/Common/Commands.Common/CmdletExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ public static void InvokeEndProcessing(this PSCmdlet cmdlt)
123123
MethodInfo dynMethod = (typeof(PSCmdlet)).GetMethod("EndProcessing", BindingFlags.NonPublic | BindingFlags.Instance);
124124
dynMethod.Invoke(cmdlt, null);
125125
}
126+
public static void ExecuteWithProcessing(this AzurePSCmdlet cmdlt)
127+
{
128+
cmdlt.InvokeBeginProcessing();
129+
cmdlt.ExecuteCmdlet();
130+
cmdlt.InvokeEndProcessing();
131+
132+
}
126133

127134
#endregion
128135
}

src/ServiceManagement/Services/Commands.Test.Utilities/Websites/WebsitesTestBase.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1919
using Microsoft.WindowsAzure.Commands.Common;
2020
using Microsoft.Azure.Common.Authentication.Models;
21+
using System;
22+
using Microsoft.Azure.Common.Authentication;
2123

2224
namespace Microsoft.WindowsAzure.Commands.Test.Utilities.Websites
2325
{
@@ -31,6 +33,8 @@ public class WebsitesTestBase : TestBase
3133
public virtual void SetupTest()
3234
{
3335
new FileSystemHelper(this).CreateAzureSdkDirectoryAndImportPublishSettings();
36+
37+
currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
3438
}
3539

3640
[TestCleanup]
@@ -52,5 +56,19 @@ public void TestCleanup()
5256
File.Delete(sitesFile);
5357
}
5458
}
59+
60+
protected void SetupProfile(string storageName)
61+
{
62+
63+
currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
64+
var subscription = new AzureSubscription { Id = new Guid(subscriptionId) };
65+
subscription.Properties[AzureSubscription.Property.Default] = "True";
66+
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
67+
if (storageName != null)
68+
{
69+
currentProfile.Context.Subscription.Properties[AzureSubscription.Property.StorageAccount] = storageName;
70+
}
71+
currentProfile.Save();
72+
}
5573
}
5674
}

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

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

15-
using System.Collections.Generic;
16-
using System.Management.Automation;
17-
using Microsoft.WindowsAzure.Commands.Common;
15+
using Microsoft.Azure.Common.Authentication;
1816
using Microsoft.Azure.Common.Authentication.Models;
1917
using Microsoft.WindowsAzure.Commands.Test.Utilities.Websites;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2019
using Microsoft.WindowsAzure.Commands.Utilities.Websites;
2120
using Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.DeploymentEntities;
2221
using Microsoft.WindowsAzure.Commands.Websites;
2322
using Moq;
24-
using Xunit;
25-
using Microsoft.Azure.Common.Authentication;
2623
using System;
24+
using System.Collections.Generic;
25+
using System.IO;
26+
using System.Management.Automation;
27+
using Xunit;
2728

2829
namespace Microsoft.WindowsAzure.Commands.Test.Websites
2930
{
@@ -56,6 +57,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplication()
5657
WebsiteDiagnosticOutput.FileSystem,
5758
properties, null));
5859

60+
SetupProfile(null);
61+
5962
enableAzureWebsiteApplicationDiagnosticCommand = new EnableAzureWebsiteApplicationDiagnosticCommand()
6063
{
6164
CommandRuntime = commandRuntimeMock.Object,
@@ -65,13 +68,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplication()
6568
LogLevel = LogEntryType.Information
6669
};
6770

68-
currentProfile = new AzureProfile();
69-
var subscription = new AzureSubscription { Id = new Guid(base.subscriptionId) };
70-
subscription.Properties[AzureSubscription.Property.Default] = "True";
71-
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
72-
7371
// Test
74-
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet();
72+
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteWithProcessing();
7573

7674
// Assert
7775
websitesClientMock.Verify(f => f.EnableApplicationDiagnostic(
@@ -95,6 +93,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplicationTableLog()
9593
WebsiteDiagnosticOutput.StorageTable,
9694
properties, null));
9795

96+
SetupProfile(null);
97+
9898
enableAzureWebsiteApplicationDiagnosticCommand = new EnableAzureWebsiteApplicationDiagnosticCommand()
9999
{
100100
CommandRuntime = commandRuntimeMock.Object,
@@ -106,13 +106,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplicationTableLog()
106106
StorageTableName = tableName
107107
};
108108

109-
currentProfile = new AzureProfile();
110-
var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) };
111-
subscription.Properties[AzureSubscription.Property.Default] = "True";
112-
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
113-
114109
// Test
115-
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet();
110+
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteWithProcessing();
116111

117112
// Assert
118113
websitesClientMock.Verify(f => f.EnableApplicationDiagnostic(
@@ -136,6 +131,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplicationTableLogUseCurrent
136131
WebsiteDiagnosticOutput.StorageTable,
137132
properties, null));
138133

134+
SetupProfile(storageName);
135+
139136
enableAzureWebsiteApplicationDiagnosticCommand = new EnableAzureWebsiteApplicationDiagnosticCommand()
140137
{
141138
CommandRuntime = commandRuntimeMock.Object,
@@ -146,14 +143,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplicationTableLogUseCurrent
146143
StorageTableName = tableName
147144
};
148145

149-
currentProfile = new AzureProfile();
150-
var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) };
151-
subscription.Properties[AzureSubscription.Property.Default] = "True";
152-
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
153-
currentProfile.Context.Subscription.Properties[AzureSubscription.Property.StorageAccount] = storageName;
154-
155146
// Test
156-
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet();
147+
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteWithProcessing();
157148

158149
// Assert
159150
websitesClientMock.Verify(f => f.EnableApplicationDiagnostic(
@@ -177,6 +168,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplicationBlobLog()
177168
WebsiteDiagnosticOutput.StorageBlob,
178169
properties, null));
179170

171+
SetupProfile(null);
172+
180173
enableAzureWebsiteApplicationDiagnosticCommand = new EnableAzureWebsiteApplicationDiagnosticCommand()
181174
{
182175
CommandRuntime = commandRuntimeMock.Object,
@@ -188,13 +181,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplicationBlobLog()
188181
StorageBlobContainerName = blobContainerName
189182
};
190183

191-
currentProfile = new AzureProfile();
192-
var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) };
193-
subscription.Properties[AzureSubscription.Property.Default] = "True";
194-
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
195-
196184
// Test
197-
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet();
185+
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteWithProcessing();
198186

199187
// Assert
200188
websitesClientMock.Verify(f => f.EnableApplicationDiagnostic(
@@ -218,6 +206,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplicationBlobLogUseCurrentS
218206
WebsiteDiagnosticOutput.StorageBlob,
219207
properties, null));
220208

209+
SetupProfile(storageName);
210+
221211
enableAzureWebsiteApplicationDiagnosticCommand = new EnableAzureWebsiteApplicationDiagnosticCommand()
222212
{
223213
CommandRuntime = commandRuntimeMock.Object,
@@ -228,14 +218,8 @@ public void EnableAzureWebsiteApplicationDiagnosticApplicationBlobLogUseCurrentS
228218
StorageBlobContainerName = blobContainerName
229219
};
230220

231-
currentProfile = new AzureProfile();
232-
var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) };
233-
subscription.Properties[AzureSubscription.Property.Default] = "True";
234-
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
235-
currentProfile.Context.Subscription.Properties[AzureSubscription.Property.StorageAccount] = storageName;
236-
237221
// Test
238-
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet();
222+
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteWithProcessing();
239223

240224
// Assert
241225
websitesClientMock.Verify(f => f.EnableApplicationDiagnostic(
@@ -256,6 +240,8 @@ public void EnableApplicationDiagnosticOnSlot()
256240
WebsiteDiagnosticOutput.FileSystem,
257241
properties,
258242
slot));
243+
244+
SetupProfile(null);
259245

260246
enableAzureWebsiteApplicationDiagnosticCommand = new EnableAzureWebsiteApplicationDiagnosticCommand()
261247
{
@@ -267,13 +253,8 @@ public void EnableApplicationDiagnosticOnSlot()
267253
Slot = slot
268254
};
269255

270-
currentProfile = new AzureProfile();
271-
var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) };
272-
subscription.Properties[AzureSubscription.Property.Default] = "True";
273-
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
274-
275256
// Test
276-
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet();
257+
enableAzureWebsiteApplicationDiagnosticCommand.ExecuteWithProcessing();
277258

278259
// Assert
279260
websitesClientMock.Verify(f => f.EnableApplicationDiagnostic(

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

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

15-
using System;
16-
using System.Collections.Generic;
17-
using System.Linq;
18-
using Xunit;
19-
using Microsoft.WindowsAzure.Commands.Common;
2015
using Microsoft.Azure.Common.Authentication.Models;
2116
using Microsoft.WindowsAzure.Commands.Common.Properties;
2217
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2318
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2419
using Microsoft.WindowsAzure.Commands.Test.Utilities.Websites;
20+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2521
using Microsoft.WindowsAzure.Commands.Utilities.Websites;
2622
using Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities;
2723
using Microsoft.WindowsAzure.Commands.Websites;
2824
using Moq;
29-
using Microsoft.Azure.Common.Authentication;
25+
using System;
26+
using System.Collections.Generic;
27+
using System.Linq;
28+
using Xunit;
3029

3130
namespace Microsoft.WindowsAzure.Commands.Test.Websites
3231
{
@@ -50,18 +49,15 @@ public void ProcessGetWebsiteTest()
5049
.Returns(new List<Site> { new Site { Name = "website1", WebSpace = "webspace1" },
5150
new Site { Name = "website2", WebSpace = "webspace2" }});
5251

52+
SetupProfile(null);
5353
// Test
5454
var getAzureWebsiteCommand = new GetAzureWebsiteCommand
5555
{
5656
CommandRuntime = new MockCommandRuntime(),
5757
WebsitesClient = clientMock.Object
5858
};
59-
currentProfile = new AzureProfile();
60-
var subscription = new AzureSubscription { Id = new Guid(base.subscriptionId) };
61-
subscription.Properties[AzureSubscription.Property.Default] = "True";
62-
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
6359

64-
getAzureWebsiteCommand.ExecuteCmdlet();
60+
getAzureWebsiteCommand.ExecuteWithProcessing();
6561
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
6662
var sites = (IEnumerable<Site>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
6763
Assert.NotNull(sites);
@@ -92,6 +88,7 @@ public void GetWebsiteProcessShowTest()
9288
PublishingUsername = "user1"}
9389
);
9490

91+
SetupProfile(null);
9592

9693
// Test
9794
var getAzureWebsiteCommand = new GetAzureWebsiteCommand
@@ -100,12 +97,8 @@ public void GetWebsiteProcessShowTest()
10097
Name = "website1",
10198
WebsitesClient = clientMock.Object
10299
};
103-
currentProfile = new AzureProfile();
104-
var subscription = new AzureSubscription{Id = new Guid(subscriptionId) };
105-
subscription.Properties[AzureSubscription.Property.Default] = "True";
106-
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
107100

108-
getAzureWebsiteCommand.ExecuteCmdlet();
101+
getAzureWebsiteCommand.ExecuteWithProcessing();
109102
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
110103

111104
SiteWithConfig website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
@@ -114,19 +107,17 @@ public void GetWebsiteProcessShowTest()
114107
Assert.Equal("website1", website.Name);
115108
Assert.Equal("webspace1", website.WebSpace);
116109

110+
SetupProfile(null);
111+
117112
// Run with mixed casing
118113
getAzureWebsiteCommand = new GetAzureWebsiteCommand
119114
{
120115
CommandRuntime = new MockCommandRuntime(),
121116
Name = "WEBSiTe1",
122117
WebsitesClient = clientMock.Object
123118
};
124-
currentProfile = new AzureProfile();
125-
subscription = new AzureSubscription{Id = new Guid(subscriptionId) };
126-
subscription.Properties[AzureSubscription.Property.Default] = "True";
127-
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
128119

129-
getAzureWebsiteCommand.ExecuteCmdlet();
120+
getAzureWebsiteCommand.ExecuteWithProcessing();
130121
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
131122

132123
website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
@@ -145,7 +136,7 @@ public void ProcessGetWebsiteWithNullSubscription()
145136
CommandRuntime = new MockCommandRuntime()
146137
};
147138

148-
Testing.AssertThrows<Exception>(getAzureWebsiteCommand.ExecuteCmdlet, Resources.InvalidDefaultSubscription);
139+
Testing.AssertThrows<Exception>(getAzureWebsiteCommand.ExecuteWithProcessing, Resources.InvalidDefaultSubscription);
149140
}
150141

151142
[Fact]
@@ -165,20 +156,18 @@ public void TestGetAzureWebsiteWithDiagnosticsSettings()
165156
websitesClientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny<string>(), slot))
166157
.Returns(new SiteConfig {PublishingUsername = "user1"});
167158

159+
SetupProfile(null);
160+
168161
var getAzureWebsiteCommand = new GetAzureWebsiteCommand
169162
{
170163
CommandRuntime = new MockCommandRuntime(),
171164
Name = "website1",
172165
WebsitesClient = websitesClientMock.Object,
173166
Slot = slot
174167
};
175-
currentProfile = new AzureProfile();
176-
var subscription = new AzureSubscription{Id = new Guid(subscriptionId) };
177-
subscription.Properties[AzureSubscription.Property.Default] = "True";
178-
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
179168

180169
// Test
181-
getAzureWebsiteCommand.ExecuteCmdlet();
170+
getAzureWebsiteCommand.ExecuteWithProcessing();
182171

183172
// Assert
184173
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
@@ -209,6 +198,7 @@ public void GetsWebsiteSlot()
209198
PublishingUsername = "user1"
210199
});
211200

201+
SetupProfile(null);
212202
// Test
213203
var getAzureWebsiteCommand = new GetAzureWebsiteCommand
214204
{
@@ -217,12 +207,8 @@ public void GetsWebsiteSlot()
217207
WebsitesClient = clientMock.Object,
218208
Slot = slot
219209
};
220-
currentProfile = new AzureProfile();
221-
var subscription = new AzureSubscription{Id = new Guid(subscriptionId) };
222-
subscription.Properties[AzureSubscription.Property.Default] = "True";
223-
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
224210

225-
getAzureWebsiteCommand.ExecuteCmdlet();
211+
getAzureWebsiteCommand.ExecuteWithProcessing();
226212
Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
227213

228214
var website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
@@ -255,19 +241,17 @@ public void GetsSlots()
255241
PublishingUsername = "user1"
256242
});
257243

244+
SetupProfile(null);
245+
258246
// Test
259247
var getAzureWebsiteCommand = new GetAzureWebsiteCommand
260248
{
261249
CommandRuntime = new MockCommandRuntime(),
262250
WebsitesClient = clientMock.Object,
263251
Slot = slot
264252
};
265-
currentProfile = new AzureProfile();
266-
var subscription = new AzureSubscription{Id = new Guid(subscriptionId) };
267-
subscription.Properties[AzureSubscription.Property.Default] = "True";
268-
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
269253

270-
getAzureWebsiteCommand.ExecuteCmdlet();
254+
getAzureWebsiteCommand.ExecuteWithProcessing();
271255
IEnumerable<Site> sites = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as IEnumerable<Site>;
272256

273257
var website1 = sites.ElementAt(0);

0 commit comments

Comments
 (0)