diff --git a/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs b/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs index 878d2c4..d709bff 100644 --- a/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs +++ b/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs @@ -1,21 +1,19 @@ 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 _envs = new List(); - [TestInitialize] - public void Init() + public AddEnvironmentTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (AddEnvironment)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -23,8 +21,8 @@ public void Init() _envs.Clear(); var envRepo = new Mock(); - envRepo.Setup(e => e.Create(It.IsAny())) - .Returns(delegate(EnvironmentResource e) + envRepo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((EnvironmentResource e, object o) => { _envs.Add(e); return e; @@ -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(() => _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 @@ -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(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs b/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs index 060e1aa..c81f866 100644 --- a/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs +++ b/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs @@ -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); @@ -52,63 +50,67 @@ public void Init() octoRepo.Setup(o => o.Machines.FindByNames(new[] { "web-01" }, It.IsAny(), It.IsAny())).Returns(machines); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _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(() => _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); } } } diff --git a/Octopus-Cmdlets.Tests/AddMachineTests.cs b/Octopus-Cmdlets.Tests/AddMachineTests.cs index a71dc02..07d9a0f 100644 --- a/Octopus-Cmdlets.Tests/AddMachineTests.cs +++ b/Octopus-Cmdlets.Tests/AddMachineTests.cs @@ -1,6 +1,6 @@ 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; @@ -8,14 +8,12 @@ namespace Octopus_Cmdlets.Tests { - [TestClass] public class AddMachineTests { private PowerShell _ps; private readonly List _machines = new List(); - [TestInitialize] - public void Init() + public AddMachineTests() { _ps = Utilities.CreatePowerShell("Add-OctoMachine", typeof (AddMachine)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -30,8 +28,8 @@ public void Init() _machines.Clear(); var machineRepo = new Mock(); - machineRepo.Setup(m => m.Create(It.IsAny())) - .Returns(delegate(MachineResource m) + machineRepo.Setup(m => m.Create(It.IsAny(), It.IsAny())) + .Returns((MachineResource m, object o) => { _machines.Add(m); return m; @@ -40,7 +38,7 @@ public void Init() octoRepo.Setup(o => o.Machines).Returns(machineRepo.Object); } - [TestMethod] + [Fact] public void With_EnvName() { // Execute cmdlet @@ -51,16 +49,16 @@ public void With_EnvName() .AddParameter("Endpoint", new ListeningTentacleEndpointResource { Uri = "https://server.domain:port/", Thumbprint = "ThisIsMyThumbprint" }); _ps.Invoke(); - Assert.AreEqual(1, _machines.Count); - Assert.AreEqual(new ReferenceCollection("environments-1").ToString(), _machines[0].EnvironmentIds.ToString()); - Assert.AreEqual("Tentacle_Name", _machines[0].Name); - Assert.AreEqual("ThisIsMyThumbprint", ((ListeningTentacleEndpointResource)_machines[0].Endpoint).Thumbprint); - Assert.AreEqual(new ReferenceCollection() { "Role1", "Role2" }.ToString(), _machines[0].Roles.ToString()); - Assert.AreEqual("https://server.domain:port/", ((ListeningTentacleEndpointResource)_machines[0].Endpoint).Uri); - Assert.AreEqual(CommunicationStyle.TentaclePassive, _machines[0].Endpoint.CommunicationStyle); + Assert.Single(_machines); + Assert.Equal(new ReferenceCollection("environments-1").ToString(), _machines[0].EnvironmentIds.ToString()); + Assert.Equal("Tentacle_Name", _machines[0].Name); + Assert.Equal("ThisIsMyThumbprint", ((ListeningTentacleEndpointResource)_machines[0].Endpoint).Thumbprint); + Assert.Equal(new ReferenceCollection() { "Role1", "Role2" }.ToString(), _machines[0].Roles.ToString()); + Assert.Equal("https://server.domain:port/", ((ListeningTentacleEndpointResource)_machines[0].Endpoint).Uri); + Assert.Equal(CommunicationStyle.TentaclePassive, _machines[0].Endpoint.CommunicationStyle); } - [TestMethod] + [Fact] public void With_EnvId() { // Execute cmdlet @@ -71,16 +69,16 @@ public void With_EnvId() .AddParameter("Endpoint", new ListeningTentacleEndpointResource { Uri = "https://server.domain:port/", Thumbprint = "ThisIsMyThumbprint" }); _ps.Invoke(); - Assert.AreEqual(1, _machines.Count); - Assert.AreEqual(new ReferenceCollection("environments-1").ToString(), _machines[0].EnvironmentIds.ToString()); - Assert.AreEqual("Tentacle_Name", _machines[0].Name); - Assert.AreEqual("ThisIsMyThumbprint", ((ListeningTentacleEndpointResource)_machines[0].Endpoint).Thumbprint); - Assert.AreEqual(new ReferenceCollection() { "Role1", "Role2" }.ToString(), _machines[0].Roles.ToString()); - Assert.AreEqual("https://server.domain:port/", ((ListeningTentacleEndpointResource)_machines[0].Endpoint).Uri); - Assert.AreEqual(CommunicationStyle.TentaclePassive, _machines[0].Endpoint.CommunicationStyle); + Assert.Single(_machines); + Assert.Equal(new ReferenceCollection("environments-1").ToString(), _machines[0].EnvironmentIds.ToString()); + Assert.Equal("Tentacle_Name", _machines[0].Name); + Assert.Equal("ThisIsMyThumbprint", ((ListeningTentacleEndpointResource)_machines[0].Endpoint).Thumbprint); + Assert.Equal(new ReferenceCollection() { "Role1", "Role2" }.ToString(), _machines[0].Roles.ToString()); + Assert.Equal("https://server.domain:port/", ((ListeningTentacleEndpointResource)_machines[0].Endpoint).Uri); + Assert.Equal(CommunicationStyle.TentaclePassive, _machines[0].Endpoint.CommunicationStyle); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Missing_Arguments1() { // Execute cmdlet @@ -91,10 +89,10 @@ public void Missing_Arguments1() .AddParameter("Roles", "Role1,Role2") .AddParameter("Uri", "https://server.domain:port/") .AddParameter("CommunicationStyle", "TentaclePassive"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Missing_Arguments2() { // Execute cmdlet @@ -105,10 +103,10 @@ public void Missing_Arguments2() .AddParameter("Roles", "Role1,Role2") .AddParameter("Uri", "https://server.domain:port/") .AddParameter("CommunicationStyle", "TentaclePassive"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Missing_Arguments3() { // Execute cmdlet @@ -119,10 +117,10 @@ public void Missing_Arguments3() .AddParameter("Roles", "Role1,Role2") .AddParameter("Uri", "https://server.domain:port/") .AddParameter("CommunicationStyle", "TentaclePassive"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Missing_Arguments4() { // Execute cmdlet @@ -133,10 +131,10 @@ public void Missing_Arguments4() //.AddParameter("Roles", "Role1,Role2") .AddParameter("Uri", "https://server.domain:port/") .AddParameter("CommunicationStyle", "TentaclePassive"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Missing_Arguments5() { // Execute cmdlet @@ -147,10 +145,10 @@ public void Missing_Arguments5() .AddParameter("Roles", "Role1,Role2") //.AddParameter("Uri", "https://server.domain:port/") .AddParameter("CommunicationStyle", "TentaclePassive"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Missing_Arguments6() { // Execute cmdlet @@ -162,15 +160,15 @@ public void Missing_Arguments6() .AddParameter("Uri", "https://server.domain:port/") //.AddParameter("CommunicationStyle", "TentaclePassive") ; - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand("Add-OctoMachine"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/AddFeedTests.cs b/Octopus-Cmdlets.Tests/AddNugetFeedTests.cs similarity index 55% rename from Octopus-Cmdlets.Tests/AddFeedTests.cs rename to Octopus-Cmdlets.Tests/AddNugetFeedTests.cs index edba40a..0e63ab4 100644 --- a/Octopus-Cmdlets.Tests/AddFeedTests.cs +++ b/Octopus-Cmdlets.Tests/AddNugetFeedTests.cs @@ -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 AddFeedTests + public class AddNugetFeedTests { - private const string CmdletName = "Add-OctoFeed"; + private const string CmdletName = "Add-OctoNugetFeed"; private PowerShell _ps; - private readonly List _feeds = new List(); + private readonly List _feeds = new List(); - [TestInitialize] - public void Init() + public AddNugetFeedTests() { - _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddFeed)); + _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddNugetFeed)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); _feeds.Clear(); var feedRepo = new Mock(); - feedRepo.Setup(e => e.Create(It.IsAny())) - .Returns(delegate(FeedResource e) + feedRepo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((NuGetFeedResource e, object o) => { _feeds.Add(e); return e; @@ -33,38 +31,40 @@ public void Init() octoRepo.Setup(o => o.Feeds).Returns(feedRepo.Object); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev"); _ps.Invoke(); - Assert.AreEqual(1, _feeds.Count); - Assert.AreEqual("Octopus_Dev", _feeds[0].Name); + Assert.Single(_feeds); + Assert.Equal("Octopus_Dev", _feeds[0].Name); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Uri() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Uri", "\\test"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name_And_Description() { // Execute cmdlet - _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev").AddParameter("Uri", "\\test"); + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddNugetFeed.Name), "Octopus_Dev") + .AddParameter(nameof(AddNugetFeed.FeedUri), "\\test"); _ps.Invoke(); - Assert.AreEqual(1, _feeds.Count); - Assert.AreEqual("Octopus_Dev", _feeds[0].Name); - Assert.AreEqual("\\test", _feeds[0].FeedUri); + Assert.Single(_feeds); + Assert.Equal("Octopus_Dev", _feeds[0].Name); + Assert.Equal("\\test", _feeds[0].FeedUri); } - [TestMethod] + [Fact] public void With_Arguements() { // Execute cmdlet @@ -73,17 +73,17 @@ public void With_Arguements() .AddArgument("\\test"); _ps.Invoke(); - Assert.AreEqual(1, _feeds.Count); - Assert.AreEqual("Octopus_Dev", _feeds[0].Name); - Assert.AreEqual("\\test", _feeds[0].FeedUri); + Assert.Single(_feeds); + Assert.Equal("Octopus_Dev", _feeds[0].Name); + Assert.Equal("\\test", _feeds[0].FeedUri); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs b/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs index 12c6c50..a1c718f 100644 --- a/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs +++ b/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs @@ -1,21 +1,19 @@ 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 AddProjectGroupTests { private const string CmdletName = "Add-OctoProjectGroup"; private PowerShell _ps; private readonly List _groups = new List(); - [TestInitialize] - public void Init() + public AddProjectGroupTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddProjectGroup)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -23,8 +21,8 @@ public void Init() _groups.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny())) - .Returns(delegate(ProjectGroupResource p) + repo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((ProjectGroupResource p, object o) => { _groups.Add(p); return p; @@ -33,37 +31,37 @@ public void Init() octoRepo.Setup(o => o.ProjectGroups).Returns(repo.Object); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); _ps.Invoke(); - Assert.AreEqual(1, _groups.Count); - Assert.AreEqual("Octopus", _groups[0].Name); + Assert.Single(_groups); + Assert.Equal("Octopus", _groups[0].Name); } - [TestMethod] + [Fact] public void With_Name_Parameter() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus"); _ps.Invoke(); - Assert.AreEqual(1, _groups.Count); - Assert.AreEqual("Octopus", _groups[0].Name); + Assert.Single(_groups); + Assert.Equal("Octopus", _groups[0].Name); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Description() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Description", "Octopus Development Group"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name_And_Description() { // Execute cmdlet @@ -72,17 +70,17 @@ public void With_Name_And_Description() .AddArgument("Octopus Development Group"); _ps.Invoke(); - Assert.AreEqual(1, _groups.Count); - Assert.AreEqual("Octopus", _groups[0].Name); - Assert.AreEqual("Octopus Development Group", _groups[0].Description); + Assert.Single(_groups); + Assert.Equal("Octopus", _groups[0].Name); + Assert.Equal("Octopus Development Group", _groups[0].Description); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/AddProjectTests.cs b/Octopus-Cmdlets.Tests/AddProjectTests.cs index 995a796..c873e3d 100644 --- a/Octopus-Cmdlets.Tests/AddProjectTests.cs +++ b/Octopus-Cmdlets.Tests/AddProjectTests.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; @@ -8,15 +8,13 @@ namespace Octopus_Cmdlets.Tests { - [TestClass] public class AddProjectTests { private const string CmdletName = "Add-OctoProject"; private PowerShell _ps; private readonly List _projects = new List(); - [TestInitialize] - public void Init() + public AddProjectTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddProject)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -34,8 +32,8 @@ public void Init() _projects.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny())) - .Returns(delegate(ProjectResource p) + repo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((ProjectResource p, object o) => { _projects.Add(p); return p; @@ -44,79 +42,79 @@ public void Init() octoRepo.Setup(o => o.Projects).Returns(repo.Object); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_ProjectGroup() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Octopus"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_ProjectGroup() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Gibberish").AddParameter("Name", "Octopus"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_ProjectGroupId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroupId", "projectgroups-1"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_ProjectGroupId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroupId", "Gibberish").AddParameter("Name", "Octopus"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Octopus").AddParameter("Name", "Octopus"); _ps.Invoke(); - Assert.AreEqual(1, _projects.Count); - Assert.AreEqual("Octopus", _projects[0].Name); + Assert.Single(_projects); + Assert.Equal("Octopus", _projects[0].Name); } - [TestMethod] + [Fact] public void ById_With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroupId", "projectgroups-1").AddParameter("Name", "Octopus"); _ps.Invoke(); - Assert.AreEqual(1, _projects.Count); - Assert.AreEqual("Octopus", _projects[0].Name); + Assert.Single(_projects); + Assert.Equal("Octopus", _projects[0].Name); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Description() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Description", "Octopus Development Project"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Group_And_Description() { // Execute cmdlet _ps.AddCommand(CmdletName) .AddParameter("ProjectGroup", "Octopus") .AddParameter("Description", "Octopus Development Project"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name_And_Description() { // Execute cmdlet @@ -126,13 +124,13 @@ public void With_Name_And_Description() .AddParameter("Description", "Octopus Development Project"); _ps.Invoke(); - Assert.AreEqual(1, _projects.Count); - Assert.AreEqual("Octopus", _projects[0].Name); - Assert.AreEqual("projectgroups-1", _projects[0].ProjectGroupId); - Assert.AreEqual("Octopus Development Project", _projects[0].Description); + Assert.Single(_projects); + Assert.Equal("Octopus", _projects[0].Name); + Assert.Equal("projectgroups-1", _projects[0].ProjectGroupId); + Assert.Equal("Octopus Development Project", _projects[0].Description); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet @@ -142,18 +140,18 @@ public void With_Arguments() .AddArgument("Octopus Development Project"); _ps.Invoke(); - Assert.AreEqual(1, _projects.Count); - Assert.AreEqual("Octopus", _projects[0].Name); - Assert.AreEqual("projectgroups-1", _projects[0].ProjectGroupId); - Assert.AreEqual("Octopus Development Project", _projects[0].Description); + Assert.Single(_projects); + Assert.Equal("Octopus", _projects[0].Name); + Assert.Equal("projectgroups-1", _projects[0].ProjectGroupId); + Assert.Equal("Octopus Development Project", _projects[0].Description); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/AddVariableSetTests.cs b/Octopus-Cmdlets.Tests/AddVariableSetTests.cs index f67d835..eb8dc78 100644 --- a/Octopus-Cmdlets.Tests/AddVariableSetTests.cs +++ b/Octopus-Cmdlets.Tests/AddVariableSetTests.cs @@ -1,21 +1,19 @@ 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 AddVariableSetTests { private const string CmdletName = "Add-OctoVariableSet"; private PowerShell _ps; private readonly List _sets = new List(); - [TestInitialize] - public void Init() + public AddVariableSetTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddVariableSet)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -23,8 +21,8 @@ public void Init() _sets.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny())) - .Returns(delegate(LibraryVariableSetResource e) + repo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((LibraryVariableSetResource e, object o) => { _sets.Add(e); return e; @@ -33,26 +31,26 @@ public void Init() octoRepo.Setup(o => o.LibraryVariableSets).Returns(repo.Object); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus"); _ps.Invoke(); - Assert.AreEqual(1, _sets.Count); - Assert.AreEqual("Octopus", _sets[0].Name); + Assert.Single(_sets); + Assert.Equal("Octopus", _sets[0].Name); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Description() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Description", "VaribleSet"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name_And_Description() { // Execute cmdlet @@ -61,12 +59,12 @@ public void With_Name_And_Description() .AddParameter("Description", "VariableSet"); _ps.Invoke(); - Assert.AreEqual(1, _sets.Count); - Assert.AreEqual("Octopus", _sets[0].Name); - Assert.AreEqual("VariableSet", _sets[0].Description); + Assert.Single(_sets); + Assert.Equal("Octopus", _sets[0].Name); + Assert.Equal("VariableSet", _sets[0].Description); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet @@ -75,17 +73,17 @@ public void With_Arguments() .AddArgument("VariableSet"); _ps.Invoke(); - Assert.AreEqual(1, _sets.Count); - Assert.AreEqual("Octopus", _sets[0].Name); - Assert.AreEqual("VariableSet", _sets[0].Description); + Assert.Single(_sets); + Assert.Equal("Octopus", _sets[0].Name); + Assert.Equal("VariableSet", _sets[0].Description); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/AddVariableTests.cs b/Octopus-Cmdlets.Tests/AddVariableTests.cs index db0a445..5f27b4b 100644 --- a/Octopus-Cmdlets.Tests/AddVariableTests.cs +++ b/Octopus-Cmdlets.Tests/AddVariableTests.cs @@ -1,19 +1,17 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class AddVariableTests { private const string CmdletName = "Add-OctoVariable"; private PowerShell _ps; private readonly VariableSetResource _variableSet = new VariableSetResource(); - [TestInitialize] - public void Init() + public AddVariableTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddVariable)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -44,34 +42,34 @@ public void Init() octoRepo.Setup(o => o.Machines.FindByNames(new[] { "web-01" }, null, null)).Returns(machines); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("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_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish").AddParameter("Name", "Test"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_All() { // Execute cmdlet @@ -86,15 +84,15 @@ public void With_All() .AddParameter("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); var scopeValue = _variableSet.Variables[0].Scope[ScopeField.Action]; - Assert.AreEqual("Step-1", scopeValue.ToString()); + Assert.Equal("Step-1", scopeValue.ToString()); } - [TestMethod] + [Fact] public void With_Object() { // Execute cmdlet @@ -103,8 +101,8 @@ public void With_Object() .AddParameter("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); } } } diff --git a/Octopus-Cmdlets.Tests/ConnectServerTests.cs b/Octopus-Cmdlets.Tests/ConnectServerTests.cs index 8971767..faac43a 100644 --- a/Octopus-Cmdlets.Tests/ConnectServerTests.cs +++ b/Octopus-Cmdlets.Tests/ConnectServerTests.cs @@ -1,10 +1,9 @@ using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Octopus.Client; namespace Octopus_Cmdlets.Tests { - [TestClass] public class ConnectServerTests { private PowerShell _ps; @@ -16,7 +15,7 @@ public void Init() _ps = Utilities.CreatePowerShell(CmdletName, typeof(ConnectServer)); } - [TestMethod] + [Fact] public void Connection() { _ps.AddCommand(CmdletName) @@ -24,12 +23,12 @@ public void Connection() .AddArgument("API-ABCDEFGHIJKLMNOP"); _ps.Invoke(); - Assert.IsNotNull(_ps.Runspace.SessionStateProxy.PSVariable.GetValue("OctopusRepository")); + Assert.NotNull(_ps.Runspace.SessionStateProxy.PSVariable.GetValue("OctopusRepository")); Assert.IsInstanceOfType(_ps.Runspace.SessionStateProxy.PSVariable.GetValue("OctopusRepository"), typeof (OctopusRepository)); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact, ExpectedException(typeof(ParameterBindingException))] public void Missing_Key() { _ps.AddCommand(CmdletName).AddArgument("http://localhost:8081"); diff --git a/Octopus-Cmdlets.Tests/CopyChannelTests.cs b/Octopus-Cmdlets.Tests/CopyChannelTests.cs index adfe658..b53354d 100644 --- a/Octopus-Cmdlets.Tests/CopyChannelTests.cs +++ b/Octopus-Cmdlets.Tests/CopyChannelTests.cs @@ -1,13 +1,13 @@ using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Model; using System.Collections.Generic; using Octopus.Client; +using Octopus.Client.Extensibility; namespace Octopus_Cmdlets.Tests { - [TestClass] public class CopyChannelTests { private const string CmdletName = "Copy-OctoChannel"; @@ -15,8 +15,7 @@ public class CopyChannelTests private Mock _octoRepo; private ChannelResource _channel; - [TestInitialize] - public void Init() + public CopyChannelTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(CopyChannel)); _octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -68,39 +67,39 @@ public void Init() _octoRepo.Setup(o => o.Channels.FindByName(It.IsAny(), "Default")).Returns((ChannelResource)null); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Just_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Just_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Priority"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Project_And_Name() { ChannelResource createdChannel = null; _octoRepo - .Setup(o => o.Channels.Create(It.IsAny())) - .Callback(ch => createdChannel = ch) - .Returns(ch => ch); + .Setup(o => o.Channels.Create(It.IsAny(), It.IsAny())) + .Callback((ch, o) => createdChannel = ch) + .Returns((ch, o) => ch); // Execute cmdlet _ps.AddCommand(CmdletName) @@ -108,52 +107,52 @@ public void With_Project_And_Name() .AddParameter("Name", "Priority"); _ps.Invoke(); - Assert.IsNotNull(createdChannel); - Assert.IsNull(createdChannel.Id); - Assert.AreEqual(_channel.LifecycleId, createdChannel.LifecycleId); - Assert.AreEqual(_channel.ProjectId, createdChannel.ProjectId); - Assert.AreEqual($"{_channel.Name} - Copy", createdChannel.Name); - Assert.AreEqual(_channel.Description, createdChannel.Description); - Assert.IsFalse(createdChannel.IsDefault); - Assert.IsNull(createdChannel.LastModifiedBy); - Assert.IsNull(createdChannel.LastModifiedOn); - Assert.IsNotNull(createdChannel.Links); - Assert.AreNotSame(_channel.Links, createdChannel.Links); - Assert.IsNotNull(createdChannel.Rules); - Assert.AreNotSame(_channel.Rules, createdChannel.Rules); - Assert.IsNotNull(createdChannel.TenantTags); - Assert.AreNotSame(_channel.TenantTags, createdChannel.TenantTags); + Assert.NotNull(createdChannel); + Assert.Null(createdChannel.Id); + Assert.Equal(_channel.LifecycleId, createdChannel.LifecycleId); + Assert.Equal(_channel.ProjectId, createdChannel.ProjectId); + Assert.Equal($"{_channel.Name} - Copy", createdChannel.Name); + Assert.Equal(_channel.Description, createdChannel.Description); + Assert.False(createdChannel.IsDefault); + Assert.Null(createdChannel.LastModifiedBy); + Assert.Null(createdChannel.LastModifiedOn); + Assert.NotNull(createdChannel.Links); + Assert.NotSame(_channel.Links, createdChannel.Links); + Assert.NotNull(createdChannel.Rules); + Assert.NotSame(_channel.Rules, createdChannel.Rules); + Assert.NotNull(createdChannel.TenantTags); + Assert.NotSame(_channel.TenantTags, createdChannel.TenantTags); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName) .AddParameter("Project", "Gibberish") .AddParameter("Name", "Priority"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Project_And_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName) .AddParameter("Project", "Octopus") .AddParameter("Name", "Default"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Destination() { ChannelResource createdChannel = null; _octoRepo - .Setup(o => o.Channels.Create(It.IsAny())) - .Callback(ch => createdChannel = ch) - .Returns(ch => ch); + .Setup(o => o.Channels.Create(It.IsAny(), It.IsAny())) + .Callback((ch, o) => createdChannel = ch) + .Returns((ch, o) => ch); // Execute cmdlet _ps.AddCommand(CmdletName) @@ -162,32 +161,32 @@ public void With_Destination() .AddParameter("Destination", "Passthrough"); _ps.Invoke(); - Assert.IsNotNull(createdChannel); - Assert.IsNull(createdChannel.Id); - Assert.AreEqual(_channel.LifecycleId, createdChannel.LifecycleId); - Assert.AreEqual(_channel.ProjectId, createdChannel.ProjectId); - Assert.AreEqual("Passthrough", createdChannel.Name); - Assert.AreEqual(_channel.Description, createdChannel.Description); - Assert.IsFalse(createdChannel.IsDefault); - Assert.IsNull(createdChannel.LastModifiedBy); - Assert.IsNull(createdChannel.LastModifiedOn); - Assert.IsNotNull(createdChannel.Links); - Assert.AreNotSame(_channel.Links, createdChannel.Links); - Assert.IsNotNull(createdChannel.Rules); - Assert.AreNotSame(_channel.Rules, createdChannel.Rules); - Assert.IsNotNull(createdChannel.TenantTags); - Assert.AreNotSame(_channel.TenantTags, createdChannel.TenantTags); + Assert.NotNull(createdChannel); + Assert.Null(createdChannel.Id); + Assert.Equal(_channel.LifecycleId, createdChannel.LifecycleId); + Assert.Equal(_channel.ProjectId, createdChannel.ProjectId); + Assert.Equal("Passthrough", createdChannel.Name); + Assert.Equal(_channel.Description, createdChannel.Description); + Assert.False(createdChannel.IsDefault); + Assert.Null(createdChannel.LastModifiedBy); + Assert.Null(createdChannel.LastModifiedOn); + Assert.NotNull(createdChannel.Links); + Assert.NotSame(_channel.Links, createdChannel.Links); + Assert.NotNull(createdChannel.Rules); + Assert.NotSame(_channel.Rules, createdChannel.Rules); + Assert.NotNull(createdChannel.TenantTags); + Assert.NotSame(_channel.TenantTags, createdChannel.TenantTags); } - [TestMethod] + [Fact] public void With_Arguments() { ChannelResource createdChannel = null; _octoRepo - .Setup(o => o.Channels.Create(It.IsAny())) - .Callback(ch => createdChannel = ch) - .Returns(ch => ch); + .Setup(o => o.Channels.Create(It.IsAny(), It.IsAny())) + .Callback((ch, o) => createdChannel = ch) + .Returns((ch, o) => ch); // Execute cmdlet _ps.AddCommand(CmdletName) @@ -196,21 +195,21 @@ public void With_Arguments() .AddArgument("Passthrough"); _ps.Invoke(); - Assert.IsNotNull(createdChannel); - Assert.IsNull(createdChannel.Id); - Assert.AreEqual(_channel.LifecycleId, createdChannel.LifecycleId); - Assert.AreEqual(_channel.ProjectId, createdChannel.ProjectId); - Assert.AreEqual("Passthrough", createdChannel.Name); - Assert.AreEqual(_channel.Description, createdChannel.Description); - Assert.IsFalse(createdChannel.IsDefault); - Assert.IsNull(createdChannel.LastModifiedBy); - Assert.IsNull(createdChannel.LastModifiedOn); - Assert.IsNotNull(createdChannel.Links); - Assert.AreNotSame(_channel.Links, createdChannel.Links); - Assert.IsNotNull(createdChannel.Rules); - Assert.AreNotSame(_channel.Rules, createdChannel.Rules); - Assert.IsNotNull(createdChannel.TenantTags); - Assert.AreNotSame(_channel.TenantTags, createdChannel.TenantTags); + Assert.NotNull(createdChannel); + Assert.Null(createdChannel.Id); + Assert.Equal(_channel.LifecycleId, createdChannel.LifecycleId); + Assert.Equal(_channel.ProjectId, createdChannel.ProjectId); + Assert.Equal("Passthrough", createdChannel.Name); + Assert.Equal(_channel.Description, createdChannel.Description); + Assert.False(createdChannel.IsDefault); + Assert.Null(createdChannel.LastModifiedBy); + Assert.Null(createdChannel.LastModifiedOn); + Assert.NotNull(createdChannel.Links); + Assert.NotSame(_channel.Links, createdChannel.Links); + Assert.NotNull(createdChannel.Rules); + Assert.NotSame(_channel.Rules, createdChannel.Rules); + Assert.NotNull(createdChannel.TenantTags); + Assert.NotSame(_channel.TenantTags, createdChannel.TenantTags); } } } diff --git a/Octopus-Cmdlets.Tests/CopyProjectTests.cs b/Octopus-Cmdlets.Tests/CopyProjectTests.cs index c894241..9bb76f7 100644 --- a/Octopus-Cmdlets.Tests/CopyProjectTests.cs +++ b/Octopus-Cmdlets.Tests/CopyProjectTests.cs @@ -1,13 +1,12 @@ 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 CopyProjectTests { private const string CmdletName = "Copy-OctoProject"; @@ -16,8 +15,7 @@ public class CopyProjectTests private VariableSetResource _copyVariables; private DeploymentProcessResource _copyProcess; - [TestInitialize] - public void Init() + public CopyProjectTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (CopyProject)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -49,8 +47,8 @@ public void Init() octoRepo.Setup(o => o.Projects.FindByName("Source", null, null)).Returns(project); octoRepo.Setup(o => o.Projects.FindByName("Gibberish", null, null)).Returns((ProjectResource) null); - octoRepo.Setup(o => o.Projects.Create(It.IsAny())).Returns( - delegate(ProjectResource p) + octoRepo.Setup(o => o.Projects.Create(It.IsAny(), It.IsAny())).Returns( + (ProjectResource p, object o) => { p.VariableSetId = "variablesets-2"; p.DeploymentProcessId = "deploymentprocesses-2"; @@ -86,7 +84,7 @@ public void Init() octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-2" }))).Returns(_copyVariables); } - [TestMethod] + [Fact] public void With_All() { // Execute cmdlet @@ -96,36 +94,36 @@ public void With_All() .AddParameter("ProjectGroup", "Octopus"); _ps.Invoke(); - Assert.AreEqual(2, _projects.Count); + Assert.Equal(2, _projects.Count); var source = _projects[0]; var copy = _projects[1]; - Assert.AreEqual("Copy", copy.Name); - Assert.AreEqual(source.Description, copy.Description); - Assert.AreEqual("projectgroups-1", copy.ProjectGroupId); - Assert.AreEqual(source.DefaultToSkipIfAlreadyInstalled, copy.DefaultToSkipIfAlreadyInstalled); - CollectionAssert.AreEqual(source.IncludedLibraryVariableSetIds, copy.IncludedLibraryVariableSetIds); - Assert.AreEqual(source.VersioningStrategy, copy.VersioningStrategy); - Assert.AreEqual(source.AutoCreateRelease, copy.AutoCreateRelease); - Assert.AreEqual(source.ReleaseCreationStrategy, copy.ReleaseCreationStrategy); - Assert.AreEqual(source.IsDisabled, copy.IsDisabled); - Assert.AreEqual(source.LifecycleId, copy.LifecycleId); + Assert.Equal("Copy", copy.Name); + Assert.Equal(source.Description, copy.Description); + Assert.Equal("projectgroups-1", copy.ProjectGroupId); + Assert.Equal(source.DefaultToSkipIfAlreadyInstalled, copy.DefaultToSkipIfAlreadyInstalled); + Assert.Equal(source.IncludedLibraryVariableSetIds, copy.IncludedLibraryVariableSetIds); + Assert.Equal(source.VersioningStrategy, copy.VersioningStrategy); + Assert.Equal(source.AutoCreateRelease, copy.AutoCreateRelease); + Assert.Equal(source.ReleaseCreationStrategy, copy.ReleaseCreationStrategy); + Assert.Equal(source.IsDisabled, copy.IsDisabled); + Assert.Equal(source.LifecycleId, copy.LifecycleId); var variable = _copyVariables.Variables.FirstOrDefault(x => x.Name == "Name" && x.Value == "Value"); - Assert.IsNotNull(variable); - Assert.IsTrue(variable.Scope.ContainsKey(ScopeField.Action)); - Assert.AreEqual(0, variable.Scope[ScopeField.Action].Count); - Assert.IsTrue(variable.Scope.ContainsKey(ScopeField.Environment)); - Assert.AreEqual("environments-1", variable.Scope[ScopeField.Environment].First()); + Assert.NotNull(variable); + Assert.True(variable.Scope.ContainsKey(ScopeField.Action)); + Assert.Empty(variable.Scope[ScopeField.Action]); + Assert.True(variable.Scope.ContainsKey(ScopeField.Environment)); + Assert.Equal("environments-1", variable.Scope[ScopeField.Environment].First()); var steps = _copyProcess.Steps.FirstOrDefault(x => x.Name == "Database"); - Assert.IsNotNull(steps); - Assert.AreEqual(1, steps.Actions.Count); - Assert.AreEqual("Action", steps.Actions[0].Name); - Assert.AreEqual("environments-1", steps.Actions[0].Environments.First()); + Assert.NotNull(steps); + Assert.Single(steps.Actions); + Assert.Equal("Action", steps.Actions[0].Name); + Assert.Equal("environments-1", steps.Actions[0].Environments.First()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Group() { // Execute cmdlet @@ -133,10 +131,10 @@ public void With_Invalid_Group() .AddParameter("Name", "Source") .AddParameter("Destination", "Copy") .AddParameter("ProjectGroup", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet @@ -144,10 +142,10 @@ public void With_Invalid_Project() .AddParameter("Name", "Gibberish") .AddParameter("Destination", "Copy") .AddParameter("ProjectGroup", "Octopus"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet @@ -157,28 +155,28 @@ public void With_Arguments() .AddArgument("Octopus"); _ps.Invoke(); - Assert.AreEqual(2, _projects.Count); + Assert.Equal(2, _projects.Count); var source = _projects[0]; var copy = _projects[1]; - Assert.AreEqual("Copy", copy.Name); - Assert.AreEqual(source.Description, copy.Description); - Assert.AreEqual("projectgroups-1", copy.ProjectGroupId); - Assert.AreEqual(source.DefaultToSkipIfAlreadyInstalled, copy.DefaultToSkipIfAlreadyInstalled); - CollectionAssert.AreEqual(source.IncludedLibraryVariableSetIds, copy.IncludedLibraryVariableSetIds); - Assert.AreEqual(source.VersioningStrategy, copy.VersioningStrategy); - Assert.AreEqual(source.AutoCreateRelease, copy.AutoCreateRelease); - Assert.AreEqual(source.ReleaseCreationStrategy, copy.ReleaseCreationStrategy); - Assert.AreEqual(source.IsDisabled, copy.IsDisabled); - Assert.AreEqual(source.LifecycleId, copy.LifecycleId); + Assert.Equal("Copy", copy.Name); + Assert.Equal(source.Description, copy.Description); + Assert.Equal("projectgroups-1", copy.ProjectGroupId); + Assert.Equal(source.DefaultToSkipIfAlreadyInstalled, copy.DefaultToSkipIfAlreadyInstalled); + Assert.Equal(source.IncludedLibraryVariableSetIds, copy.IncludedLibraryVariableSetIds); + Assert.Equal(source.VersioningStrategy, copy.VersioningStrategy); + Assert.Equal(source.AutoCreateRelease, copy.AutoCreateRelease); + Assert.Equal(source.ReleaseCreationStrategy, copy.ReleaseCreationStrategy); + Assert.Equal(source.IsDisabled, copy.IsDisabled); + Assert.Equal(source.LifecycleId, copy.LifecycleId); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/CopyStepTests.cs b/Octopus-Cmdlets.Tests/CopyStepTests.cs index 9ce3ea0..d1ad4c6 100644 --- a/Octopus-Cmdlets.Tests/CopyStepTests.cs +++ b/Octopus-Cmdlets.Tests/CopyStepTests.cs @@ -1,19 +1,17 @@ using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class CopyStepTests { private const string CmdletName = "Copy-OctoStep"; private PowerShell _ps; private DeploymentProcessResource _process; - [TestInitialize] - public void Init() + public CopyStepTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(CopyStep)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -58,31 +56,31 @@ public void Init() octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-2" }))).Returns(new VariableSetResource()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Just_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void Just_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Website"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Project_And_Name() { // Execute cmdlet @@ -91,27 +89,28 @@ public void With_Project_And_Name() .AddParameter("Name", "Website"); _ps.Invoke(); - Assert.AreEqual(2, _process.Steps.Count); - Assert.AreEqual("Website - Copy", _process.Steps[1].Name); + Assert.Equal(2, _process.Steps.Count); + Assert.Equal("Website - Copy", _process.Steps[1].Name); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish").AddParameter("Name", "Website"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Project_And_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Name", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); + } - [TestMethod] + [Fact] public void With_Destination() { // Execute cmdlet @@ -121,27 +120,27 @@ public void With_Destination() .AddParameter("Destination", "Webservice"); _ps.Invoke(); - Assert.AreEqual(2, _process.Steps.Count); + Assert.Equal(2, _process.Steps.Count); var step = _process.Steps[1]; - Assert.AreEqual("Webservice", step.Name); - Assert.AreNotEqual("deploymentsteps-1", step.Id); + Assert.Equal("Webservice", step.Name); + Assert.NotEqual("deploymentsteps-1", step.Id); var action = new DeploymentActionResource { Name = "Webservice" }; action.Environments.Add("environments-1"); var actionResource = step.Actions[0]; - Assert.AreEqual(action.Name, actionResource.Name); - Assert.AreEqual("NuGet", actionResource.ActionType); - - Assert.AreEqual(action.Environments.ToString(), actionResource.Environments.ToString()); - Assert.IsTrue(actionResource.Properties.ContainsKey("Something")); - Assert.AreEqual("Value", actionResource.Properties["Something"].Value); - Assert.IsTrue(actionResource.Properties["SomethingElse"].IsSensitive); - Assert.AreEqual("Secret", actionResource.Properties["SomethingElse"].SensitiveValue.NewValue); + Assert.Equal(action.Name, actionResource.Name); + Assert.Equal("NuGet", actionResource.ActionType); + + Assert.Equal(action.Environments.ToString(), actionResource.Environments.ToString()); + Assert.True(actionResource.Properties.ContainsKey("Something")); + Assert.Equal("Value", actionResource.Properties["Something"].Value); + Assert.True(actionResource.Properties["SomethingElse"].IsSensitive); + Assert.Equal("Secret", actionResource.Properties["SomethingElse"].SensitiveValue.NewValue); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet @@ -151,24 +150,24 @@ public void With_Arguments() .AddArgument("Webservice"); _ps.Invoke(); - Assert.AreEqual(2, _process.Steps.Count); + Assert.Equal(2, _process.Steps.Count); var step = _process.Steps[1]; - Assert.AreEqual("Webservice", step.Name); - Assert.AreNotEqual("deploymentsteps-1", step.Id); + Assert.Equal("Webservice", step.Name); + Assert.NotEqual("deploymentsteps-1", step.Id); var action = new DeploymentActionResource { Name = "Webservice" }; action.Environments.Add("environments-1"); var actionResource = step.Actions[0]; - Assert.AreEqual(action.Name, actionResource.Name); - Assert.AreEqual("NuGet", actionResource.ActionType); - - Assert.AreEqual(action.Environments.ToString(), actionResource.Environments.ToString()); - Assert.IsTrue(actionResource.Properties.ContainsKey("Something")); - Assert.AreEqual("Value", actionResource.Properties["Something"].Value); - Assert.IsTrue(actionResource.Properties["SomethingElse"].IsSensitive); - Assert.AreEqual("Secret", actionResource.Properties["SomethingElse"].SensitiveValue.NewValue); + Assert.Equal(action.Name, actionResource.Name); + Assert.Equal("NuGet", actionResource.ActionType); + + Assert.Equal(action.Environments.ToString(), actionResource.Environments.ToString()); + Assert.True(actionResource.Properties.ContainsKey("Something")); + Assert.Equal("Value", actionResource.Properties["Something"].Value); + Assert.True(actionResource.Properties["SomethingElse"].IsSensitive); + Assert.Equal("Secret", actionResource.Properties["SomethingElse"].SensitiveValue.NewValue); } } } diff --git a/Octopus-Cmdlets.Tests/GetActionTests.cs b/Octopus-Cmdlets.Tests/GetActionTests.cs index 57f4ad2..fa556f9 100644 --- a/Octopus-Cmdlets.Tests/GetActionTests.cs +++ b/Octopus-Cmdlets.Tests/GetActionTests.cs @@ -1,19 +1,17 @@ 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 GetActionTests { private const string CmdletName = "Get-OctoAction"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetActionTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetAction)); @@ -37,83 +35,83 @@ public void Init() octoRepo.Setup(o => o.DeploymentProcesses).Returns(dpRepo.Object); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); var actions = _ps.Invoke(); - Assert.AreEqual(2, actions.Count); + Assert.Equal(2, actions.Count); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Do Stuff"); var actions = _ps.Invoke(); - Assert.AreEqual(1, actions.Count); - Assert.AreEqual("Do Stuff", actions[0].Name); + Assert.Single(actions); + Assert.Equal("Do Stuff", actions[0].Name); } - [TestMethod] + [Fact] public void With_Name_Parameter() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddParameter("Name", "Do Stuff"); var actions = _ps.Invoke(); - Assert.AreEqual(1, actions.Count); - Assert.AreEqual("Do Stuff", actions[0].Name); + Assert.Single(actions); + Assert.Equal("Do Stuff", actions[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Gibberish"); var actions = _ps.Invoke(); - Assert.AreEqual(0, actions.Count); + Assert.Empty(actions); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddParameter("Id", "Globally unique identifier"); var actions = _ps.Invoke(); - Assert.AreEqual(1, actions.Count); - Assert.AreEqual("Do Stuff", actions[0].Name); + Assert.Single(actions); + Assert.Equal("Do Stuff", actions[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddParameter("Id", "Gibberish"); var actions = _ps.Invoke(); - Assert.AreEqual(0, actions.Count); + Assert.Empty(actions); } } } diff --git a/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs b/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs index 7026da0..d3342a3 100644 --- a/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs +++ b/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs @@ -1,20 +1,18 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetDeploymentProcessTests { private const string CmdletName = "Get-OctoDeploymentProcess"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetDeploymentProcessTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetDeploymentProcess)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -36,71 +34,71 @@ public void Init() .Throws(new OctopusResourceNotFoundException("Not Found")); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "DeploymentProcesses-1"); var projects = _ps.Invoke(); - Assert.AreEqual(1, projects.Count); + Assert.Single(projects); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); var projects = _ps.Invoke(); - Assert.AreEqual(0, projects.Count); + Assert.Empty(projects); } - [TestMethod] + [Fact] public void With_ProjectName() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus"); var projects = _ps.Invoke(); - Assert.AreEqual(1, projects.Count); + Assert.Single(projects); } - [TestMethod] + [Fact] public void With_Invalid_ProjectName() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish"); var projects = _ps.Invoke(); - Assert.AreEqual(0, projects.Count); + Assert.Empty(projects); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("DeploymentProcesses-1"); var projects = _ps.Invoke(); - Assert.AreEqual(1, projects.Count); + Assert.Single(projects); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Both() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish").AddParameter("Project", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/GetDeploymentTests.cs b/Octopus-Cmdlets.Tests/GetDeploymentTests.cs index fc749bd..09fc13c 100644 --- a/Octopus-Cmdlets.Tests/GetDeploymentTests.cs +++ b/Octopus-Cmdlets.Tests/GetDeploymentTests.cs @@ -1,18 +1,17 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Octopus.Client.Model; +using Octopus.Client.Extensibility; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetDeploymentTests { private const string CmdletName = "Get-OctoDeployment"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetDeploymentTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetDeployment)); @@ -39,85 +38,85 @@ public void Init() octoRepo.Setup(o => o.Releases.Get("Releases-1")).Returns(release); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Project_And_Release() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Release", "1.0.0"); var deployments = _ps.Invoke(); - Assert.AreEqual(1, deployments.Count); + Assert.Single(deployments); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project_And_Release() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish").AddParameter("Release", "1.0.0"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Project_And_Invalid_Release() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Release", "Gibberish"); var deployments = _ps.Invoke(); - Assert.AreEqual(0, deployments.Count); + Assert.Empty(deployments); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Project_And_ReleaseId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("ReleaseId", "Releases-1"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_ReleaseId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ReleaseId", "Releases-1"); var deployments = _ps.Invoke(); - Assert.AreEqual(1, deployments.Count); + Assert.Single(deployments); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("1.0.0"); var deployments = _ps.Invoke(); - Assert.AreEqual(1, deployments.Count); + Assert.Single(deployments); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Both() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish").AddParameter("Project", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/GetEnvironmentTests.cs b/Octopus-Cmdlets.Tests/GetEnvironmentTests.cs index 97bea56..fe5fd41 100644 --- a/Octopus-Cmdlets.Tests/GetEnvironmentTests.cs +++ b/Octopus-Cmdlets.Tests/GetEnvironmentTests.cs @@ -1,18 +1,16 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetEnvironmentTests { private const string CmdletName = "Get-OctoEnvironment"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetEnvironmentTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetEnvironment)); @@ -29,85 +27,85 @@ public void Init() octoRepo.Setup(o => o.Environments.FindAll(null, null)).Returns(environments); } - [TestMethod] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); var environments = _ps.Invoke(); - Assert.AreEqual(4, environments.Count); + Assert.Equal(4, environments.Count); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); var environments = _ps.Invoke(); - Assert.AreEqual(1, environments.Count); - Assert.AreEqual("Octopus", environments[0].Name); + Assert.Single(environments); + Assert.Equal("Octopus", environments[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var environments = _ps.Invoke(); - Assert.AreEqual(0, environments.Count); + Assert.Empty(environments); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "environments-1"); var environments = _ps.Invoke(); - Assert.AreEqual(1, environments.Count); - Assert.AreEqual("Octopus", environments[0].Name); + Assert.Single(environments); + Assert.Equal("Octopus", environments[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); var environments = _ps.Invoke(); - Assert.AreEqual(0, environments.Count); + Assert.Empty(environments); } - [TestMethod] + [Fact] public void With_ScopeValue() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ScopeValue", new ScopeValue("environments-1")); var environments = _ps.Invoke(); - Assert.AreEqual(1, environments.Count); - Assert.AreEqual("Octopus", environments[0].Name); + Assert.Single(environments); + Assert.Equal("Octopus", environments[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_ScopeValue() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ScopeValue", new ScopeValue("Gibberish")); var environments = _ps.Invoke(); - Assert.AreEqual(0, environments.Count); + Assert.Empty(environments); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Id_And_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Name").AddParameter("Id", "Id"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs b/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs index 8b64b34..9bc2037 100644 --- a/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs +++ b/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs @@ -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; using Octopus.Client.Repositories; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetExternalFeedTests { private const string CmdletName = "Get-OctoExternalFeed"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetExternalFeedTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (GetExternalFeed)); @@ -26,8 +24,8 @@ public void Init() var feedRepo = new Mock(); var feedResources = new List { - new FeedResource {FeedUri = @"\\someshare\octopus", Name = "Octopus"}, - new FeedResource {FeedUri = @"\\someshare\deploy", Name = "Deploy"} + new NuGetFeedResource {FeedUri = @"\\someshare\octopus", Name = "Octopus"}, + new NuGetFeedResource {FeedUri = @"\\someshare\deploy", Name = "Deploy"} }; feedRepo.Setup(f => f.FindAll(null, null)).Returns(feedResources); @@ -40,35 +38,35 @@ where n.Equals(f.Name, StringComparison.InvariantCultureIgnoreCase) octoRepo.Setup(o => o.Feeds).Returns(feedRepo.Object); } - [TestMethod] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); var feeds = _ps.Invoke(); - Assert.AreEqual(2, feeds.Count); + Assert.Equal(2, feeds.Count); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); var feeds = _ps.Invoke(); - Assert.AreEqual(1, feeds.Count); - Assert.AreEqual("Octopus", feeds[0].Name); + Assert.Single(feeds); + Assert.Equal("Octopus", feeds[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var feeds = _ps.Invoke(); - Assert.AreEqual(0, feeds.Count); + Assert.Empty(feeds); } } } diff --git a/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs b/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs index b2f1884..087b4a9 100644 --- a/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs +++ b/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs @@ -1,19 +1,17 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Repositories; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetMachineRoleTests { private const string CmdletName = "Get-OctoMachineRole"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetMachineRoleTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetMachineRole)); @@ -31,35 +29,35 @@ public void Init() octoRepo.Setup(o => o.MachineRoles).Returns(machineRepo.Object); } - [TestMethod] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); var results = _ps.Invoke(); - Assert.AreEqual(2, results.Count); + Assert.Equal(2, results.Count); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("WebServer"); var results = _ps.Invoke(); - Assert.AreEqual(1, results.Count); - Assert.AreEqual("WebServer", results[0]); + Assert.Single(results); + Assert.Equal("WebServer", results[0]); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var results = _ps.Invoke(); - Assert.AreEqual(0, results.Count); + Assert.Empty(results); } } } diff --git a/Octopus-Cmdlets.Tests/GetMachineTests.cs b/Octopus-Cmdlets.Tests/GetMachineTests.cs index 39c3321..a3909af 100644 --- a/Octopus-Cmdlets.Tests/GetMachineTests.cs +++ b/Octopus-Cmdlets.Tests/GetMachineTests.cs @@ -1,20 +1,18 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetMachineTests { private const string CmdletName = "Get-OctoMachine"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetMachineTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetMachine)); @@ -35,77 +33,77 @@ public void Init() octoRepo.Setup(o => o.Machines.Get(It.Is((string s) => s != "Machines-1"))).Throws(new OctopusResourceNotFoundException("Not Found")); } - [TestMethod] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); var machines = _ps.Invoke(); - Assert.AreEqual(2, machines.Count); + Assert.Equal(2, machines.Count); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] {"dbserver-01"}); var machines = _ps.Invoke(); - Assert.AreEqual(1, machines.Count); - Assert.AreEqual("dbserver-01", machines[0].Name); + Assert.Single(machines); + Assert.Equal("dbserver-01", machines[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Gibberish" }); var machines = _ps.Invoke(); - Assert.AreEqual(0, machines.Count); + Assert.Empty(machines); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", new[] { "Machines-1" }); var machines = _ps.Invoke(); - Assert.AreEqual(1, machines.Count); - Assert.AreEqual("dbserver-01", machines[0].Name); + Assert.Single(machines); + Assert.Equal("dbserver-01", machines[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", new[] { "Gibberish" }); var machines = _ps.Invoke(); - Assert.AreEqual(0, machines.Count); + Assert.Empty(machines); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Name_And_Id() { // Execute cmdlet _ps.AddCommand(CmdletName) .AddParameter("Name", new[] {"dbserver-01"}) .AddParameter("Id", new[] {"Machines-1"}); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument(new[] { "dbserver-01" }); var machines = _ps.Invoke(); - Assert.AreEqual(1, machines.Count); - Assert.AreEqual("dbserver-01", machines[0].Name); + Assert.Single(machines); + Assert.Equal("dbserver-01", machines[0].Name); } } } diff --git a/Octopus-Cmdlets.Tests/GetProjectGroupTests.cs b/Octopus-Cmdlets.Tests/GetProjectGroupTests.cs index e4a8b80..09de2ff 100644 --- a/Octopus-Cmdlets.Tests/GetProjectGroupTests.cs +++ b/Octopus-Cmdlets.Tests/GetProjectGroupTests.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; @@ -10,14 +10,12 @@ namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetProjectGroupTests { private const string CmdletName = "Get-OctoProjectGroup"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetProjectGroupTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (GetProjectGroup)); @@ -46,7 +44,7 @@ where g.Name.Equals(n, StringComparison.InvariantCultureIgnoreCase) private static Func CreateGet(IEnumerable groupResources) { - return delegate(string id) + return (string id) => { var group = (from g in groupResources where g.Id.Equals(id, @@ -60,56 +58,56 @@ where g.Id.Equals(id, }; } - [TestMethod] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); var groups = _ps.Invoke(); - Assert.AreEqual(2, groups.Count); + Assert.Equal(2, groups.Count); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); var groups = _ps.Invoke(); - Assert.AreEqual(1, groups.Count); - Assert.AreEqual("Octopus", groups[0].Name); + Assert.Single(groups); + Assert.Equal("Octopus", groups[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var groups = _ps.Invoke(); - Assert.AreEqual(0, groups.Count); + Assert.Empty(groups); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "projectgroups-1"); var groups = _ps.Invoke(); - Assert.AreEqual(1, groups.Count); - Assert.AreEqual("Octopus", groups[0].Name); + Assert.Single(groups); + Assert.Equal("Octopus", groups[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "gibberish"); var groups = _ps.Invoke(); - Assert.AreEqual(0, groups.Count); + Assert.Empty(groups); } } } diff --git a/Octopus-Cmdlets.Tests/GetProjectTests.cs b/Octopus-Cmdlets.Tests/GetProjectTests.cs index d6aee8d..470d556 100644 --- a/Octopus-Cmdlets.Tests/GetProjectTests.cs +++ b/Octopus-Cmdlets.Tests/GetProjectTests.cs @@ -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; using Octopus.Client.Repositories; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetProjectTests { private const string CmdletName = "Get-OctoProject"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetProjectTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (GetProject)); @@ -60,108 +58,108 @@ where p.Name.Equals(n, StringComparison.InvariantCultureIgnoreCase) octoRepo.Setup(o => o.ProjectGroups).Returns(projectGroupRepo.Object); } - [TestMethod] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); var projects = _ps.Invoke(); - Assert.AreEqual(4, projects.Count); + Assert.Equal(4, projects.Count); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); var projects = _ps.Invoke(); - Assert.AreEqual(1, projects.Count); - Assert.AreEqual("Octopus", projects[0].Name); + Assert.Single(projects); + Assert.Equal("Octopus", projects[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var projects = _ps.Invoke(); - Assert.AreEqual(0, projects.Count); + Assert.Empty(projects); } - [TestMethod] + [Fact] public void With_Group() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Octopus"); var projects = _ps.Invoke(); - Assert.AreEqual(2, projects.Count); - Assert.AreEqual(1, projects.Count(p => p.Name == "Octopus")); - Assert.AreEqual(1, projects.Count(p => p.Name == "Deploy")); + Assert.Equal(2, projects.Count); + Assert.Equal(1, projects.Count(p => p.Name == "Octopus")); + Assert.Equal(1, projects.Count(p => p.Name == "Deploy")); } - [TestMethod] + [Fact] public void With_Invalid_Group() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Gibberish"); var projects = _ps.Invoke(); - Assert.AreEqual(0, projects.Count); + Assert.Empty(projects); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "projects-1"); var projects = _ps.Invoke(); - Assert.AreEqual(1, projects.Count); - Assert.AreEqual("Octopus", projects[0].Name); + Assert.Single(projects); + Assert.Equal("Octopus", projects[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "projects-5000"); var projects = _ps.Invoke(); - Assert.AreEqual(0, projects.Count); + Assert.Empty(projects); } - [TestMethod] + [Fact] public void With_Exclude() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Exclude", new[]{"Deploy", "Server"}); var projects = _ps.Invoke(); - Assert.AreEqual(2, projects.Count); - Assert.AreEqual(1, projects.Count(p => p.Name == "Octopus")); - Assert.AreEqual(1, projects.Count(p => p.Name == "Automation")); + Assert.Equal(2, projects.Count); + Assert.Equal(1, projects.Count(p => p.Name == "Octopus")); + Assert.Equal(1, projects.Count(p => p.Name == "Automation")); } - [TestMethod] + [Fact] public void With_Invalid_Exclude() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Exclude", "Gibberish"); var projects = _ps.Invoke(); - Assert.AreEqual(4, projects.Count); + Assert.Equal(4, projects.Count); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Id_And_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Name").AddParameter("Id", "Id"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/GetReleaseTests.cs b/Octopus-Cmdlets.Tests/GetReleaseTests.cs index dc7dae0..f58eeab 100644 --- a/Octopus-Cmdlets.Tests/GetReleaseTests.cs +++ b/Octopus-Cmdlets.Tests/GetReleaseTests.cs @@ -1,19 +1,18 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Octopus.Client.Exceptions; using Octopus.Client.Model; +using Octopus.Client.Extensibility; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetReleaseTests { private const string CmdletName = "Get-OctoRelease"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetReleaseTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetRelease)); @@ -42,90 +41,90 @@ public void Init() octoRepo.Setup(o => o.Releases.Get("Gibberish")).Throws(new OctopusResourceNotFoundException("Not found")); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus"); var releases = _ps.Invoke(); - Assert.AreEqual(3, releases.Count); + Assert.Equal(3, releases.Count); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_ProjectId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectId", "projects-1"); var releases = _ps.Invoke(); - Assert.AreEqual(3, releases.Count); + Assert.Equal(3, releases.Count); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_ProjectId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectId", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Project_And_Version() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Version", new[] {"1.0.0"}); var releases = _ps.Invoke(); - Assert.AreEqual(1, releases.Count); - Assert.AreEqual("1.0.0", releases[0].Version); + Assert.Single(releases); + Assert.Equal("1.0.0", releases[0].Version); } - [TestMethod] + [Fact] public void With_Project_And_Invalid_Version() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Version", new[] { "Gibberish" }); var releases = _ps.Invoke(); - Assert.AreEqual(0, releases.Count); + Assert.Empty(releases); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "releases-1"); var releases = _ps.Invoke(); - Assert.AreEqual(1, releases.Count); - Assert.AreEqual("1.0.0", releases[0].Version); + Assert.Single(releases); + Assert.Equal("1.0.0", releases[0].Version); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); var releases = _ps.Invoke(); - Assert.AreEqual(0, releases.Count); + Assert.Empty(releases); } } } diff --git a/Octopus-Cmdlets.Tests/GetStepTests.cs b/Octopus-Cmdlets.Tests/GetStepTests.cs index 7202979..eb0be51 100644 --- a/Octopus-Cmdlets.Tests/GetStepTests.cs +++ b/Octopus-Cmdlets.Tests/GetStepTests.cs @@ -1,20 +1,18 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetStepTests { private const string CmdletName = "Get-OctoStep"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetStepTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (GetStep)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -46,100 +44,100 @@ public void Init() .Throws(new OctopusResourceNotFoundException("Not Found")); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_ProjectName() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus"); var steps = _ps.Invoke(); - Assert.AreEqual(2, steps.Count); - Assert.AreEqual("Test Step", steps[0].Name); + Assert.Equal(2, steps.Count); + Assert.Equal("Test Step", steps[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_ProjectName() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish"); var steps = _ps.Invoke(); - Assert.AreEqual(0, steps.Count); + Assert.Empty(steps); } - [TestMethod] + [Fact] public void With_ProjectId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectId", "projects-1"); var steps = _ps.Invoke(); - Assert.AreEqual(2, steps.Count); - Assert.AreEqual("Test Step", steps[0].Name); + Assert.Equal(2, steps.Count); + Assert.Equal("Test Step", steps[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_ProjectId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectId", "Gibberish"); var steps = _ps.Invoke(); - Assert.AreEqual(0, steps.Count); + Assert.Empty(steps); } - [TestMethod] + [Fact] public void With_ProcessId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("DeploymentProcessId", "deploymentprocess-projects-1"); var steps = _ps.Invoke(); - Assert.AreEqual(2, steps.Count); - Assert.AreEqual("Test Step", steps[0].Name); + Assert.Equal(2, steps.Count); + Assert.Equal("Test Step", steps[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_ProcessId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("DeploymentProcessId", "Gibberish"); var steps = _ps.Invoke(); - Assert.AreEqual(0, steps.Count); + Assert.Empty(steps); } - [TestMethod] + [Fact] public void With_ProjectAndName() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Name", "Test Step 2"); var steps = _ps.Invoke(); - Assert.AreEqual(1, steps.Count); - Assert.AreEqual("Test Step 2", steps[0].Name); + Assert.Single(steps); + Assert.Equal("Test Step 2", steps[0].Name); } - [TestMethod] + [Fact] public void With_ProjectIdAndName() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectId", "projects-1").AddParameter("Name", "Test Step 2"); var steps = _ps.Invoke(); - Assert.AreEqual(1, steps.Count); - Assert.AreEqual("Test Step 2", steps[0].Name); + Assert.Single(steps); + Assert.Equal("Test Step 2", steps[0].Name); } - [TestMethod] + [Fact] public void With_ProcessIdAndName() { // Execute cmdlet @@ -148,32 +146,20 @@ public void With_ProcessIdAndName() .AddParameter("Name", "Test Step 2"); var steps = _ps.Invoke(); - Assert.AreEqual(1, steps.Count); - Assert.AreEqual("Test Step 2", steps[0].Name); + Assert.Single(steps); + Assert.Equal("Test Step 2", steps[0].Name); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Test Step 2"); var steps = _ps.Invoke(); - Assert.AreEqual(1, steps.Count); - Assert.AreEqual("Test Step 2", steps[0].Name); - } - - - [TestMethod, ExpectedException(typeof(ParameterBindingException))] - public void With_KitchenSink() - { - // Execute cmdlet - _ps.AddCommand(CmdletName) - .AddParameter("Project", "Gibberish") - .AddParameter("ProjectId", "Gibberish") - .AddParameter("DeploymentProcessId", "Gibberish"); - _ps.Invoke(); + Assert.Single(steps); + Assert.Equal("Test Step 2", steps[0].Name); } } } diff --git a/Octopus-Cmdlets.Tests/GetVariableSetTests.cs b/Octopus-Cmdlets.Tests/GetVariableSetTests.cs index c8ed176..c640161 100644 --- a/Octopus-Cmdlets.Tests/GetVariableSetTests.cs +++ b/Octopus-Cmdlets.Tests/GetVariableSetTests.cs @@ -1,20 +1,18 @@ 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 GetVariableSetTests { private const string CmdletName = "Get-OctoVariableSet"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetVariableSetTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetVariableSet)); @@ -47,75 +45,75 @@ public void Init() octoRepo.Setup(o => o.VariableSets).Returns(variableRepo.Object); } - [TestMethod] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); var variables = _ps.Invoke(); - Assert.AreEqual(3, variables.Count); + Assert.Equal(3, variables.Count); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); var variables = _ps.Invoke(); - Assert.AreEqual(1, variables.Count); - Assert.AreEqual("Octopus", variables[0].Name); + Assert.Single(variables); + Assert.Equal("Octopus", variables[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var variables = _ps.Invoke(); - Assert.AreEqual(0, variables.Count); + Assert.Empty(variables); } - [TestMethod] + [Fact] public void By_Name_With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus"); var variables = _ps.Invoke(); - Assert.AreEqual(1, variables.Count); - Assert.AreEqual("Octopus", variables[0].Name); + Assert.Single(variables); + Assert.Equal("Octopus", variables[0].Name); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "LibraryVariableSets-1"); var variables = _ps.Invoke(); - Assert.AreEqual(1, variables.Count); - Assert.AreEqual("Octopus", variables[0].Name); + Assert.Single(variables); + Assert.Equal("Octopus", variables[0].Name); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); var variables = _ps.Invoke(); - Assert.AreEqual(0, variables.Count); + Assert.Empty(variables); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Id_And_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus").AddParameter("Id", "Id"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/GetVariableTests.cs b/Octopus-Cmdlets.Tests/GetVariableTests.cs index dec3847..c151430 100644 --- a/Octopus-Cmdlets.Tests/GetVariableTests.cs +++ b/Octopus-Cmdlets.Tests/GetVariableTests.cs @@ -2,21 +2,20 @@ using System.Collections.Generic; using System.Linq; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Model; using Octopus.Client.Repositories; +using Octopus.Client.Extensibility; namespace Octopus_Cmdlets.Tests { - [TestClass] public class GetVariableTests { private const string CmdletName = "Get-OctoVariable"; private PowerShell _ps; - [TestInitialize] - public void Init() + public GetVariableTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetVariable)); @@ -74,97 +73,97 @@ public void Init() octoRepo.Setup(o => o.VariableSets).Returns(variableRepo.Object); } - [TestMethod] + [Fact] public void By_Project_No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); var variables = _ps.Invoke(); - Assert.AreEqual(3, variables.Count); + Assert.Equal(3, variables.Count); } - [TestMethod] + [Fact] public void By_Project_With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Deploy"); var variables = _ps.Invoke(); - Assert.AreEqual(1, variables.Count); - Assert.AreEqual("To Production", variables[0].Value); + Assert.Single(variables); + Assert.Equal("To Production", variables[0].Value); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish").AddArgument("Deploy"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void By_VariableSet_No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "Octopus"); var variables = _ps.Invoke(); - Assert.AreEqual(3, variables.Count); + Assert.Equal(3, variables.Count); } - [TestMethod] + [Fact] public void With_Invalid_VariableSet() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "Gibberish").AddArgument("Deploy"); _ps.Invoke(); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("Library variable set 'Gibberish' was not found.", _ps.Streams.Warning[0].ToString()); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("Library variable set 'Gibberish' was not found.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void By_VariableSet_With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "Octopus").AddArgument("Deploy"); var variables = _ps.Invoke(); - Assert.AreEqual(1, variables.Count); - Assert.AreEqual("To Production", variables[0].Value); + Assert.Single(variables); + Assert.Equal("To Production", variables[0].Value); } - [TestMethod] + [Fact] public void By_VariableSetId_No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSetId", "LibraryVariableSets-1"); var variables = _ps.Invoke(); - Assert.AreEqual(3, variables.Count); + Assert.Equal(3, variables.Count); } - [TestMethod] + [Fact] public void By_VariableSetId_With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSetId", "LibraryVariableSets-1").AddArgument("Deploy"); var variables = _ps.Invoke(); - Assert.AreEqual(1, variables.Count); - Assert.AreEqual("To Production", variables[0].Value); + Assert.Single(variables); + Assert.Equal("To Production", variables[0].Value); } - [TestMethod] + [Fact] public void With_Invalid_VariableSetId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSetId", "Gibberish").AddArgument("Deploy"); _ps.Invoke(); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("Library variable set with id 'Gibberish' was not found.", _ps.Streams.Warning[0].ToString()); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("Library variable set with id 'Gibberish' was not found.", _ps.Streams.Warning[0].ToString()); } } } diff --git a/Octopus-Cmdlets.Tests/Octopus-Cmdlets.Tests.csproj b/Octopus-Cmdlets.Tests/Octopus-Cmdlets.Tests.csproj index 3712edd..6728caa 100644 --- a/Octopus-Cmdlets.Tests/Octopus-Cmdlets.Tests.csproj +++ b/Octopus-Cmdlets.Tests/Octopus-Cmdlets.Tests.csproj @@ -13,21 +13,17 @@ - - - - - - - - + + + - - + + + - \ No newline at end of file + diff --git a/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs b/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs index 226a157..443fde7 100644 --- a/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs @@ -1,13 +1,12 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class RemoveEnvironmentTests { private const string CmdletName = "Remove-OctoEnvironment"; @@ -20,8 +19,7 @@ public class RemoveEnvironmentTests Name = "Test" }; - [TestInitialize] - public void Init() + public RemoveEnvironmentTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(RemoveEnvironment)); @@ -34,7 +32,7 @@ public void Init() _envs.Add(new EnvironmentResource { Id = "Environments-3", Name = "Prod" }); octoRepo.Setup(o => o.Environments.Delete(It.IsAny())).Callback( - delegate (EnvironmentResource set) + (EnvironmentResource set) => { if (_envs.Contains(set)) _envs.Remove(set); @@ -51,114 +49,114 @@ public void Init() octoRepo.Setup(o => o.Environments.FindByName("Gibberish", It.IsAny(), It.IsAny())).Returns((EnvironmentResource) null); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - //[TestMethod] + //[Fact] //public void With_Object() //{ // // Execute cmdlet // _ps.AddCommand(CmdletName).AddParameter("InputObject", _env); // _ps.Invoke(); - // Assert.AreEqual(2, _envs.Count); + // Assert.Equal(2, _envs.Count); // Assert.IsFalse(_envs.Contains(_env)); //} - //[TestMethod] + //[Fact] //public void With_Invalid_Object() //{ // // Execute cmdlet // _ps.AddCommand(CmdletName).AddParameter("InputObject", new EnvironmentResource()); // _ps.Invoke(); - // Assert.AreEqual(3, _envs.Count); - // Assert.AreEqual(1, _ps.Streams.Warning.Count); - // Assert.AreEqual("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); + // Assert.Equal(3, _envs.Count); + // Assert.Equal(1, _ps.Streams.Warning.Count); + // Assert.Equal("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); //} - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", new [] {"Environments-2"}); _ps.Invoke(); - Assert.AreEqual(2, _envs.Count); - Assert.IsFalse(_envs.Contains(_env)); + Assert.Equal(2, _envs.Count); + Assert.DoesNotContain(_env, _envs); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", new[] {"Gibberish"}); _ps.Invoke(); - Assert.AreEqual(3, _envs.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("An environment with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _envs.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("An environment with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] {"Test"}); _ps.Invoke(); - Assert.AreEqual(2, _envs.Count); - Assert.IsFalse(_envs.Contains(_env)); + Assert.Equal(2, _envs.Count); + Assert.DoesNotContain(_env, _envs); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Gibberish" }); _ps.Invoke(); - Assert.AreEqual(3, _envs.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("The environment 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _envs.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("The environment 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Valid_And_Invalid_Names() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Test", "Gibberish" }); _ps.Invoke(); - Assert.AreEqual(2, _envs.Count); - Assert.IsFalse(_envs.Contains(_env)); + Assert.Equal(2, _envs.Count); + Assert.DoesNotContain(_env, _envs); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument(new[] { "Test" }); _ps.Invoke(); - Assert.AreEqual(2, _envs.Count); - Assert.IsFalse(_envs.Contains(_env)); + Assert.Equal(2, _envs.Count); + Assert.DoesNotContain(_env, _envs); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Name_And_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Gibberish").AddParameter("Id", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Name_And_Object() //{ // // Execute cmdlet @@ -168,7 +166,7 @@ public void With_Name_And_Id() // _ps.Invoke(); //} - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Object_And_Id() //{ // // Execute cmdlet @@ -178,7 +176,7 @@ public void With_Name_And_Id() // _ps.Invoke(); //} - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Name_Id_And_Object() //{ // // Execute cmdlet diff --git a/Octopus-Cmdlets.Tests/RemoveProjectGroupTests.cs b/Octopus-Cmdlets.Tests/RemoveProjectGroupTests.cs index 7aef449..e498855 100644 --- a/Octopus-Cmdlets.Tests/RemoveProjectGroupTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveProjectGroupTests.cs @@ -1,13 +1,12 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class RemoveProjectGroupTests { private const string CmdletName = "Remove-OctoProjectGroup"; @@ -20,8 +19,7 @@ public class RemoveProjectGroupTests Name = "Deploy" }; - [TestInitialize] - public void Init() + public RemoveProjectGroupTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(RemoveProjectGroup)); @@ -34,7 +32,7 @@ public void Init() _groups.Add(new ProjectGroupResource { Id = "ProjectGroups-3", Name = "Automation" }); octoRepo.Setup(o => o.ProjectGroups.Delete(It.IsAny())).Callback( - delegate (ProjectGroupResource set) + (ProjectGroupResource set) => { if (_groups.Contains(set)) _groups.Remove(set); @@ -51,114 +49,114 @@ public void Init() octoRepo.Setup(o => o.ProjectGroups.FindByName("Gibberish", It.IsAny(), It.IsAny())).Returns((ProjectGroupResource)null); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - //[TestMethod] + //[Fact] //public void With_Object() //{ // // Execute cmdlet // _ps.AddCommand(CmdletName).AddParameter("InputObject", _env); // _ps.Invoke(); - // Assert.AreEqual(2, _groups.Count); + // Assert.Equal(2, _groups.Count); // Assert.IsFalse(_groups.Contains(_env)); //} - //[TestMethod] + //[Fact] //public void With_Invalid_Object() //{ // // Execute cmdlet // _ps.AddCommand(CmdletName).AddParameter("InputObject", new ProjectGroupResource()); // _ps.Invoke(); - // Assert.AreEqual(3, _groups.Count); - // Assert.AreEqual(1, _ps.Streams.Warning.Count); - // Assert.AreEqual("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); + // Assert.Equal(3, _groups.Count); + // Assert.Equal(1, _ps.Streams.Warning.Count); + // Assert.Equal("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); //} - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", new[] { "ProjectGroups-2" }); _ps.Invoke(); - Assert.AreEqual(2, _groups.Count); - Assert.IsFalse(_groups.Contains(_group)); + Assert.Equal(2, _groups.Count); + Assert.DoesNotContain(_group, _groups); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", new[] { "Gibberish" }); _ps.Invoke(); - Assert.AreEqual(3, _groups.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("A project group with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _groups.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("A project group with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Test" }); _ps.Invoke(); - Assert.AreEqual(2, _groups.Count); - Assert.IsFalse(_groups.Contains(_group)); + Assert.Equal(2, _groups.Count); + Assert.DoesNotContain(_group, _groups); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Gibberish" }); _ps.Invoke(); - Assert.AreEqual(3, _groups.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("The project group 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _groups.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("The project group 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Valid_And_Invalid_Names() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Test", "Gibberish" }); _ps.Invoke(); - Assert.AreEqual(2, _groups.Count); - Assert.IsFalse(_groups.Contains(_group)); + Assert.Equal(2, _groups.Count); + Assert.DoesNotContain(_group, _groups); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument(new[] { "Test" }); _ps.Invoke(); - Assert.AreEqual(2, _groups.Count); - Assert.IsFalse(_groups.Contains(_group)); + Assert.Equal(2, _groups.Count); + Assert.DoesNotContain(_group, _groups); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Name_And_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Gibberish").AddParameter("Id", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Name_And_Object() //{ // // Execute cmdlet @@ -168,7 +166,7 @@ public void With_Name_And_Id() // _ps.Invoke(); //} - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Object_And_Id() //{ // // Execute cmdlet @@ -178,7 +176,7 @@ public void With_Name_And_Id() // _ps.Invoke(); //} - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Name_Id_And_Object() //{ // // Execute cmdlet diff --git a/Octopus-Cmdlets.Tests/RemoveProjectTests.cs b/Octopus-Cmdlets.Tests/RemoveProjectTests.cs index e0561b8..a8fab40 100644 --- a/Octopus-Cmdlets.Tests/RemoveProjectTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveProjectTests.cs @@ -1,13 +1,12 @@ using System.Collections.Generic; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class RemoveProjectTests { private const string CmdletName = "Remove-OctoProject"; @@ -20,8 +19,7 @@ public class RemoveProjectTests Name = "Deploy" }; - [TestInitialize] - public void Init() + public RemoveProjectTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(RemoveProject)); @@ -34,7 +32,7 @@ public void Init() _projects.Add(new ProjectResource { Id = "Projects-3", Name = "Automation" }); octoRepo.Setup(o => o.Projects.Delete(It.IsAny())).Callback( - delegate (ProjectResource set) + (ProjectResource set) => { if (_projects.Contains(set)) _projects.Remove(set); @@ -51,114 +49,114 @@ public void Init() octoRepo.Setup(o => o.Projects.FindByName("Gibberish", It.IsAny(), It.IsAny())).Returns((ProjectResource)null); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - //[TestMethod] + //[Fact] //public void With_Object() //{ // // Execute cmdlet // _ps.AddCommand(CmdletName).AddParameter("InputObject", _env); // _ps.Invoke(); - // Assert.AreEqual(2, _projects.Count); + // Assert.Equal(2, _projects.Count); // Assert.IsFalse(_projects.Contains(_env)); //} - //[TestMethod] + //[Fact] //public void With_Invalid_Object() //{ // // Execute cmdlet // _ps.AddCommand(CmdletName).AddParameter("InputObject", new ProjectResource()); // _ps.Invoke(); - // Assert.AreEqual(3, _projects.Count); - // Assert.AreEqual(1, _ps.Streams.Warning.Count); - // Assert.AreEqual("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); + // Assert.Equal(3, _projects.Count); + // Assert.Equal(1, _ps.Streams.Warning.Count); + // Assert.Equal("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); //} - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", new[] { "Projects-2" }); _ps.Invoke(); - Assert.AreEqual(2, _projects.Count); - Assert.IsFalse(_projects.Contains(_project)); + Assert.Equal(2, _projects.Count); + Assert.DoesNotContain(_project, _projects); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", new[] { "Gibberish" }); _ps.Invoke(); - Assert.AreEqual(3, _projects.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("A project with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _projects.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("A project with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Test" }); _ps.Invoke(); - Assert.AreEqual(2, _projects.Count); - Assert.IsFalse(_projects.Contains(_project)); + Assert.Equal(2, _projects.Count); + Assert.DoesNotContain(_project, _projects); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Gibberish" }); _ps.Invoke(); - Assert.AreEqual(3, _projects.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("The project 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _projects.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("The project 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Valid_And_Invalid_Names() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Test", "Gibberish" }); _ps.Invoke(); - Assert.AreEqual(2, _projects.Count); - Assert.IsFalse(_projects.Contains(_project)); + Assert.Equal(2, _projects.Count); + Assert.DoesNotContain(_project, _projects); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument(new[] { "Test" }); _ps.Invoke(); - Assert.AreEqual(2, _projects.Count); - Assert.IsFalse(_projects.Contains(_project)); + Assert.Equal(2, _projects.Count); + Assert.DoesNotContain(_project, _projects); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Name_And_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Gibberish").AddParameter("Id", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Name_And_Object() //{ // // Execute cmdlet @@ -168,7 +166,7 @@ public void With_Name_And_Id() // _ps.Invoke(); //} - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Object_And_Id() //{ // // Execute cmdlet @@ -178,7 +176,7 @@ public void With_Name_And_Id() // _ps.Invoke(); //} - //[TestMethod, ExpectedException(typeof(ParameterBindingException))] + //[Fact, ExpectedException(typeof(ParameterBindingException))] //public void With_Name_Id_And_Object() //{ // // Execute cmdlet diff --git a/Octopus-Cmdlets.Tests/RemoveVariableSetTests.cs b/Octopus-Cmdlets.Tests/RemoveVariableSetTests.cs index b9c901d..e152db9 100644 --- a/Octopus-Cmdlets.Tests/RemoveVariableSetTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveVariableSetTests.cs @@ -2,14 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Moq; using Octopus.Client.Exceptions; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class RemoveVariableSetTests { private const string CmdletName = "Remove-OctoVariableSet"; @@ -22,8 +21,7 @@ public class RemoveVariableSetTests Name = "Azure" }; - [TestInitialize] - public void Init() + public RemoveVariableSetTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (RemoveVariableSet)); @@ -35,7 +33,8 @@ public void Init() _sets.Add(_set); _sets.Add(new LibraryVariableSetResource {Id = "LibraryVariableSets-3", Name = "Service Endpoints"}); - octoRepo.Setup(o => o.LibraryVariableSets.Delete(It.IsAny())).Callback(delegate (LibraryVariableSetResource set) + octoRepo.Setup(o => o.LibraryVariableSets.Delete(It.IsAny())).Callback( + (LibraryVariableSetResource set) => { if (_sets.Contains(set)) _sets.Remove(set); @@ -55,123 +54,123 @@ public void Init() (from l in _sets where f(l) select l).FirstOrDefault()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Object() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("InputObject", _set); _ps.Invoke(); - Assert.AreEqual(2, _sets.Count); - Assert.IsFalse(_sets.Contains(_set)); + Assert.Equal(2, _sets.Count); + Assert.DoesNotContain(_set, _sets); } - [TestMethod] + [Fact] public void With_Invalid_Object() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("InputObject", new LibraryVariableSetResource()); _ps.Invoke(); - Assert.AreEqual(3, _sets.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _sets.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "LibraryVariableSets-2"); _ps.Invoke(); - Assert.AreEqual(2, _sets.Count); - Assert.IsFalse(_sets.Contains(_set)); + Assert.Equal(2, _sets.Count); + Assert.DoesNotContain(_set, _sets); } - [TestMethod] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); _ps.Invoke(); - Assert.AreEqual(3, _sets.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("The library variable set with id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _sets.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("The library variable set with id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Azure"); _ps.Invoke(); - Assert.AreEqual(2, _sets.Count); - Assert.IsFalse(_sets.Contains(_set)); + Assert.Equal(2, _sets.Count); + Assert.DoesNotContain(_set, _sets); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Gibberish"); _ps.Invoke(); - Assert.AreEqual(3, _sets.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("The library variable set 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _sets.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("The library variable set 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Azure"); _ps.Invoke(); - Assert.AreEqual(2, _sets.Count); - Assert.IsFalse(_sets.Contains(_set)); + Assert.Equal(2, _sets.Count); + Assert.DoesNotContain(_set, _sets); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Name_And_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Name", "Gibberish").AddParameter("Id", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Name_And_Object() { // Execute cmdlet _ps.AddCommand(CmdletName) .AddParameter("Name", "Gibberish") .AddParameter("InputObject", new LibraryVariableSetResource()); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Object_And_Id() { // Execute cmdlet _ps.AddCommand(CmdletName) .AddParameter("Id", "Gibberish") .AddParameter("InputObject", new LibraryVariableSetResource()); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Name_Id_And_Object() { // Execute cmdlet @@ -179,7 +178,7 @@ public void With_Name_Id_And_Object() .AddParameter("Name", "Gibberish") .AddParameter("Id", "Gibberish") .AddParameter("InputObject", new LibraryVariableSetResource()); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/RemoveVariableTests.cs b/Octopus-Cmdlets.Tests/RemoveVariableTests.cs index 687e2b8..a0b6484 100644 --- a/Octopus-Cmdlets.Tests/RemoveVariableTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveVariableTests.cs @@ -1,10 +1,9 @@ using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Octopus.Client.Model; namespace Octopus_Cmdlets.Tests { - [TestClass] public class RemoveVariableTests { private const string CmdletName = "Remove-OctoVariableSet"; @@ -17,8 +16,7 @@ public class RemoveVariableTests private VariableResource _variable; - [TestInitialize] - public void Init() + public RemoveVariableTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (RemoveVariable)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -37,95 +35,95 @@ public void Init() octoRepo.Setup(o => o.VariableSets.Get("variablesets-1")).Returns(_variableSet); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Object() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("InputObject", _variable); _ps.Invoke(); - Assert.AreEqual(2, _variableSet.Variables.Count); - Assert.IsFalse(_variableSet.Variables.Contains(_variable)); + Assert.Equal(2, _variableSet.Variables.Count); + Assert.False(_variableSet.Variables.Contains(_variable)); } - [TestMethod] + [Fact] public void With_Invalid_Object() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("InputObject", new VariableResource()); _ps.Invoke(); - Assert.AreEqual(3, _variableSet.Variables.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("Variable '' in project 'Octopus' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _variableSet.Variables.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("Variable '' in project 'Octopus' does not exist.", _ps.Streams.Warning[0].ToString()); } - //[TestMethod] + //[Fact] //public void With_Id() //{ // // Execute cmdlet // _ps.AddCommand(CmdletName).AddParameter("Id", "LibraryVariableSets-2"); // _ps.Invoke(); - // Assert.AreEqual(2, _variableSet.Variables.Count); + // Assert.Equal(2, _variableSet.Variables.Count); // Assert.IsFalse(_variableSet.Variables.Contains(_set)); //} - //[TestMethod] + //[Fact] //public void With_Invalid_Id() //{ // // Execute cmdlet // _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); // _ps.Invoke(); - // Assert.AreEqual(3, _variableSet.Variables.Count); - // Assert.AreEqual(1, _ps.Streams.Warning.Count); - // Assert.AreEqual("The library variable set with id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); + // Assert.Equal(3, _variableSet.Variables.Count); + // Assert.Equal(1, _ps.Streams.Warning.Count); + // Assert.Equal("The library variable set with id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); //} - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Name", "Azure"); _ps.Invoke(); - Assert.AreEqual(2, _variableSet.Variables.Count); - Assert.IsFalse(_variableSet.Variables.Contains(_variable)); + Assert.Equal(2, _variableSet.Variables.Count); + Assert.False(_variableSet.Variables.Contains(_variable)); } - [TestMethod] + [Fact] public void With_Invalid_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Name", "Gibberish"); _ps.Invoke(); - Assert.AreEqual(3, _variableSet.Variables.Count); - Assert.AreEqual(1, _ps.Streams.Warning.Count); - Assert.AreEqual("Variable 'Gibberish' in project 'Octopus' does not exist.", _ps.Streams.Warning[0].ToString()); + Assert.Equal(3, _variableSet.Variables.Count); + Assert.Single(_ps.Streams.Warning); + Assert.Equal("Variable 'Gibberish' in project 'Octopus' does not exist.", _ps.Streams.Warning[0].ToString()); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Azure"); _ps.Invoke(); - Assert.AreEqual(2, _variableSet.Variables.Count); - Assert.IsFalse(_variableSet.Variables.Contains(_variable)); + Assert.Equal(2, _variableSet.Variables.Count); + Assert.False(_variableSet.Variables.Contains(_variable)); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Name_And_Object() { // Execute cmdlet @@ -133,7 +131,7 @@ public void With_Name_And_Object() .AddParameter("Project", "Gibberish") .AddParameter("Name", "Gibberish") .AddParameter("InputObject", new VariableResource()); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets.Tests/UpdateLibraryVariableTests.cs b/Octopus-Cmdlets.Tests/UpdateLibraryVariableTests.cs index 050d199..60b3269 100644 --- a/Octopus-Cmdlets.Tests/UpdateLibraryVariableTests.cs +++ b/Octopus-Cmdlets.Tests/UpdateLibraryVariableTests.cs @@ -2,13 +2,12 @@ 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 UpdateLibraryVariableTests { private const string CmdletName = "Update-OctoLibraryVariable"; @@ -16,8 +15,7 @@ public class UpdateLibraryVariableTests private readonly List _sets = new List(); private readonly VariableSetResource _variableSet = new VariableSetResource(); - [TestInitialize] - public void Init() + public UpdateLibraryVariableTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(UpdateLibraryVariable)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -77,77 +75,77 @@ where m.Name.Equals(n, StringComparison.InvariantCultureIgnoreCase) select m).ToList()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "ConnectionStrings").AddParameter("Name", "Test"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "variables-1").AddParameter("Name", "Test"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "ConnectionStrings").AddParameter("Id", "variables-1").AddParameter("Name", "NewName"); _ps.Invoke(); - Assert.AreEqual("NewName", _variableSet.Variables[0].Name); + Assert.Equal("NewName", _variableSet.Variables[0].Name); } - [TestMethod] + [Fact] public void With_Sensitive() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "ConnectionStrings").AddParameter("Id", "variables-1").AddParameter("Sensitive", true); _ps.Invoke(); - Assert.AreEqual(true, _variableSet.Variables[0].IsSensitive); + Assert.True(_variableSet.Variables[0].IsSensitive); } - [TestMethod] + [Fact] public void With_Environments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "ConnectionStrings").AddParameter("Id", "variables-1").AddParameter("Environment", "TEST"); _ps.Invoke(); - Assert.AreEqual("environments-2", _variableSet.Variables[0].Scope[ScopeField.Environment].First()); + Assert.Equal("environments-2", _variableSet.Variables[0].Scope[ScopeField.Environment].First()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "Gibberish").AddParameter("Id", "variables-1"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "ConnectionStrings").AddParameter("Id", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_All() { // Execute cmdlet @@ -162,16 +160,16 @@ public void With_All() .AddParameter("Sensitive", true); _ps.Invoke(); - Assert.AreEqual(1, _variableSet.Variables.Count); - Assert.AreEqual("NewName", _variableSet.Variables[0].Name); - Assert.AreEqual("New Test Value", _variableSet.Variables[0].Value); - Assert.AreEqual(true, _variableSet.Variables[0].IsSensitive); - Assert.AreEqual("environments-2", _variableSet.Variables[0].Scope[ScopeField.Environment].First()); - Assert.AreEqual("Web", _variableSet.Variables[0].Scope[ScopeField.Role].First()); - Assert.AreEqual("machines-2", _variableSet.Variables[0].Scope[ScopeField.Machine].First()); + Assert.Equal(1, _variableSet.Variables.Count); + Assert.Equal("NewName", _variableSet.Variables[0].Name); + Assert.Equal("New Test Value", _variableSet.Variables[0].Value); + Assert.True(_variableSet.Variables[0].IsSensitive); + Assert.Equal("environments-2", _variableSet.Variables[0].Scope[ScopeField.Environment].First()); + Assert.Equal("Web", _variableSet.Variables[0].Scope[ScopeField.Role].First()); + Assert.Equal("machines-2", _variableSet.Variables[0].Scope[ScopeField.Machine].First()); } - //[TestMethod] + //[Fact] //public void With_Object() //{ // // Execute cmdlet @@ -180,8 +178,8 @@ public void With_All() // .AddParameter("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); //} } } diff --git a/Octopus-Cmdlets.Tests/UpdateVariableTests.cs b/Octopus-Cmdlets.Tests/UpdateVariableTests.cs index 771396f..c6be7a9 100644 --- a/Octopus-Cmdlets.Tests/UpdateVariableTests.cs +++ b/Octopus-Cmdlets.Tests/UpdateVariableTests.cs @@ -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 UpdateVariableTests { private const string CmdletName = "Update-OctoVariable"; private PowerShell _ps; private readonly VariableSetResource _variableSet = new VariableSetResource(); - [TestInitialize] - public void Init() + public UpdateVariableTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(UpdateVariable)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); @@ -69,77 +67,77 @@ where m.Name.Equals(n, StringComparison.InvariantCultureIgnoreCase) select m).ToList()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Name", "Test"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Id", "variables-1").AddParameter("Name", "Test"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Id", "variables-1").AddParameter("Name", "NewName"); _ps.Invoke(); - Assert.AreEqual("NewName", _variableSet.Variables[0].Name); + Assert.Equal("NewName", _variableSet.Variables[0].Name); } - [TestMethod] + [Fact] public void With_Sensitive() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Id", "variables-1").AddParameter("Sensitive", true); _ps.Invoke(); - Assert.AreEqual(true, _variableSet.Variables[0].IsSensitive); + Assert.True(_variableSet.Variables[0].IsSensitive); } - [TestMethod] + [Fact] public void With_Environments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Id", "variables-1").AddParameter("Environment", "TEST"); _ps.Invoke(); - Assert.AreEqual("environments-2", _variableSet.Variables[0].Scope[ScopeField.Environment].First()); + Assert.Equal("environments-2", _variableSet.Variables[0].Scope[ScopeField.Environment].First()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish").AddParameter("Id", "variables-1"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Id() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Id", "Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_All() { // Execute cmdlet @@ -154,16 +152,16 @@ public void With_All() .AddParameter("Sensitive", true); _ps.Invoke(); - Assert.AreEqual(1, _variableSet.Variables.Count); - Assert.AreEqual("NewName", _variableSet.Variables[0].Name); - Assert.AreEqual("New Test Value", _variableSet.Variables[0].Value); - Assert.AreEqual(true, _variableSet.Variables[0].IsSensitive); - Assert.AreEqual("environments-2", _variableSet.Variables[0].Scope[ScopeField.Environment].First()); - Assert.AreEqual("Web", _variableSet.Variables[0].Scope[ScopeField.Role].First()); - Assert.AreEqual("machines-2", _variableSet.Variables[0].Scope[ScopeField.Machine].First()); + Assert.Equal(1, _variableSet.Variables.Count); + Assert.Equal("NewName", _variableSet.Variables[0].Name); + Assert.Equal("New Test Value", _variableSet.Variables[0].Value); + Assert.True(_variableSet.Variables[0].IsSensitive); + Assert.Equal("environments-2", _variableSet.Variables[0].Scope[ScopeField.Environment].First()); + Assert.Equal("Web", _variableSet.Variables[0].Scope[ScopeField.Role].First()); + Assert.Equal("machines-2", _variableSet.Variables[0].Scope[ScopeField.Machine].First()); } - //[TestMethod] + //[Fact] //public void With_Object() //{ // // Execute cmdlet @@ -172,8 +170,8 @@ public void With_All() // .AddParameter("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); //} } } diff --git a/Octopus-Cmdlets.Tests/UseVariableSetTests.cs b/Octopus-Cmdlets.Tests/UseVariableSetTests.cs index ffc4185..4de21d9 100644 --- a/Octopus-Cmdlets.Tests/UseVariableSetTests.cs +++ b/Octopus-Cmdlets.Tests/UseVariableSetTests.cs @@ -1,21 +1,19 @@ 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 UseVariableSetTests { private const string CmdletName = "Use-OctoVariableSet"; private PowerShell _ps; private ProjectResource _projectResource; - [TestInitialize] - public void Init() + public UseVariableSetTests() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(UseVariableSet)); @@ -39,46 +37,46 @@ public void Init() octoRepo.Setup(o => o.LibraryVariableSets.FindAll(null, null)).Returns(libraryResources); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish").AddArgument("ConnectionStrings"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_Name_Parameter() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddParameter("Name", "ConnectionStrings"); _ps.Invoke(); - Assert.AreEqual("LibraryVariableSets-1", _projectResource.IncludedLibraryVariableSetIds[0]); + Assert.Equal("LibraryVariableSets-1", _projectResource.IncludedLibraryVariableSetIds[0]); } - [TestMethod, ExpectedException(typeof(CmdletInvocationException))] + [Fact] public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Gibberish"); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } } } diff --git a/Octopus-Cmdlets/AddEnvironment.cs b/Octopus-Cmdlets/AddEnvironment.cs index debeca5..99cc94b 100644 --- a/Octopus-Cmdlets/AddEnvironment.cs +++ b/Octopus-Cmdlets/AddEnvironment.cs @@ -77,7 +77,7 @@ protected override void ProcessRecord() { Name = Name, Description = Description - }); + }, null); } } } diff --git a/Octopus-Cmdlets/AddFeed.cs b/Octopus-Cmdlets/AddNugetFeed.cs similarity index 62% rename from Octopus-Cmdlets/AddFeed.cs rename to Octopus-Cmdlets/AddNugetFeed.cs index 7c5f5e5..506cc5c 100644 --- a/Octopus-Cmdlets/AddFeed.cs +++ b/Octopus-Cmdlets/AddNugetFeed.cs @@ -1,5 +1,5 @@ #region License -// Copyright 2014 Colin Svingen +// Copyright 2018 Colin Svingen // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,22 +22,22 @@ namespace Octopus_Cmdlets { /// /// Add a new external feed to the Octopus Deploy server. - /// The Add-OctoFeed cmdlet adds a external feed to the Octopus Deploy server. + /// The Add-OctoNugetFeed cmdlet adds a external feed to the Octopus Deploy server. /// /// - /// PS C:\>add-octofeed DEV + /// PS C:\>add-octonugetfeed DEV /// /// Add a new feed named 'DEV'. /// /// /// - /// PS C:\>add-octofeed -Name DEV -Uri "\\test" + /// PS C:\>add-octonugetfeed -Name DEV -FeedUri "\\test" /// /// Add a new feed named 'DEV' pointing to the path '\\test'. /// /// - [Cmdlet(VerbsCommon.Add, "Feed")] - public class AddFeed : PSCmdlet + [Cmdlet(VerbsCommon.Add, "NugetFeed")] + public class AddNugetFeed : PSCmdlet { /// /// The name of the feed to create. @@ -56,7 +56,22 @@ public class AddFeed : PSCmdlet Position = 1, Mandatory = false, ValueFromPipelineByPropertyName = true)] - public string Uri { get; set; } + public string FeedUri { get; set; } + + [Parameter] + public string Username { get; set; } + + [Parameter] + public SensitiveValue Password { get; set; } + + [Parameter] + public int DownloadAttempts { get; set; } = NuGetFeedResource.DefaultDownloadAttempts; + + [Parameter] + public int DownloadRetryBackoffSeconds { get; set; } = NuGetFeedResource.DefaultDownloadRetryBackoffSeconds; + + [Parameter] + public bool EnhancedMode { get; set; } = NuGetFeedResource.DefaultEnhancedMode; private IOctopusRepository _octopus; @@ -73,10 +88,15 @@ protected override void BeginProcessing() /// protected override void ProcessRecord() { - _octopus.Feeds.Create(new FeedResource + _octopus.Feeds.Create(new NuGetFeedResource { Name = Name, - FeedUri = Uri + FeedUri = FeedUri, + Username = Username, + Password = Password, + DownloadAttempts = DownloadAttempts, + DownloadRetryBackoffSeconds = DownloadRetryBackoffSeconds, + EnhancedMode = EnhancedMode }); } } diff --git a/Octopus-Cmdlets/Octopus-Cmdlets.csproj b/Octopus-Cmdlets/Octopus-Cmdlets.csproj index 543b575..4d902fe 100644 --- a/Octopus-Cmdlets/Octopus-Cmdlets.csproj +++ b/Octopus-Cmdlets/Octopus-Cmdlets.csproj @@ -13,10 +13,8 @@ - - - - + + @@ -36,4 +34,4 @@ - \ No newline at end of file + diff --git a/README.md b/README.md index 67ae3e9..a610d9f 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ can automate while you automate. Octopus-Cmdlets is a suite of PowerShell cmdlets that enable you to simplify and automate your interactions with an Octopus Deploy server. -Automate all the things!!! - Note ==== The module name has changed from `Octopus.Cmdlets` to `Octopus-Cmdlets`. Please @@ -22,13 +20,6 @@ Powershell Gallery (preferred method) Install-Module -Name Octopus-Cmdlets -PsGet ------ -If you don't already have PsGet, install it from https://github.com/psget/psget - -To install Octopus-Cmdlets run - - install-module Octopus-Cmdlets Binary Archive -------------- @@ -66,6 +57,6 @@ description of the individual cmdlets, or type `help [cmdlet]` from PowerShell. Licence ======= -Copyright 2014 Colin Svingen +Copyright 2018 Colin Svingen Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) diff --git a/Version.cs b/Version.cs index f1f29d8..4ab3645 100644 --- a/Version.cs +++ b/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("0.4.5.0")] -[assembly: AssemblyFileVersion("0.4.5.0")] \ No newline at end of file +[assembly: AssemblyVersion("0.5.0.0")] +[assembly: AssemblyFileVersion("0.5.0.0")] \ No newline at end of file diff --git a/default.ps1 b/psakefile.ps1 similarity index 100% rename from default.ps1 rename to psakefile.ps1