Skip to content

Commit

Permalink
Setting TimeZone when creating weekly and monthly schedules (#4165)
Browse files Browse the repository at this point in the history
* Setting TimeZone when creating weekly and monthly schedules

* Changing NewAzureAutomationScheduleTest to be xUnit tests
  • Loading branch information
Bpoe authored and shahabhijeet committed Jun 27, 2017
1 parent 75b53e9 commit 4b49871
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
using Microsoft.Azure.Commands.Automation.Cmdlet;
using Microsoft.Azure.Commands.Automation.Common;
using Microsoft.Azure.Commands.Automation.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Moq;
using System;
using System.Linq;
using Xunit;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;

namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
{
[TestClass]
public class NewAzureAutomationScheduleTest : RMTestBase
{
private Mock<IAutomationClient> mockAutomationClient;
Expand All @@ -33,8 +35,7 @@ public class NewAzureAutomationScheduleTest : RMTestBase

private NewAzureAutomationSchedule cmdlet;

[TestInitialize]
public void SetupTest()
public NewAzureAutomationScheduleTest()
{
this.mockAutomationClient = new Mock<IAutomationClient>();
this.mockCommandRuntime = new MockCommandRuntime();
Expand All @@ -45,7 +46,8 @@ public void SetupTest()
};
}

[TestMethod]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewAzureAutomationScheduleByOneTimeSuccessfull()
{
// Setup
Expand All @@ -68,7 +70,8 @@ public void NewAzureAutomationScheduleByOneTimeSuccessfull()
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
}

[TestMethod]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewAzureAutomationScheduleByDailySuccessfull()
{
// Setup
Expand All @@ -92,7 +95,8 @@ public void NewAzureAutomationScheduleByDailySuccessfull()
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
}

[TestMethod]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewAzureAutomationScheduleByHourlySuccessfull()
{
// Setup
Expand All @@ -116,7 +120,8 @@ public void NewAzureAutomationScheduleByHourlySuccessfull()
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());
}

[TestMethod]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewAzureAutomationScheduleByDailyWithDefaultExpiryTimeDayIntervalSuccessfull()
{
// Setup
Expand Down Expand Up @@ -166,7 +171,8 @@ public void NewAzureAutomationScheduleByDailyWithDefaultExpiryTimeDayIntervalSuc
schedule.Frequency);
}

[TestMethod]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewAzureAutomationScheduleByHourlyWithDefaultExpiryTimeDayIntervalSuccessfull()
{
// Setup
Expand Down Expand Up @@ -216,7 +222,8 @@ public void NewAzureAutomationScheduleByHourlyWithDefaultExpiryTimeDayIntervalSu
schedule.Frequency);
}

[TestMethod]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewAzureAutomationScheduleByDailyWithExpiryTimeSuccessfull()
{
// Setup
Expand Down Expand Up @@ -268,7 +275,8 @@ public void NewAzureAutomationScheduleByDailyWithExpiryTimeSuccessfull()
schedule.Frequency);
}

[TestMethod]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewAzureAutomationScheduleByHourlyWithExpiryTimeSuccessfull()
{
// Setup
Expand Down Expand Up @@ -320,5 +328,128 @@ public void NewAzureAutomationScheduleByHourlyWithExpiryTimeSuccessfull()
"Hour Frequency is unexpectedly {0}",
schedule.Frequency);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void WeeklyWithTimeZoneSetsTheTimeZoneProperty()
{
// Setup
string resourceGroupName = "resourceGroup";
string accountName = "automation";
string scheduleName = "schedule";
byte weekInterval = 2;
var startTime = DateTimeOffset.Now;
var expiryTime = startTime.AddDays(10);
var timeZone = "America/Los_Angeles";

this.mockAutomationClient
.Setup(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()))
.Returns((string a, string b, Schedule s) => s);

this.cmdlet.ResourceGroupName = resourceGroupName;
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.Name = scheduleName;
this.cmdlet.StartTime = startTime;
this.cmdlet.ExpiryTime = expiryTime;
this.cmdlet.WeekInterval = weekInterval;
this.cmdlet.TimeZone = timeZone;
this.cmdlet.SetParameterSet(AutomationCmdletParameterSets.ByWeekly);
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());

Assert.AreEqual(1, ((MockCommandRuntime)this.cmdlet.CommandRuntime).OutputPipeline.Count);
var schedule = (Schedule)((MockCommandRuntime)this.cmdlet.CommandRuntime)
.OutputPipeline
.FirstOrDefault();
Assert.IsNotNull(schedule);

// Test for correct time zone value
Assert.AreEqual(timeZone, schedule.TimeZone);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void MonthlyDaysOfMonthWithTimeZoneSetsTheTimeZoneProperty()
{
// Setup
string resourceGroupName = "resourceGroup";
string accountName = "automation";
string scheduleName = "schedule";
byte monthInterval = 1;
var startTime = DateTimeOffset.Now;
var expiryTime = startTime.AddDays(10);
var timeZone = "America/Los_Angeles";

this.mockAutomationClient
.Setup(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()))
.Returns((string a, string b, Schedule s) => s);

this.cmdlet.ResourceGroupName = resourceGroupName;
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.Name = scheduleName;
this.cmdlet.StartTime = startTime;
this.cmdlet.ExpiryTime = expiryTime;
this.cmdlet.MonthInterval = monthInterval;
this.cmdlet.TimeZone = timeZone;
this.cmdlet.SetParameterSet(AutomationCmdletParameterSets.ByMonthlyDaysOfMonth);
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());

Assert.AreEqual(1, ((MockCommandRuntime)this.cmdlet.CommandRuntime).OutputPipeline.Count);
var schedule = (Schedule)((MockCommandRuntime)this.cmdlet.CommandRuntime)
.OutputPipeline
.FirstOrDefault();
Assert.IsNotNull(schedule);

// Test for correct time zone value
Assert.AreEqual(timeZone, schedule.TimeZone);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void MonthlyDayOfWeekWithTimeZoneSetsTheTimeZoneProperty()
{
// Setup
string resourceGroupName = "resourceGroup";
string accountName = "automation";
string scheduleName = "schedule";
byte monthInterval = 1;
var startTime = DateTimeOffset.Now;
var expiryTime = startTime.AddDays(10);
var timeZone = "America/Los_Angeles";

this.mockAutomationClient
.Setup(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()))
.Returns((string a, string b, Schedule s) => s);

this.cmdlet.ResourceGroupName = resourceGroupName;
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.Name = scheduleName;
this.cmdlet.StartTime = startTime;
this.cmdlet.ExpiryTime = expiryTime;
this.cmdlet.MonthInterval = monthInterval;
this.cmdlet.TimeZone = timeZone;
this.cmdlet.SetParameterSet(AutomationCmdletParameterSets.ByMonthlyDayOfWeek);
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient
.Verify(f => f.CreateSchedule(resourceGroupName, accountName, It.IsAny<Schedule>()), Times.Once());

Assert.AreEqual(1, ((MockCommandRuntime)this.cmdlet.CommandRuntime).OutputPipeline.Count);
var schedule = (Schedule)((MockCommandRuntime)this.cmdlet.CommandRuntime)
.OutputPipeline
.FirstOrDefault();
Assert.IsNotNull(schedule);

// Test for correct time zone value
Assert.AreEqual(timeZone, schedule.TimeZone);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ private Schedule CreateMonthlyScheduleModel()
StartTime = this.StartTime,
Description = this.Description,
ExpiryTime = this.ExpiryTime,
TimeZone = this.TimeZone,
Frequency = ScheduleFrequency.Month,
Interval = this.MonthInterval,
MonthlyScheduleOptions = this.IsMonthlyScheduleNull()
Expand Down Expand Up @@ -247,6 +248,7 @@ private Schedule CreateWeeklyScheduleModel()
StartTime = this.StartTime,
Description = this.Description,
ExpiryTime = this.ExpiryTime,
TimeZone = this.TimeZone,
Frequency = ScheduleFrequency.Week,
Interval = this.WeekInterval,
WeeklyScheduleOptions = this.DaysOfWeek == null
Expand Down Expand Up @@ -278,7 +280,7 @@ public enum DayOfWeekOccurrence
/// </summary>
public enum DaysOfMonth
{
One = 1,
One = 1,
Two = 2,
Three = 3,
Four = 4,
Expand Down

0 comments on commit 4b49871

Please sign in to comment.