Skip to content

Commit 183beb1

Browse files
committed
Merge pull request #4 from kiranisaac/master
Merge kirab(master) with elvg(dev) - Jobs, Variables, Modules
2 parents 49d22b8 + 581a82a commit 183beb1

18 files changed

+693
-205
lines changed

src/ServiceManagement/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,22 @@
102102
<Compile Include="UnitTests\SetAzureAutomationRunbookDefinitionTest.cs" />
103103
<Compile Include="UnitTests\SetAzureAutomationRunbookTest.cs" />
104104
<Compile Include="UnitTests\GetAzureAutomationCredentialTest.cs" />
105+
<Compile Include="UnitTests\GetAzureAutomationJobTest.cs" />
105106
<Compile Include="UnitTests\GetAzureAutomationModuleTest.cs" />
106107
<Compile Include="UnitTests\GetAzureAutomationScheduleTest.cs" />
107108
<Compile Include="UnitTests\NewAzureAutomationCredentialTest.cs" />
108109
<Compile Include="UnitTests\NewAzureAutomationModuleTest.cs" />
109110
<Compile Include="UnitTests\NewAzureAutomationScheduleTest.cs" />
110111
<Compile Include="UnitTests\NewAzureAutomationVariableTest.cs" />
111-
<Compile Include="UnitTests\RemoveAzureAutomationCredentialTest.cs" />
112112
<Compile Include="UnitTests\RemoveAzureAutomationModuleTest.cs" />
113113
<Compile Include="UnitTests\RemoveAzureAutomationScheduleTest.cs" />
114114
<Compile Include="UnitTests\RemoveAzureAutomationVariableTest.cs" />
115+
<Compile Include="UnitTests\GetAzureAutomationVariableTest.cs" />
116+
<Compile Include="UnitTests\ResumeAzureAutomationJobTest.cs" />
115117
<Compile Include="UnitTests\SetAzureAutomationCredentialTest.cs" />
116118
<Compile Include="UnitTests\SetAzureAutomationScheduleTest.cs" />
117-
<Compile Include="UnitTests\GetAzureAutomationVariableTest.cs" />
119+
<Compile Include="UnitTests\StopAzureAutomationJobTest.cs" />
120+
<Compile Include="UnitTests\SuspendAzureAutomationJobTest.cs" />
118121
<Compile Include="UnitTests\StartAzureAutomationRunbookTest.cs" />
119122
</ItemGroup>
120123
<ItemGroup>
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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+
using System;
16+
using System.Collections.Generic;
17+
using Microsoft.Azure.Commands.Automation.Cmdlet;
18+
using Microsoft.Azure.Commands.Automation.Common;
19+
using Microsoft.Azure.Commands.Automation.Model;
20+
using Microsoft.VisualStudio.TestTools.UnitTesting;
21+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
22+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23+
using Moq;
24+
25+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
26+
{
27+
[TestClass]
28+
public class GetAzureAutomationJobTest : TestBase
29+
{
30+
private Mock<IAutomationClient> mockAutomationClient;
31+
32+
private MockCommandRuntime mockCommandRuntime;
33+
34+
private GetAzureAutomationJob cmdlet;
35+
36+
[TestInitialize]
37+
public void SetupTest()
38+
{
39+
this.mockAutomationClient = new Mock<IAutomationClient>();
40+
this.mockCommandRuntime = new MockCommandRuntime();
41+
this.cmdlet = new GetAzureAutomationJob
42+
{
43+
AutomationClient = this.mockAutomationClient.Object,
44+
CommandRuntime = this.mockCommandRuntime
45+
};
46+
}
47+
48+
[TestMethod]
49+
public void GetAzureAutomationJobByRunbookNameSuccessfull()
50+
{
51+
// Setup
52+
string accountName = "automation";
53+
string runbookName = "runbook";
54+
55+
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null));
56+
57+
// Test
58+
this.cmdlet.AutomationAccountName = accountName;
59+
this.cmdlet.RunbookName = runbookName;
60+
this.cmdlet.ExecuteCmdlet();
61+
62+
// Assert
63+
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null), Times.Once());
64+
}
65+
66+
public void GetAzureAutomationJobByRunbookNamAndStartTimeEndTimeeSuccessfull()
67+
{
68+
// Setup
69+
string accountName = "automation";
70+
string runbookName = "runbook";
71+
DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0);
72+
DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0);
73+
74+
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null));
75+
76+
// Test
77+
this.cmdlet.AutomationAccountName = accountName;
78+
this.cmdlet.RunbookName = runbookName;
79+
this.cmdlet.ExecuteCmdlet();
80+
81+
// Assert
82+
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null), Times.Once());
83+
}
84+
85+
public void GetAzureAutomationCompletedJobByRunbookNamAndStartTimeEndTimeeSuccessfull()
86+
{
87+
// Setup
88+
string accountName = "automation";
89+
string runbookName = "runbook";
90+
DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0);
91+
DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0);
92+
string status = "Completed";
93+
94+
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status));
95+
96+
// Test
97+
this.cmdlet.AutomationAccountName = accountName;
98+
this.cmdlet.RunbookName = runbookName;
99+
this.cmdlet.Status = status;
100+
this.cmdlet.ExecuteCmdlet();
101+
102+
// Assert
103+
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status), Times.Once());
104+
}
105+
106+
[TestMethod]
107+
public void GetAzureAutomationAllJobsSuccessfull()
108+
{
109+
// Setup
110+
string accountName = "automation";
111+
112+
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, null, null, null));
113+
114+
// Test
115+
this.cmdlet.AutomationAccountName = accountName;
116+
this.cmdlet.ExecuteCmdlet();
117+
118+
// Assert
119+
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, null, null, null), Times.Once());
120+
}
121+
122+
[TestMethod]
123+
public void GetAzureAutomationAllJobsBetweenStartAndEndTimeSuccessfull()
124+
{
125+
// Setup
126+
string accountName = "automation";
127+
DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0);
128+
DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0);
129+
130+
// look for jobs between 5pm to 6pm on 30th december 2014
131+
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, null));
132+
133+
// Test
134+
this.cmdlet.AutomationAccountName = accountName;
135+
this.cmdlet.StartTime = startTime;
136+
this.cmdlet.EndTime = endTime;
137+
this.cmdlet.ExecuteCmdlet();
138+
139+
// Assert
140+
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, null), Times.Once());
141+
}
142+
143+
[TestMethod]
144+
public void GetAzureAutomationAllCompletedJobsBetweenStartAndEndTimeSuccessfull()
145+
{
146+
// Setup
147+
string accountName = "automation";
148+
DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0);
149+
DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0);
150+
string status = "Completed";
151+
152+
// look for jobs between 5pm to 6pm on 30th december 2014
153+
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, status));
154+
155+
// Test
156+
this.cmdlet.AutomationAccountName = accountName;
157+
this.cmdlet.StartTime = startTime;
158+
this.cmdlet.EndTime = endTime;
159+
this.cmdlet.Status = status;
160+
this.cmdlet.ExecuteCmdlet();
161+
162+
// Assert
163+
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, status), Times.Once());
164+
}
165+
166+
public void GetAzureAutomationJobByIdSuccessfull()
167+
{
168+
// Setup
169+
string accountName = "automation";
170+
Guid jobId = Guid.NewGuid();
171+
172+
// look for jobs between 5pm to 6pm on 30th december 2014
173+
this.mockAutomationClient.Setup(f => f.GetJob(accountName, jobId));
174+
175+
// Test
176+
this.cmdlet.AutomationAccountName = accountName;
177+
this.cmdlet.Id = jobId;
178+
this.cmdlet.ExecuteCmdlet();
179+
180+
// Assert
181+
this.mockAutomationClient.Verify(f => f.GetJob(accountName, jobId), Times.Once());
182+
}
183+
184+
}
185+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
using System;
16+
using System.Collections.Generic;
17+
using Microsoft.Azure.Commands.Automation.Cmdlet;
18+
using Microsoft.Azure.Commands.Automation.Common;
19+
using Microsoft.Azure.Commands.Automation.Model;
20+
using Microsoft.VisualStudio.TestTools.UnitTesting;
21+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
22+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23+
using Moq;
24+
25+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
26+
{
27+
[TestClass]
28+
public class ResumeAzureAutomationJobTest : TestBase
29+
{
30+
private Mock<IAutomationClient> mockAutomationClient;
31+
32+
private MockCommandRuntime mockCommandRuntime;
33+
34+
private ResumeAzureAutomationJob cmdlet;
35+
36+
[TestInitialize]
37+
public void SetupTest()
38+
{
39+
this.mockAutomationClient = new Mock<IAutomationClient>();
40+
this.mockCommandRuntime = new MockCommandRuntime();
41+
this.cmdlet = new ResumeAzureAutomationJob
42+
{
43+
AutomationClient = this.mockAutomationClient.Object,
44+
CommandRuntime = this.mockCommandRuntime
45+
};
46+
}
47+
48+
[TestMethod]
49+
public void ResumeAzureAutomationJobSuccessfull()
50+
{
51+
// Setup
52+
string accountName = "automation";
53+
Guid jobId = Guid.NewGuid();
54+
55+
this.mockAutomationClient.Setup(f => f.ResumeJob(accountName, jobId));
56+
57+
// Test
58+
this.cmdlet.AutomationAccountName = accountName;
59+
this.cmdlet.Id = jobId;
60+
this.cmdlet.ExecuteCmdlet();
61+
62+
// Assert
63+
this.mockAutomationClient.Verify(f => f.ResumeJob(accountName, jobId), Times.Once());
64+
}
65+
}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
using System;
16+
using System.Collections.Generic;
17+
using Microsoft.Azure.Commands.Automation.Cmdlet;
18+
using Microsoft.Azure.Commands.Automation.Common;
19+
using Microsoft.Azure.Commands.Automation.Model;
20+
using Microsoft.VisualStudio.TestTools.UnitTesting;
21+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
22+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23+
using Moq;
24+
25+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
26+
{
27+
[TestClass]
28+
public class StopAzureAutomationJobTest : TestBase
29+
{
30+
private Mock<IAutomationClient> mockAutomationClient;
31+
32+
private MockCommandRuntime mockCommandRuntime;
33+
34+
private StopAzureAutomationJob cmdlet;
35+
36+
[TestInitialize]
37+
public void SetupTest()
38+
{
39+
this.mockAutomationClient = new Mock<IAutomationClient>();
40+
this.mockCommandRuntime = new MockCommandRuntime();
41+
this.cmdlet = new StopAzureAutomationJob
42+
{
43+
AutomationClient = this.mockAutomationClient.Object,
44+
CommandRuntime = this.mockCommandRuntime
45+
};
46+
}
47+
48+
[TestMethod]
49+
public void StopAzureAutomationJobSuccessfull()
50+
{
51+
// Setup
52+
string accountName = "automation";
53+
Guid jobId = Guid.NewGuid();
54+
55+
this.mockAutomationClient.Setup(f => f.StopJob(accountName, jobId));
56+
57+
// Test
58+
this.cmdlet.AutomationAccountName = accountName;
59+
this.cmdlet.Id = jobId;
60+
this.cmdlet.ExecuteCmdlet();
61+
62+
// Assert
63+
this.mockAutomationClient.Verify(f => f.StopJob(accountName, jobId), Times.Once());
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)