Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting TimeZone when creating weekly and monthly schedules #4165

Merged
merged 2 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bpoe are you converting msTests to xunit tests? Is this why you need to mix two Asserts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these were previously MSTests. I just converted them so that they could run during CI


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