Skip to content

Commit 4b49871

Browse files
Bpoeshahabhijeet
authored andcommitted
Setting TimeZone when creating weekly and monthly schedules (#4165)
* Setting TimeZone when creating weekly and monthly schedules * Changing NewAzureAutomationScheduleTest to be xUnit tests
1 parent 75b53e9 commit 4b49871

File tree

2 files changed

+145
-12
lines changed

2 files changed

+145
-12
lines changed

src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationScheduleTest.cs

Lines changed: 142 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
using Microsoft.Azure.Commands.Automation.Cmdlet;
1616
using Microsoft.Azure.Commands.Automation.Common;
1717
using Microsoft.Azure.Commands.Automation.Model;
18-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1918
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2020
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2121
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2222
using Moq;
2323
using System;
2424
using System.Linq;
25+
using Xunit;
26+
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
27+
2528
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
2629
{
27-
[TestClass]
2830
public class NewAzureAutomationScheduleTest : RMTestBase
2931
{
3032
private Mock<IAutomationClient> mockAutomationClient;
@@ -33,8 +35,7 @@ public class NewAzureAutomationScheduleTest : RMTestBase
3335

3436
private NewAzureAutomationSchedule cmdlet;
3537

36-
[TestInitialize]
37-
public void SetupTest()
38+
public NewAzureAutomationScheduleTest()
3839
{
3940
this.mockAutomationClient = new Mock<IAutomationClient>();
4041
this.mockCommandRuntime = new MockCommandRuntime();
@@ -45,7 +46,8 @@ public void SetupTest()
4546
};
4647
}
4748

48-
[TestMethod]
49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
4951
public void NewAzureAutomationScheduleByOneTimeSuccessfull()
5052
{
5153
// Setup
@@ -68,7 +70,8 @@ public void NewAzureAutomationScheduleByOneTimeSuccessfull()
6870
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
6971
}
7072

71-
[TestMethod]
73+
[Fact]
74+
[Trait(Category.AcceptanceType, Category.CheckIn)]
7275
public void NewAzureAutomationScheduleByDailySuccessfull()
7376
{
7477
// Setup
@@ -92,7 +95,8 @@ public void NewAzureAutomationScheduleByDailySuccessfull()
9295
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
9396
}
9497

95-
[TestMethod]
98+
[Fact]
99+
[Trait(Category.AcceptanceType, Category.CheckIn)]
96100
public void NewAzureAutomationScheduleByHourlySuccessfull()
97101
{
98102
// Setup
@@ -116,7 +120,8 @@ public void NewAzureAutomationScheduleByHourlySuccessfull()
116120
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
117121
}
118122

119-
[TestMethod]
123+
[Fact]
124+
[Trait(Category.AcceptanceType, Category.CheckIn)]
120125
public void NewAzureAutomationScheduleByDailyWithDefaultExpiryTimeDayIntervalSuccessfull()
121126
{
122127
// Setup
@@ -166,7 +171,8 @@ public void NewAzureAutomationScheduleByDailyWithDefaultExpiryTimeDayIntervalSuc
166171
schedule.Frequency);
167172
}
168173

169-
[TestMethod]
174+
[Fact]
175+
[Trait(Category.AcceptanceType, Category.CheckIn)]
170176
public void NewAzureAutomationScheduleByHourlyWithDefaultExpiryTimeDayIntervalSuccessfull()
171177
{
172178
// Setup
@@ -216,7 +222,8 @@ public void NewAzureAutomationScheduleByHourlyWithDefaultExpiryTimeDayIntervalSu
216222
schedule.Frequency);
217223
}
218224

219-
[TestMethod]
225+
[Fact]
226+
[Trait(Category.AcceptanceType, Category.CheckIn)]
220227
public void NewAzureAutomationScheduleByDailyWithExpiryTimeSuccessfull()
221228
{
222229
// Setup
@@ -268,7 +275,8 @@ public void NewAzureAutomationScheduleByDailyWithExpiryTimeSuccessfull()
268275
schedule.Frequency);
269276
}
270277

271-
[TestMethod]
278+
[Fact]
279+
[Trait(Category.AcceptanceType, Category.CheckIn)]
272280
public void NewAzureAutomationScheduleByHourlyWithExpiryTimeSuccessfull()
273281
{
274282
// Setup
@@ -320,5 +328,128 @@ public void NewAzureAutomationScheduleByHourlyWithExpiryTimeSuccessfull()
320328
"Hour Frequency is unexpectedly {0}",
321329
schedule.Frequency);
322330
}
331+
332+
[Fact]
333+
[Trait(Category.AcceptanceType, Category.CheckIn)]
334+
public void WeeklyWithTimeZoneSetsTheTimeZoneProperty()
335+
{
336+
// Setup
337+
string resourceGroupName = "resourceGroup";
338+
string accountName = "automation";
339+
string scheduleName = "schedule";
340+
byte weekInterval = 2;
341+
var startTime = DateTimeOffset.Now;
342+
var expiryTime = startTime.AddDays(10);
343+
var timeZone = "America/Los_Angeles";
344+
345+
this.mockAutomationClient
346+
.Setup(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()))
347+
.Returns((string a, string b, Schedule s) => s);
348+
349+
this.cmdlet.ResourceGroupName = resourceGroupName;
350+
this.cmdlet.AutomationAccountName = accountName;
351+
this.cmdlet.Name = scheduleName;
352+
this.cmdlet.StartTime = startTime;
353+
this.cmdlet.ExpiryTime = expiryTime;
354+
this.cmdlet.WeekInterval = weekInterval;
355+
this.cmdlet.TimeZone = timeZone;
356+
this.cmdlet.SetParameterSet(AutomationCmdletParameterSets.ByWeekly);
357+
this.cmdlet.ExecuteCmdlet();
358+
359+
// Assert
360+
this.mockAutomationClient
361+
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
362+
363+
Assert.AreEqual(1, ((MockCommandRuntime)this.cmdlet.CommandRuntime).OutputPipeline.Count);
364+
var schedule = (Schedule)((MockCommandRuntime)this.cmdlet.CommandRuntime)
365+
.OutputPipeline
366+
.FirstOrDefault();
367+
Assert.IsNotNull(schedule);
368+
369+
// Test for correct time zone value
370+
Assert.AreEqual(timeZone, schedule.TimeZone);
371+
}
372+
373+
[Fact]
374+
[Trait(Category.AcceptanceType, Category.CheckIn)]
375+
public void MonthlyDaysOfMonthWithTimeZoneSetsTheTimeZoneProperty()
376+
{
377+
// Setup
378+
string resourceGroupName = "resourceGroup";
379+
string accountName = "automation";
380+
string scheduleName = "schedule";
381+
byte monthInterval = 1;
382+
var startTime = DateTimeOffset.Now;
383+
var expiryTime = startTime.AddDays(10);
384+
var timeZone = "America/Los_Angeles";
385+
386+
this.mockAutomationClient
387+
.Setup(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()))
388+
.Returns((string a, string b, Schedule s) => s);
389+
390+
this.cmdlet.ResourceGroupName = resourceGroupName;
391+
this.cmdlet.AutomationAccountName = accountName;
392+
this.cmdlet.Name = scheduleName;
393+
this.cmdlet.StartTime = startTime;
394+
this.cmdlet.ExpiryTime = expiryTime;
395+
this.cmdlet.MonthInterval = monthInterval;
396+
this.cmdlet.TimeZone = timeZone;
397+
this.cmdlet.SetParameterSet(AutomationCmdletParameterSets.ByMonthlyDaysOfMonth);
398+
this.cmdlet.ExecuteCmdlet();
399+
400+
// Assert
401+
this.mockAutomationClient
402+
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
403+
404+
Assert.AreEqual(1, ((MockCommandRuntime)this.cmdlet.CommandRuntime).OutputPipeline.Count);
405+
var schedule = (Schedule)((MockCommandRuntime)this.cmdlet.CommandRuntime)
406+
.OutputPipeline
407+
.FirstOrDefault();
408+
Assert.IsNotNull(schedule);
409+
410+
// Test for correct time zone value
411+
Assert.AreEqual(timeZone, schedule.TimeZone);
412+
}
413+
414+
[Fact]
415+
[Trait(Category.AcceptanceType, Category.CheckIn)]
416+
public void MonthlyDayOfWeekWithTimeZoneSetsTheTimeZoneProperty()
417+
{
418+
// Setup
419+
string resourceGroupName = "resourceGroup";
420+
string accountName = "automation";
421+
string scheduleName = "schedule";
422+
byte monthInterval = 1;
423+
var startTime = DateTimeOffset.Now;
424+
var expiryTime = startTime.AddDays(10);
425+
var timeZone = "America/Los_Angeles";
426+
427+
this.mockAutomationClient
428+
.Setup(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()))
429+
.Returns((string a, string b, Schedule s) => s);
430+
431+
this.cmdlet.ResourceGroupName = resourceGroupName;
432+
this.cmdlet.AutomationAccountName = accountName;
433+
this.cmdlet.Name = scheduleName;
434+
this.cmdlet.StartTime = startTime;
435+
this.cmdlet.ExpiryTime = expiryTime;
436+
this.cmdlet.MonthInterval = monthInterval;
437+
this.cmdlet.TimeZone = timeZone;
438+
this.cmdlet.SetParameterSet(AutomationCmdletParameterSets.ByMonthlyDayOfWeek);
439+
this.cmdlet.ExecuteCmdlet();
440+
441+
// Assert
442+
this.mockAutomationClient
443+
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
444+
445+
Assert.AreEqual(1, ((MockCommandRuntime)this.cmdlet.CommandRuntime).OutputPipeline.Count);
446+
var schedule = (Schedule)((MockCommandRuntime)this.cmdlet.CommandRuntime)
447+
.OutputPipeline
448+
.FirstOrDefault();
449+
Assert.IsNotNull(schedule);
450+
451+
// Test for correct time zone value
452+
Assert.AreEqual(timeZone, schedule.TimeZone);
453+
}
323454
}
324455
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationSchedule.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ private Schedule CreateMonthlyScheduleModel()
202202
StartTime = this.StartTime,
203203
Description = this.Description,
204204
ExpiryTime = this.ExpiryTime,
205+
TimeZone = this.TimeZone,
205206
Frequency = ScheduleFrequency.Month,
206207
Interval = this.MonthInterval,
207208
MonthlyScheduleOptions = this.IsMonthlyScheduleNull()
@@ -247,6 +248,7 @@ private Schedule CreateWeeklyScheduleModel()
247248
StartTime = this.StartTime,
248249
Description = this.Description,
249250
ExpiryTime = this.ExpiryTime,
251+
TimeZone = this.TimeZone,
250252
Frequency = ScheduleFrequency.Week,
251253
Interval = this.WeekInterval,
252254
WeeklyScheduleOptions = this.DaysOfWeek == null
@@ -278,7 +280,7 @@ public enum DayOfWeekOccurrence
278280
/// </summary>
279281
public enum DaysOfMonth
280282
{
281-
One = 1,
283+
One = 1,
282284
Two = 2,
283285
Three = 3,
284286
Four = 4,

0 commit comments

Comments
 (0)