Skip to content

Merge all changes from mpenta and kirab #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,20 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnitTests\GetAzureAutomationCredentialTest.cs" />
<Compile Include="UnitTests\GetAzureAutomationModuleTest.cs" />
<Compile Include="UnitTests\GetAzureAutomationScheduleTest.cs" />
<Compile Include="UnitTests\NewAzureAutomationCredentialTest.cs" />
<Compile Include="UnitTests\NewAzureAutomationModuleTest.cs" />
<Compile Include="UnitTests\NewAzureAutomationScheduleTest.cs" />
<Compile Include="UnitTests\NewAzureAutomationVariableTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationCredentialTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationModuleTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationScheduleTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationVariableTest.cs" />
<Compile Include="UnitTests\SetAzureAutomationCredentialTest.cs" />
<Compile Include="UnitTests\SetAzureAutomationScheduleTest.cs" />
<Compile Include="UnitTests\GetAzureAutomationVariableTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common\Commands.Common.Test\Commands.Common.Test.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.Automation.Cmdlet;
using Microsoft.Azure.Commands.Automation.Common;
using Microsoft.Azure.Commands.Automation.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Moq;

namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
{
[TestClass]
public class GetAzureAutomationCredentialTest : TestBase
{
private Mock<IAutomationClient> mockAutomationClient;

private MockCommandRuntime mockCommandRuntime;

private GetAzureAutomationCredential cmdlet;

[TestInitialize]
public void SetupTest()
{
this.mockAutomationClient = new Mock<IAutomationClient>();
this.mockCommandRuntime = new MockCommandRuntime();
this.cmdlet = new GetAzureAutomationCredential
{
AutomationClient = this.mockAutomationClient.Object,
CommandRuntime = this.mockCommandRuntime
};
}

[TestMethod]
public void GetAzureAutomationCredentialByNameSuccessfull()
{
// Setup
string accountName = "automation";
string credentialName = "credential";

this.mockAutomationClient.Setup(f => f.GetCredential(accountName, credentialName));

// Test
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.Name = credentialName;
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient.Verify(f => f.GetCredential(accountName, credentialName), Times.Once());
}

[TestMethod]
public void GetAzureAutomationCredentialByAllSuccessfull()
{
// Setup
string accountName = "automation";

this.mockAutomationClient.Setup(f => f.ListCredentials(accountName)).Returns((string a) => new List<Credential>());

// Test
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient.Verify(f => f.ListCredentials(accountName), Times.Once());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.Automation.Cmdlet;
using Microsoft.Azure.Commands.Automation.Common;
using Microsoft.Azure.Commands.Automation.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Moq;

namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
{
[TestClass]
public class GetAzureAutomationModuleTest : TestBase
{
private Mock<IAutomationClient> mockAutomationClient;

private MockCommandRuntime mockCommandRuntime;

private GetAzureAutomationModule cmdlet;

[TestInitialize]
public void SetupTest()
{
this.mockAutomationClient = new Mock<IAutomationClient>();
this.mockCommandRuntime = new MockCommandRuntime();
this.cmdlet = new GetAzureAutomationModule
{
AutomationClient = this.mockAutomationClient.Object,
CommandRuntime = this.mockCommandRuntime
};
}

[TestMethod]
public void GetAzureAutomationModuleByNameSuccessfull()
{
// Setup
string accountName = "automation";
string moduleName = "module";

this.mockAutomationClient.Setup(f => f.GetModule(accountName, moduleName));

// Test
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.Name = moduleName;
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient.Verify(f => f.GetModule(accountName, moduleName), Times.Once());
}

[TestMethod]
public void GetAzureAutomationModuleByAllSuccessfull()
{
// Setup
string accountName = "automation";

this.mockAutomationClient.Setup(f => f.ListModules(accountName)).Returns((string a) => new List<Module>());

// Test
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient.Verify(f => f.ListModules(accountName), Times.Once());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.Automation.Cmdlet;
using Microsoft.Azure.Commands.Automation.Common;
using Microsoft.Azure.Commands.Automation.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Moq;

namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
{
[TestClass]
public class GetAzureAutomationVariableTest : TestBase
{
private Mock<IAutomationClient> mockAutomationClient;

private MockCommandRuntime mockCommandRuntime;

private GetAzureAutomationVariable cmdlet;

[TestInitialize]
public void SetupTest()
{
this.mockAutomationClient = new Mock<IAutomationClient>();
this.mockCommandRuntime = new MockCommandRuntime();
this.cmdlet = new GetAzureAutomationVariable
{
AutomationClient = this.mockAutomationClient.Object,
CommandRuntime = this.mockCommandRuntime
};
}

[TestMethod]
public void GetAzureAutomationVariableByNameSuccessfull()
{
// Setup
string accountName = "automation";
string variableName = "variable";

this.mockAutomationClient.Setup(f => f.GetVariable(accountName, variableName));

// Test
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.Name = variableName;
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient.Verify(f => f.GetVariable(accountName, variableName), Times.Once());
}

[TestMethod]
public void GetAzureAutomationVariableByAllSuccessfull()
{
// Setup
string accountName = "automation";

this.mockAutomationClient.Setup(f => f.ListVariables(accountName)).Returns((string a) => new List<Variable>());

// Test
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient.Verify(f => f.ListVariables(accountName), Times.Once());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using Microsoft.Azure.Commands.Automation.Cmdlet;
using Microsoft.Azure.Commands.Automation.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Moq;
using System.Management.Automation;
using System.Security;
using System;

namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
{
[TestClass]
public class NewAzureAutomationCredentialTest : TestBase
{
private Mock<IAutomationClient> mockAutomationClient;

private MockCommandRuntime mockCommandRuntime;

private NewAzureAutomationCredential cmdlet;

[TestInitialize]
public void SetupTest()
{
this.mockAutomationClient = new Mock<IAutomationClient>();
this.mockCommandRuntime = new MockCommandRuntime();
this.cmdlet = new NewAzureAutomationCredential
{
AutomationClient = this.mockAutomationClient.Object,
CommandRuntime = this.mockCommandRuntime
};
}

[TestMethod]
public void NewAzureAutomationCredentialByPathSuccessfull()
{
// Setup
string accountName = "automation";
string credentialName = "credential";
string username = "testUser";
string password = "password";
string description = "desc";

var secureString = new SecureString();
Array.ForEach(password.ToCharArray(), secureString.AppendChar);
secureString.MakeReadOnly();

var value = new PSCredential(username, secureString);

this.mockAutomationClient.Setup(
f => f.CreateCredential(accountName, credentialName, username, password, description));

this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.Name = credentialName;
this.cmdlet.Description = description;
this.cmdlet.Value = value;
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient.Verify(f => f.CreateCredential(accountName, credentialName, username, password, description), Times.Once());
}
}
}
Loading