Skip to content

Commit

Permalink
Merge pull request #14 from Swoogan/refresh
Browse files Browse the repository at this point in the history
Updates to latest client library
  • Loading branch information
Swoogan authored Oct 6, 2018
2 parents 5f1e58b + 444be32 commit f87c167
Show file tree
Hide file tree
Showing 40 changed files with 909 additions and 967 deletions.
50 changes: 25 additions & 25 deletions Octopus-Cmdlets.Tests/AddEnvironmentTests.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using Moq;
using Octopus.Client.Model;
using Octopus.Client.Repositories;

namespace Octopus_Cmdlets.Tests
{
[TestClass]
public class AddEnvironmentTests
{
private const string CmdletName = "Add-OctoEnvironment";
private PowerShell _ps;
private readonly List<EnvironmentResource> _envs = new List<EnvironmentResource>();

[TestInitialize]
public void Init()
public AddEnvironmentTests()
{
_ps = Utilities.CreatePowerShell(CmdletName, typeof (AddEnvironment));
var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

_envs.Clear();

var envRepo = new Mock<IEnvironmentRepository>();
envRepo.Setup(e => e.Create(It.IsAny<EnvironmentResource>()))
.Returns(delegate(EnvironmentResource e)
envRepo.Setup(e => e.Create(It.IsAny<EnvironmentResource>(), It.IsAny<object>()))
.Returns((EnvironmentResource e, object o) =>
{
_envs.Add(e);
return e;
Expand All @@ -33,40 +31,42 @@ public void Init()
octoRepo.Setup(o => o.Environments).Returns(envRepo.Object);
}

[TestMethod]
[Fact]
public void With_Name()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev");
_ps.AddCommand(CmdletName)
.AddParameter(nameof(AddEnvironment.Name), "Octopus_Dev");
_ps.Invoke();

Assert.AreEqual(1, _envs.Count);
Assert.AreEqual("Octopus_Dev", _envs[0].Name);
Assert.Single(_envs);
Assert.Equal("Octopus_Dev", _envs[0].Name);
}

[TestMethod, ExpectedException(typeof(ParameterBindingException))]
[Fact]
public void With_Description()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).AddParameter("Description", "Octopus Development environment");
_ps.Invoke();
_ps.AddCommand(CmdletName)
.AddParameter(nameof(AddEnvironment.Description), "Octopus Development environment");
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
}

[TestMethod]
[Fact]
public void With_Name_And_Description()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).
AddParameter("Name", "Octopus_Dev").
AddParameter("Description", "Octopus Development environment");
AddParameter(nameof(AddEnvironment.Name), "Octopus_Dev").
AddParameter(nameof(AddEnvironment.Description), "Octopus Development environment");
_ps.Invoke();

Assert.AreEqual(1, _envs.Count);
Assert.AreEqual("Octopus_Dev", _envs[0].Name);
Assert.AreEqual("Octopus Development environment", _envs[0].Description);
Assert.Single(_envs);
Assert.Equal("Octopus_Dev", _envs[0].Name);
Assert.Equal("Octopus Development environment", _envs[0].Description);
}

[TestMethod]
[Fact]
public void With_Arguments()
{
// Execute cmdlet
Expand All @@ -75,17 +75,17 @@ public void With_Arguments()
.AddArgument("Octopus Development environment");
_ps.Invoke();

Assert.AreEqual(1, _envs.Count);
Assert.AreEqual("Octopus_Dev", _envs[0].Name);
Assert.AreEqual("Octopus Development environment", _envs[0].Description);
Assert.Single(_envs);
Assert.Equal("Octopus_Dev", _envs[0].Name);
Assert.Equal("Octopus Development environment", _envs[0].Description);
}

[TestMethod, ExpectedException(typeof(ParameterBindingException))]
[Fact]
public void No_Arguments()
{
// Execute cmdlet
_ps.AddCommand(CmdletName);
_ps.Invoke();
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
}
}
}
60 changes: 31 additions & 29 deletions Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using Moq;
using Octopus.Client.Model;

namespace Octopus_Cmdlets.Tests
{
[TestClass]
public class AddLibraryVariableTests
{
private const string CmdletName = "Add-OctoLibraryVariable";
private PowerShell _ps;
private readonly VariableSetResource _variableSet = new VariableSetResource();

[TestInitialize]
public void Init()
public AddLibraryVariableTests()
{
_ps = Utilities.CreatePowerShell(CmdletName, typeof(AddLibraryVariable));
var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);
Expand Down Expand Up @@ -52,63 +50,67 @@ public void Init()
octoRepo.Setup(o => o.Machines.FindByNames(new[] { "web-01" }, It.IsAny<string>(), It.IsAny<object>())).Returns(machines);
}

[TestMethod, ExpectedException(typeof(ParameterBindingException))]
[Fact]
public void No_Arguments()
{
// Execute cmdlet
_ps.AddCommand(CmdletName);
_ps.Invoke();
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
}

[TestMethod]
[Fact]
public void With_Name()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).AddParameter("VariableSet", "Octopus").AddParameter("Name", "Test");
_ps.AddCommand(CmdletName)
.AddParameter(nameof(AddLibraryVariable.VariableSet), "Octopus")
.AddParameter(nameof(AddLibraryVariable.Name), "Test");
_ps.Invoke();

Assert.AreEqual(1, _variableSet.Variables.Count);
Assert.AreEqual("Test", _variableSet.Variables[0].Name);
Assert.Equal(1, _variableSet.Variables.Count);
Assert.Equal("Test", _variableSet.Variables[0].Name);
}

[TestMethod, ExpectedException(typeof(CmdletInvocationException))]
[Fact]
public void With_Invalid_VariableSet()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).AddParameter("VariableSet", "Gibberish").AddParameter("Name", "Test");
_ps.Invoke();
_ps.AddCommand(CmdletName)
.AddParameter(nameof(AddLibraryVariable.VariableSet), "Gibberish")
.AddParameter(nameof(AddLibraryVariable.Name), "Test");
Assert.Throws<CmdletInvocationException>(() => _ps.Invoke());
}

[TestMethod]
[Fact]
public void With_All()
{
// Execute cmdlet
_ps.AddCommand(CmdletName)
.AddParameter("VariableSet", "Octopus")
.AddParameter("Name", "Test")
.AddParameter("Value", "Test Value")
.AddParameter("Environments", new[] { "DEV" })
.AddParameter("Roles", new[] { "Web" })
.AddParameter("Machines", new[] { "web-01" })
.AddParameter("Sensitive", false);
.AddParameter(nameof(AddLibraryVariable.VariableSet), "Octopus")
.AddParameter(nameof(AddLibraryVariable.Name), "Test")
.AddParameter(nameof(AddLibraryVariable.Value), "Test Value")
.AddParameter(nameof(AddLibraryVariable.Environments), new[] { "DEV" })
.AddParameter(nameof(AddLibraryVariable.Roles), new[] { "Web" })
.AddParameter(nameof(AddLibraryVariable.Machines), new[] { "web-01" })
.AddParameter(nameof(AddLibraryVariable.Sensitive), false);
_ps.Invoke();

Assert.AreEqual(1, _variableSet.Variables.Count);
Assert.AreEqual("Test", _variableSet.Variables[0].Name);
Assert.AreEqual("Test Value", _variableSet.Variables[0].Value);
Assert.Equal(1, _variableSet.Variables.Count);
Assert.Equal("Test", _variableSet.Variables[0].Name);
Assert.Equal("Test Value", _variableSet.Variables[0].Value);
}

[TestMethod]
[Fact]
public void With_Object()
{
// Execute cmdlet
_ps.AddCommand(CmdletName)
.AddParameter("VariableSet", "Octopus")
.AddParameter("InputObject", new VariableResource { Name = "Test" });
.AddParameter(nameof(AddLibraryVariable.VariableSet), "Octopus")
.AddParameter(nameof(AddLibraryVariable.InputObject), new VariableResource { Name = "Test" });
_ps.Invoke();

Assert.AreEqual(1, _variableSet.Variables.Count);
Assert.AreEqual("Test", _variableSet.Variables[0].Name);
Assert.Equal(1, _variableSet.Variables.Count);
Assert.Equal("Test", _variableSet.Variables[0].Name);
}
}
}
Loading

0 comments on commit f87c167

Please sign in to comment.