Skip to content

Commit 372d3dd

Browse files
committed
Merge pull request #1 from kiranisaac/master
Merge all changes from mpenta and kirab
2 parents 836e859 + b29bf88 commit 372d3dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3078
-5
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,20 @@
9292
</ItemGroup>
9393
<ItemGroup>
9494
<Compile Include="Properties\AssemblyInfo.cs" />
95+
<Compile Include="UnitTests\GetAzureAutomationCredentialTest.cs" />
96+
<Compile Include="UnitTests\GetAzureAutomationModuleTest.cs" />
9597
<Compile Include="UnitTests\GetAzureAutomationScheduleTest.cs" />
98+
<Compile Include="UnitTests\NewAzureAutomationCredentialTest.cs" />
99+
<Compile Include="UnitTests\NewAzureAutomationModuleTest.cs" />
96100
<Compile Include="UnitTests\NewAzureAutomationScheduleTest.cs" />
101+
<Compile Include="UnitTests\NewAzureAutomationVariableTest.cs" />
102+
<Compile Include="UnitTests\RemoveAzureAutomationCredentialTest.cs" />
103+
<Compile Include="UnitTests\RemoveAzureAutomationModuleTest.cs" />
97104
<Compile Include="UnitTests\RemoveAzureAutomationScheduleTest.cs" />
105+
<Compile Include="UnitTests\RemoveAzureAutomationVariableTest.cs" />
106+
<Compile Include="UnitTests\SetAzureAutomationCredentialTest.cs" />
98107
<Compile Include="UnitTests\SetAzureAutomationScheduleTest.cs" />
108+
<Compile Include="UnitTests\GetAzureAutomationVariableTest.cs" />
99109
</ItemGroup>
100110
<ItemGroup>
101111
<ProjectReference Include="..\..\..\Common\Commands.Common.Test\Commands.Common.Test.csproj">
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 GetAzureAutomationCredentialTest : TestBase
29+
{
30+
private Mock<IAutomationClient> mockAutomationClient;
31+
32+
private MockCommandRuntime mockCommandRuntime;
33+
34+
private GetAzureAutomationCredential cmdlet;
35+
36+
[TestInitialize]
37+
public void SetupTest()
38+
{
39+
this.mockAutomationClient = new Mock<IAutomationClient>();
40+
this.mockCommandRuntime = new MockCommandRuntime();
41+
this.cmdlet = new GetAzureAutomationCredential
42+
{
43+
AutomationClient = this.mockAutomationClient.Object,
44+
CommandRuntime = this.mockCommandRuntime
45+
};
46+
}
47+
48+
[TestMethod]
49+
public void GetAzureAutomationCredentialByNameSuccessfull()
50+
{
51+
// Setup
52+
string accountName = "automation";
53+
string credentialName = "credential";
54+
55+
this.mockAutomationClient.Setup(f => f.GetCredential(accountName, credentialName));
56+
57+
// Test
58+
this.cmdlet.AutomationAccountName = accountName;
59+
this.cmdlet.Name = credentialName;
60+
this.cmdlet.ExecuteCmdlet();
61+
62+
// Assert
63+
this.mockAutomationClient.Verify(f => f.GetCredential(accountName, credentialName), Times.Once());
64+
}
65+
66+
[TestMethod]
67+
public void GetAzureAutomationCredentialByAllSuccessfull()
68+
{
69+
// Setup
70+
string accountName = "automation";
71+
72+
this.mockAutomationClient.Setup(f => f.ListCredentials(accountName)).Returns((string a) => new List<Credential>());
73+
74+
// Test
75+
this.cmdlet.AutomationAccountName = accountName;
76+
this.cmdlet.ExecuteCmdlet();
77+
78+
// Assert
79+
this.mockAutomationClient.Verify(f => f.ListCredentials(accountName), Times.Once());
80+
}
81+
}
82+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 GetAzureAutomationModuleTest : TestBase
29+
{
30+
private Mock<IAutomationClient> mockAutomationClient;
31+
32+
private MockCommandRuntime mockCommandRuntime;
33+
34+
private GetAzureAutomationModule cmdlet;
35+
36+
[TestInitialize]
37+
public void SetupTest()
38+
{
39+
this.mockAutomationClient = new Mock<IAutomationClient>();
40+
this.mockCommandRuntime = new MockCommandRuntime();
41+
this.cmdlet = new GetAzureAutomationModule
42+
{
43+
AutomationClient = this.mockAutomationClient.Object,
44+
CommandRuntime = this.mockCommandRuntime
45+
};
46+
}
47+
48+
[TestMethod]
49+
public void GetAzureAutomationModuleByNameSuccessfull()
50+
{
51+
// Setup
52+
string accountName = "automation";
53+
string moduleName = "module";
54+
55+
this.mockAutomationClient.Setup(f => f.GetModule(accountName, moduleName));
56+
57+
// Test
58+
this.cmdlet.AutomationAccountName = accountName;
59+
this.cmdlet.Name = moduleName;
60+
this.cmdlet.ExecuteCmdlet();
61+
62+
// Assert
63+
this.mockAutomationClient.Verify(f => f.GetModule(accountName, moduleName), Times.Once());
64+
}
65+
66+
[TestMethod]
67+
public void GetAzureAutomationModuleByAllSuccessfull()
68+
{
69+
// Setup
70+
string accountName = "automation";
71+
72+
this.mockAutomationClient.Setup(f => f.ListModules(accountName)).Returns((string a) => new List<Module>());
73+
74+
// Test
75+
this.cmdlet.AutomationAccountName = accountName;
76+
this.cmdlet.ExecuteCmdlet();
77+
78+
// Assert
79+
this.mockAutomationClient.Verify(f => f.ListModules(accountName), Times.Once());
80+
}
81+
}
82+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 GetAzureAutomationVariableTest : TestBase
29+
{
30+
private Mock<IAutomationClient> mockAutomationClient;
31+
32+
private MockCommandRuntime mockCommandRuntime;
33+
34+
private GetAzureAutomationVariable cmdlet;
35+
36+
[TestInitialize]
37+
public void SetupTest()
38+
{
39+
this.mockAutomationClient = new Mock<IAutomationClient>();
40+
this.mockCommandRuntime = new MockCommandRuntime();
41+
this.cmdlet = new GetAzureAutomationVariable
42+
{
43+
AutomationClient = this.mockAutomationClient.Object,
44+
CommandRuntime = this.mockCommandRuntime
45+
};
46+
}
47+
48+
[TestMethod]
49+
public void GetAzureAutomationVariableByNameSuccessfull()
50+
{
51+
// Setup
52+
string accountName = "automation";
53+
string variableName = "variable";
54+
55+
this.mockAutomationClient.Setup(f => f.GetVariable(accountName, variableName));
56+
57+
// Test
58+
this.cmdlet.AutomationAccountName = accountName;
59+
this.cmdlet.Name = variableName;
60+
this.cmdlet.ExecuteCmdlet();
61+
62+
// Assert
63+
this.mockAutomationClient.Verify(f => f.GetVariable(accountName, variableName), Times.Once());
64+
}
65+
66+
[TestMethod]
67+
public void GetAzureAutomationVariableByAllSuccessfull()
68+
{
69+
// Setup
70+
string accountName = "automation";
71+
72+
this.mockAutomationClient.Setup(f => f.ListVariables(accountName)).Returns((string a) => new List<Variable>());
73+
74+
// Test
75+
this.cmdlet.AutomationAccountName = accountName;
76+
this.cmdlet.ExecuteCmdlet();
77+
78+
// Assert
79+
this.mockAutomationClient.Verify(f => f.ListVariables(accountName), Times.Once());
80+
}
81+
}
82+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.Collections.Generic;
16+
using Microsoft.Azure.Commands.Automation.Cmdlet;
17+
using Microsoft.Azure.Commands.Automation.Common;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
20+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
21+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
22+
using Moq;
23+
using System.Management.Automation;
24+
using System.Security;
25+
using System;
26+
27+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
28+
{
29+
[TestClass]
30+
public class NewAzureAutomationCredentialTest : TestBase
31+
{
32+
private Mock<IAutomationClient> mockAutomationClient;
33+
34+
private MockCommandRuntime mockCommandRuntime;
35+
36+
private NewAzureAutomationCredential cmdlet;
37+
38+
[TestInitialize]
39+
public void SetupTest()
40+
{
41+
this.mockAutomationClient = new Mock<IAutomationClient>();
42+
this.mockCommandRuntime = new MockCommandRuntime();
43+
this.cmdlet = new NewAzureAutomationCredential
44+
{
45+
AutomationClient = this.mockAutomationClient.Object,
46+
CommandRuntime = this.mockCommandRuntime
47+
};
48+
}
49+
50+
[TestMethod]
51+
public void NewAzureAutomationCredentialByPathSuccessfull()
52+
{
53+
// Setup
54+
string accountName = "automation";
55+
string credentialName = "credential";
56+
string username = "testUser";
57+
string password = "password";
58+
string description = "desc";
59+
60+
var secureString = new SecureString();
61+
Array.ForEach(password.ToCharArray(), secureString.AppendChar);
62+
secureString.MakeReadOnly();
63+
64+
var value = new PSCredential(username, secureString);
65+
66+
this.mockAutomationClient.Setup(
67+
f => f.CreateCredential(accountName, credentialName, username, password, description));
68+
69+
this.cmdlet.AutomationAccountName = accountName;
70+
this.cmdlet.Name = credentialName;
71+
this.cmdlet.Description = description;
72+
this.cmdlet.Value = value;
73+
this.cmdlet.ExecuteCmdlet();
74+
75+
// Assert
76+
this.mockAutomationClient.Verify(f => f.CreateCredential(accountName, credentialName, username, password, description), Times.Once());
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)