Skip to content

Commit 1deb07a

Browse files
committed
Added test cases for DSC cmdlets
1 parent 0fe82e9 commit 1deb07a

File tree

7 files changed

+654
-1
lines changed

7 files changed

+654
-1
lines changed

src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@
155155
<Compile Include="Properties\AssemblyInfo.cs" />
156156
<Compile Include="ScenarioTests\AutomationScenarioTestsBase.cs" />
157157
<Compile Include="ScenarioTests\AutomationTests.cs" />
158+
<Compile Include="UnitTests\GetAzureAutomationDscNodeConfigurationTest.cs" />
159+
<Compile Include="UnitTests\GetAzureAutomationDscNodeReportTest.cs" />
160+
<Compile Include="UnitTests\GetAzureAutomationDscNodeTest.cs" />
161+
<Compile Include="UnitTests\GetAzureAutomationDscCompilationJobTest.cs" />
162+
<Compile Include="UnitTests\GetAzureAutomationConfigurationTest.cs" />
158163
<Compile Include="UnitTests\GetAzureAutomationCertificateTest.cs" />
159164
<Compile Include="UnitTests\GetAzureAutomationConnectionTest.cs" />
160165
<Compile Include="UnitTests\GetAzureAutomationCredentialTest.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 Microsoft.Azure.Commands.Automation.Cmdlet;
16+
using Microsoft.Azure.Commands.Automation.Common;
17+
using Microsoft.Azure.Commands.Automation.Model;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
21+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
22+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
23+
using Moq;
24+
using System.Collections.Generic;
25+
using Xunit;
26+
27+
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
28+
{
29+
[TestClass]
30+
public class GetAzureAutomationConfigurationTest : RMTestBase
31+
{
32+
private Mock<IAutomationClient> mockAutomationClient;
33+
34+
private MockCommandRuntime mockCommandRuntime;
35+
36+
private GetAzureAutomationDscConfiguration cmdlet;
37+
38+
39+
public GetAzureAutomationConfigurationTest()
40+
{
41+
this.mockAutomationClient = new Mock<IAutomationClient>();
42+
this.mockCommandRuntime = new MockCommandRuntime();
43+
this.cmdlet = new GetAzureAutomationDscConfiguration
44+
{
45+
AutomationClient = this.mockAutomationClient.Object,
46+
CommandRuntime = this.mockCommandRuntime
47+
};
48+
}
49+
50+
[Fact]
51+
[Trait(Category.AcceptanceType, Category.CheckIn)]
52+
53+
public void GetAzureAutomationAllConfigurationsSuccessfull()
54+
{
55+
// Setup
56+
string resourceGroupName = "resourceGroup";
57+
string accountName = "account";
58+
string nextLink = string.Empty;
59+
this.cmdlet.SetParameterSet("ByAll");
60+
61+
this.mockAutomationClient.Setup(f => f.ListDscConfigurations(resourceGroupName, accountName, ref nextLink)).Returns((string a, string b, string c) => new List<DscConfiguration>());
62+
63+
// Test
64+
this.cmdlet.ResourceGroupName = resourceGroupName;
65+
this.cmdlet.AutomationAccountName = accountName;
66+
this.cmdlet.ExecuteCmdlet();
67+
68+
// Assert
69+
this.mockAutomationClient.Verify(f => f.ListDscConfigurations(resourceGroupName, accountName, ref nextLink), Times.Once());
70+
}
71+
72+
[Fact]
73+
[Trait(Category.AcceptanceType, Category.CheckIn)]
74+
75+
public void GetAzureAutomationConfigurationByNameSuccessfull()
76+
{
77+
// Setup
78+
string resourceGroupName = "resourceGroup";
79+
string accountName = "account";
80+
string configurationName = "configuration";
81+
this.cmdlet.SetParameterSet("ByConfigurationName");
82+
83+
this.mockAutomationClient.Setup(f => f.GetConfiguration(resourceGroupName, accountName, configurationName));
84+
85+
// Test
86+
this.cmdlet.ResourceGroupName = resourceGroupName;
87+
this.cmdlet.AutomationAccountName = accountName;
88+
this.cmdlet.Name = configurationName;
89+
this.cmdlet.ExecuteCmdlet();
90+
91+
// Assert
92+
this.mockAutomationClient.Verify(f => f.GetConfiguration(resourceGroupName, accountName, configurationName), Times.Once());
93+
}
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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 Microsoft.Azure.Commands.Automation.Cmdlet;
17+
using Microsoft.Azure.Commands.Automation.Common;
18+
using Microsoft.Azure.Commands.Automation.Model;
19+
using Microsoft.VisualStudio.TestTools.UnitTesting;
20+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24+
using Moq;
25+
using System.Collections.Generic;
26+
using Xunit;
27+
28+
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
29+
{
30+
[TestClass]
31+
public class GetAzureAutomationDscCompilationJobTest : RMTestBase
32+
{
33+
private Mock<IAutomationClient> mockAutomationClient;
34+
35+
private MockCommandRuntime mockCommandRuntime;
36+
37+
private GetAzureAutomationDscCompilationJob cmdlet;
38+
39+
40+
public GetAzureAutomationDscCompilationJobTest()
41+
{
42+
this.mockAutomationClient = new Mock<IAutomationClient>();
43+
this.mockCommandRuntime = new MockCommandRuntime();
44+
this.cmdlet = new GetAzureAutomationDscCompilationJob
45+
{
46+
AutomationClient = this.mockAutomationClient.Object,
47+
CommandRuntime = this.mockCommandRuntime
48+
};
49+
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
54+
public void GetAzureAutomationGetCompilationJobByIdSuccessfull()
55+
{
56+
// Setup
57+
string resourceGroupName = "resourceGroup";
58+
string accountName = "account";
59+
Guid id = Guid.NewGuid();
60+
61+
this.mockAutomationClient.Setup(f => f.GetCompilationJob(resourceGroupName, accountName, id)).Returns((string a, string b, Guid c) => new CompilationJob());
62+
63+
// Test
64+
this.cmdlet.ResourceGroupName = resourceGroupName;
65+
this.cmdlet.AutomationAccountName = accountName;
66+
this.cmdlet.Id = id;
67+
this.cmdlet.ExecuteCmdlet();
68+
69+
// Assert
70+
this.mockAutomationClient.Verify(f => f.GetCompilationJob(resourceGroupName, accountName, id), Times.Once());
71+
}
72+
73+
[Fact]
74+
[Trait(Category.AcceptanceType, Category.CheckIn)]
75+
76+
public void GetAzureAutomationCompilationJobsByConfigurationNameSuccessfull()
77+
{
78+
// Setup
79+
string resourceGroupName = "resourceGroup";
80+
string accountName = "account";
81+
string configurationName = "configuration";
82+
string nextLink = string.Empty;
83+
DateTimeOffset startTime = DateTimeOffset.Now;
84+
DateTimeOffset endTime = DateTimeOffset.Now;
85+
string status = "Completed";
86+
87+
this.mockAutomationClient.Setup(f => f.ListCompilationJobsByConfigurationName(resourceGroupName, accountName, configurationName, startTime, endTime, status, ref nextLink));
88+
89+
// Test
90+
this.cmdlet.ResourceGroupName = resourceGroupName;
91+
this.cmdlet.AutomationAccountName = accountName;
92+
this.cmdlet.ConfigurationName = configurationName;
93+
this.cmdlet.StartTime = startTime;
94+
this.cmdlet.EndTime = endTime;
95+
this.cmdlet.Status = status;
96+
this.cmdlet.ExecuteCmdlet();
97+
98+
// Assert
99+
this.mockAutomationClient.Verify(f => f.ListCompilationJobsByConfigurationName(resourceGroupName, accountName, configurationName, startTime, endTime, status, ref nextLink), Times.Once());
100+
}
101+
102+
[Fact]
103+
[Trait(Category.AcceptanceType, Category.CheckIn)]
104+
105+
public void GetAzureAutomationListCompilationJobs()
106+
{
107+
// Setup
108+
string resourceGroupName = "resourceGroup";
109+
string accountName = "account";
110+
string nextLink = string.Empty;
111+
DateTimeOffset startTime = DateTimeOffset.Now;
112+
DateTimeOffset endTime = DateTimeOffset.Now;
113+
string status = "Completed";
114+
115+
this.mockAutomationClient.Setup(f => f.ListCompilationJobs(resourceGroupName, accountName, startTime, endTime, status, ref nextLink));
116+
117+
// Test
118+
this.cmdlet.ResourceGroupName = resourceGroupName;
119+
this.cmdlet.AutomationAccountName = accountName;
120+
this.cmdlet.StartTime = startTime;
121+
this.cmdlet.EndTime = endTime;
122+
this.cmdlet.Status = status;
123+
this.cmdlet.ExecuteCmdlet();
124+
125+
// Assert
126+
this.mockAutomationClient.Verify(f => f.ListCompilationJobs(resourceGroupName, accountName, startTime, endTime, status, ref nextLink), Times.Once());
127+
}
128+
}
129+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 Microsoft.Azure.Commands.Automation.Cmdlet;
17+
using Microsoft.Azure.Commands.Automation.Common;
18+
using Microsoft.Azure.Commands.Automation.Model;
19+
using Microsoft.VisualStudio.TestTools.UnitTesting;
20+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24+
using Moq;
25+
using System.Collections.Generic;
26+
using Xunit;
27+
28+
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
29+
{
30+
[TestClass]
31+
public class GetAzureAutomationDscNodeConfigurationTest : RMTestBase
32+
{
33+
private Mock<IAutomationClient> mockAutomationClient;
34+
35+
private MockCommandRuntime mockCommandRuntime;
36+
37+
private GetAzureAutomationDscNodeConfiguration cmdlet;
38+
39+
40+
public GetAzureAutomationDscNodeConfigurationTest()
41+
{
42+
this.mockAutomationClient = new Mock<IAutomationClient>();
43+
this.mockCommandRuntime = new MockCommandRuntime();
44+
this.cmdlet = new GetAzureAutomationDscNodeConfiguration
45+
{
46+
AutomationClient = this.mockAutomationClient.Object,
47+
CommandRuntime = this.mockCommandRuntime
48+
};
49+
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
54+
public void GetAzureAutomationGetDscNodeConfigurationByName()
55+
{
56+
// Setup
57+
string resourceGroupName = "resourceGroup";
58+
string accountName = "account";
59+
string nodeConfigurationName = "config.localhost";
60+
string rollupStatus = "Good";
61+
62+
this.mockAutomationClient.Setup(f => f.GetNodeConfiguration(resourceGroupName, accountName, nodeConfigurationName, rollupStatus));
63+
64+
// Test
65+
this.cmdlet.ResourceGroupName = resourceGroupName;
66+
this.cmdlet.AutomationAccountName = accountName;
67+
this.cmdlet.Name = nodeConfigurationName;
68+
this.cmdlet.RollupStatus = rollupStatus;
69+
this.cmdlet.ExecuteCmdlet();
70+
71+
// Assert
72+
this.mockAutomationClient.Verify(f => f.GetNodeConfiguration(resourceGroupName, accountName, nodeConfigurationName, rollupStatus), Times.Once());
73+
}
74+
75+
[Fact]
76+
[Trait(Category.AcceptanceType, Category.CheckIn)]
77+
78+
public void GetAzureAutomationDscNodeConfigurationByConfigurationName()
79+
{
80+
// Setup
81+
string resourceGroupName = "resourceGroup";
82+
string accountName = "account";
83+
string configurationName = "configuration";
84+
string rollupStatus = "Good";
85+
string nextLink = string.Empty;
86+
87+
this.mockAutomationClient.Setup(f => f.ListNodeConfigurationsByConfigurationName(resourceGroupName, accountName, configurationName, rollupStatus, ref nextLink));
88+
89+
// Test
90+
this.cmdlet.ResourceGroupName = resourceGroupName;
91+
this.cmdlet.AutomationAccountName = accountName;
92+
this.cmdlet.ConfigurationName = configurationName;
93+
this.cmdlet.RollupStatus = rollupStatus;
94+
this.cmdlet.ExecuteCmdlet();
95+
96+
// Assert
97+
this.mockAutomationClient.Verify(f => f.ListNodeConfigurationsByConfigurationName(resourceGroupName, accountName, configurationName, rollupStatus, ref nextLink), Times.Once());
98+
}
99+
100+
[Fact]
101+
[Trait(Category.AcceptanceType, Category.CheckIn)]
102+
103+
public void GetAzureAutomationDscNodeConfigurations()
104+
{
105+
// Setup
106+
string resourceGroupName = "resourceGroup";
107+
string accountName = "account";
108+
string rollupStatus = "Good";
109+
string nextLink = string.Empty;
110+
111+
this.mockAutomationClient.Setup(f => f.ListNodeConfigurations(resourceGroupName, accountName, rollupStatus, ref nextLink));
112+
113+
// Test
114+
this.cmdlet.ResourceGroupName = resourceGroupName;
115+
this.cmdlet.AutomationAccountName = accountName;
116+
this.cmdlet.RollupStatus = rollupStatus;
117+
this.cmdlet.ExecuteCmdlet();
118+
119+
// Assert
120+
this.mockAutomationClient.Verify(f => f.ListNodeConfigurations(resourceGroupName, accountName, rollupStatus, ref nextLink), Times.Once());
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)