Skip to content

Commit 300ec4c

Browse files
author
Maddie Clayton
authored
Merge pull request Azure#8591 from Bpoe/master
Fixing bug in Azure Automation cmdlets when retrieving Monthly Day of Week schedules
2 parents 3152c13 + f290580 commit 300ec4c

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests.Models
16+
{
17+
using System;
18+
using System.Collections.Generic;
19+
using Microsoft.Azure.Commands.Automation.Cmdlet;
20+
using Microsoft.Azure.Management.Automation.Models;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Xunit;
23+
24+
public class ScheduleTest
25+
{
26+
[Fact]
27+
[Trait(Category.AcceptanceType, Category.CheckIn)]
28+
[Trait(Category.Service, Category.Automation)]
29+
public void ScheduleConstructorHandlesMonthlyDayOfWeekSchedule()
30+
{
31+
const string expectedDayOfWeek = "Saturday";
32+
const int occurrence = 1;
33+
34+
var sdkSchedule = new Schedule()
35+
{
36+
Frequency = "Month",
37+
AdvancedSchedule = new AdvancedSchedule()
38+
{
39+
WeekDays = null,
40+
MonthDays = null,
41+
MonthlyOccurrences = new List<AdvancedScheduleMonthlyOccurrence>()
42+
{
43+
new AdvancedScheduleMonthlyOccurrence()
44+
{
45+
Day = expectedDayOfWeek,
46+
Occurrence = occurrence,
47+
},
48+
},
49+
},
50+
};
51+
52+
var schedule = new Model.Schedule("anyRg", "anyAccount", sdkSchedule);
53+
54+
Assert.NotNull(schedule.MonthlyScheduleOptions);
55+
Assert.Null(schedule.WeeklyScheduleOptions);
56+
57+
Assert.Null(schedule.MonthlyScheduleOptions.DaysOfMonth);
58+
Assert.NotNull(schedule.MonthlyScheduleOptions.DayOfWeek);
59+
60+
Assert.Equal(expectedDayOfWeek, schedule.MonthlyScheduleOptions.DayOfWeek.Day);
61+
Assert.Equal(Enum.GetName(typeof(DayOfWeekOccurrence), occurrence), schedule.MonthlyScheduleOptions.DayOfWeek.Occurrence);
62+
}
63+
64+
[Fact]
65+
[Trait(Category.AcceptanceType, Category.CheckIn)]
66+
[Trait(Category.Service, Category.Automation)]
67+
public void ScheduleConstructorHandlesMonthlyDayOfMonthSchedule()
68+
{
69+
var sdkSchedule = new Schedule()
70+
{
71+
Frequency = "Month",
72+
AdvancedSchedule = new AdvancedSchedule()
73+
{
74+
WeekDays = null,
75+
MonthDays = new List<int>() { 1, 15, },
76+
MonthlyOccurrences = null,
77+
},
78+
};
79+
80+
var schedule = new Model.Schedule("anyRg", "anyAccount", sdkSchedule);
81+
82+
Assert.NotNull(schedule.MonthlyScheduleOptions);
83+
Assert.Null(schedule.WeeklyScheduleOptions);
84+
85+
Assert.NotNull(schedule.MonthlyScheduleOptions.DaysOfMonth);
86+
Assert.Null(schedule.MonthlyScheduleOptions.DayOfWeek);
87+
}
88+
89+
[Fact]
90+
[Trait(Category.AcceptanceType, Category.CheckIn)]
91+
[Trait(Category.Service, Category.Automation)]
92+
public void ScheduleConstructorHandlesWeeklySchedule()
93+
{
94+
var sdkSchedule = new Schedule()
95+
{
96+
Frequency = "Week",
97+
AdvancedSchedule = new AdvancedSchedule()
98+
{
99+
WeekDays = new List<string>() { "Monday" },
100+
MonthDays = null,
101+
MonthlyOccurrences = null,
102+
},
103+
};
104+
105+
var schedule = new Model.Schedule("anyRg", "anyAccount", sdkSchedule);
106+
107+
Assert.Null(schedule.MonthlyScheduleOptions);
108+
Assert.NotNull(schedule.WeeklyScheduleOptions);
109+
110+
Assert.NotNull(schedule.WeeklyScheduleOptions.DaysOfWeek);
111+
}
112+
}
113+
}

src/Automation/Automation/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed issue when retreiving certain monthly schedules in several Azure Automation cmdlets
2122

2223
## Version 1.1.1
2324
* Update help for Import-AzAutomationDscNodeConfiguration

src/Automation/Automation/Model/Schedule.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ private WeeklyScheduleOptions CreateWeeklyScheduleOptions(Microsoft.Azure.Manage
233233
private static WeeklyScheduleOptions CreateWeeklyScheduleOptions(Microsoft.Azure.Management.Automation.Models.AdvancedSchedule advSchedule)
234234
{
235235
return advSchedule == null
236+
|| advSchedule.WeekDays == null
236237
? null
237238
: new WeeklyScheduleOptions()
238239
{
@@ -301,7 +302,12 @@ private static string GetDayOfWeekOccurrence(int? dayOfWeekOccurrence)
301302
/// </returns>
302303
private static IList<DaysOfMonth> GetDaysOfMonth(IList<int> daysOfMonth)
303304
{
304-
return daysOfMonth.Select(value => (DaysOfMonth)value).ToList();
305+
if (daysOfMonth != null)
306+
{
307+
return daysOfMonth.Select(value => (DaysOfMonth)value).ToList();
308+
}
309+
310+
return null;
305311
}
306312

307313
private static DateTimeOffset? AdjustOffset(DateTimeOffset? dateTimeOffset, double offsetMinutes)

0 commit comments

Comments
 (0)