|
| 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 | +} |
0 commit comments