From eb19154a120bb9edd312834e6aed866992ff661d Mon Sep 17 00:00:00 2001 From: Colin Svingen Date: Tue, 25 Sep 2018 14:56:17 -0400 Subject: [PATCH 1/3] Moves to latest client lib and tests to xunit --- Octopus-Cmdlets.Tests/AddEnvironmentTests.cs | 38 +++--- Octopus-Cmdlets.Tests/AddFeedTests.cs | 89 ------------ .../AddLibraryVariableTests.cs | 34 +++-- Octopus-Cmdlets.Tests/AddMachineTests.cs | 68 +++++---- Octopus-Cmdlets.Tests/AddNugetFeedTests.cs | 87 ++++++++++++ Octopus-Cmdlets.Tests/AddProjectGroupTests.cs | 36 +++-- Octopus-Cmdlets.Tests/AddProjectTests.cs | 68 +++++---- Octopus-Cmdlets.Tests/AddVariableSetTests.cs | 38 +++--- Octopus-Cmdlets.Tests/AddVariableTests.cs | 36 +++-- Octopus-Cmdlets.Tests/ConnectServerTests.cs | 9 +- Octopus-Cmdlets.Tests/CopyChannelTests.cs | 129 +++++++++--------- Octopus-Cmdlets.Tests/CopyProjectTests.cs | 86 ++++++------ Octopus-Cmdlets.Tests/CopyStepTests.cs | 81 ++++++----- Octopus-Cmdlets.Tests/GetActionTests.cs | 44 +++--- .../GetDeploymentProcessTests.cs | 34 +++-- Octopus-Cmdlets.Tests/GetDeploymentTests.cs | 43 +++--- Octopus-Cmdlets.Tests/GetEnvironmentTests.cs | 44 +++--- Octopus-Cmdlets.Tests/GetExternalFeedTests.cs | 24 ++-- Octopus-Cmdlets.Tests/GetMachineRoleTests.cs | 20 ++- Octopus-Cmdlets.Tests/GetMachineTests.cs | 40 +++--- Octopus-Cmdlets.Tests/GetProjectGroupTests.cs | 30 ++-- Octopus-Cmdlets.Tests/GetProjectTests.cs | 58 ++++---- Octopus-Cmdlets.Tests/GetReleaseTests.cs | 47 ++++--- Octopus-Cmdlets.Tests/GetStepTests.cs | 64 +++++---- Octopus-Cmdlets.Tests/GetVariableSetTests.cs | 40 +++--- Octopus-Cmdlets.Tests/GetVariableTests.cs | 53 ++++--- .../Octopus-Cmdlets.Tests.csproj | 15 +- .../RemoveEnvironmentTests.cs | 72 +++++----- .../RemoveProjectGroupTests.cs | 72 +++++----- Octopus-Cmdlets.Tests/RemoveProjectTests.cs | 72 +++++----- .../RemoveVariableSetTests.cs | 74 +++++----- Octopus-Cmdlets.Tests/RemoveVariableTests.cs | 60 ++++---- .../UpdateLibraryVariableTests.cs | 60 ++++---- Octopus-Cmdlets.Tests/UpdateVariableTests.cs | 60 ++++---- Octopus-Cmdlets.Tests/UseVariableSetTests.cs | 26 ++-- .../{AddFeed.cs => AddNugetFeed.cs} | 46 ++++--- Octopus-Cmdlets/Octopus-Cmdlets.csproj | 8 +- default.ps1 => psakefile.ps1 | 0 38 files changed, 924 insertions(+), 981 deletions(-) delete mode 100644 Octopus-Cmdlets.Tests/AddFeedTests.cs create mode 100644 Octopus-Cmdlets.Tests/AddNugetFeedTests.cs rename Octopus-Cmdlets/{AddFeed.cs => AddNugetFeed.cs} (59%) rename default.ps1 => psakefile.ps1 (100%) diff --git a/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs b/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs index 878d2c4..f3ac41c 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,7 +21,7 @@ public void Init() _envs.Clear(); var envRepo = new Mock(); - envRepo.Setup(e => e.Create(It.IsAny())) + envRepo.Setup(e => e.Create(It.IsAny(), null)) .Returns(delegate(EnvironmentResource e) { _envs.Add(e); @@ -33,26 +31,26 @@ 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.Invoke(); - Assert.AreEqual(1, _envs.Count); - Assert.AreEqual("Octopus_Dev", _envs[0].Name); + Assert.Equal(1, _envs.Count); + 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(); + 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", "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.Equal(1, _envs.Count); + 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 +73,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.Equal(1, _envs.Count); + 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/AddFeedTests.cs b/Octopus-Cmdlets.Tests/AddFeedTests.cs deleted file mode 100644 index edba40a..0000000 --- a/Octopus-Cmdlets.Tests/AddFeedTests.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System.Collections.Generic; -using System.Management.Automation; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Octopus.Client.Model; -using Octopus.Client.Repositories; - -namespace Octopus_Cmdlets.Tests -{ - [TestClass] - public class AddFeedTests - { - private const string CmdletName = "Add-OctoFeed"; - private PowerShell _ps; - private readonly List _feeds = new List(); - - [TestInitialize] - public void Init() - { - _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddFeed)); - 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) - { - _feeds.Add(e); - return e; - }); - - octoRepo.Setup(o => o.Feeds).Returns(feedRepo.Object); - } - - [TestMethod] - 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); - } - - [TestMethod, ExpectedException(typeof(ParameterBindingException))] - public void With_Uri() - { - // Execute cmdlet - _ps.AddCommand(CmdletName).AddParameter("Uri", "\\test"); - _ps.Invoke(); - } - - [TestMethod] - public void With_Name_And_Description() - { - // Execute cmdlet - _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev").AddParameter("Uri", "\\test"); - _ps.Invoke(); - - Assert.AreEqual(1, _feeds.Count); - Assert.AreEqual("Octopus_Dev", _feeds[0].Name); - Assert.AreEqual("\\test", _feeds[0].FeedUri); - } - - [TestMethod] - public void With_Arguements() - { - // Execute cmdlet - _ps.AddCommand(CmdletName) - .AddArgument("Octopus_Dev") - .AddArgument("\\test"); - _ps.Invoke(); - - Assert.AreEqual(1, _feeds.Count); - Assert.AreEqual("Octopus_Dev", _feeds[0].Name); - Assert.AreEqual("\\test", _feeds[0].FeedUri); - } - - [TestMethod, ExpectedException(typeof(ParameterBindingException))] - public void No_Arguments() - { - // Execute cmdlet - _ps.AddCommand(CmdletName); - _ps.Invoke(); - } - } -} diff --git a/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs b/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs index 060e1aa..11021e5 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,34 +50,34 @@ 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.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(); + Assert.Throws(() => _ps.Invoke()); } - [TestMethod] + [Fact] public void With_All() { // Execute cmdlet @@ -93,12 +91,12 @@ 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); } - [TestMethod] + [Fact] public void With_Object() { // Execute cmdlet @@ -107,8 +105,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/AddMachineTests.cs b/Octopus-Cmdlets.Tests/AddMachineTests.cs index a71dc02..8c382b8 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,7 +28,7 @@ public void Init() _machines.Clear(); var machineRepo = new Mock(); - machineRepo.Setup(m => m.Create(It.IsAny())) + machineRepo.Setup(m => m.Create(It.IsAny(), null)) .Returns(delegate(MachineResource m) { _machines.Add(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.Equal(1, _machines.Count); + 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.Equal(1, _machines.Count); + 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/AddNugetFeedTests.cs b/Octopus-Cmdlets.Tests/AddNugetFeedTests.cs new file mode 100644 index 0000000..e8bba32 --- /dev/null +++ b/Octopus-Cmdlets.Tests/AddNugetFeedTests.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; +using System.Management.Automation; +using Xunit; +using Moq; +using Octopus.Client.Model; +using Octopus.Client.Repositories; + +namespace Octopus_Cmdlets.Tests +{ + public class AddNugetFeedTests + { + private const string CmdletName = "Add-OctoNugetFeed"; + private PowerShell _ps; + private readonly List _feeds = new List(); + + public AddNugetFeedTests() + { + _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(), null)) + .Returns(delegate(FeedResource e) + { + _feeds.Add(e); + return e; + }); + + octoRepo.Setup(o => o.Feeds).Returns(feedRepo.Object); + } + + [Fact] + public void With_Name() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev"); + _ps.Invoke(); + + Assert.Equal(1, _feeds.Count); + Assert.Equal("Octopus_Dev", _feeds[0].Name); + } + + [Fact] + public void With_Uri() + { + // Execute cmdlet + _ps.AddCommand(CmdletName).AddParameter("Uri", "\\test"); + Assert.Throws(() => _ps.Invoke()); + } + + //[Fact] + //public void With_Name_And_Description() + //{ + // // Execute cmdlet + // _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev").AddParameter("Uri", "\\test"); + // _ps.Invoke(); + + // Assert.Equal(1, _feeds.Count); + // Assert.Equal("Octopus_Dev", _feeds[0].Name); + // Assert.Equal("\\test", _feeds[0].FeedUri); + //} + + //[Fact] + //public void With_Arguements() + //{ + // // Execute cmdlet + // _ps.AddCommand(CmdletName) + // .AddArgument("Octopus_Dev") + // .AddArgument("\\test"); + // _ps.Invoke(); + + // Assert.Equal(1, _feeds.Count); + // Assert.Equal("Octopus_Dev", _feeds[0].Name); + // Assert.Equal("\\test", _feeds[0].FeedUri); + //} + + [Fact] + public void No_Arguments() + { + // Execute cmdlet + _ps.AddCommand(CmdletName); + Assert.Throws(() => _ps.Invoke()); + } + } +} diff --git a/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs b/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs index 12c6c50..dfc7d9b 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,7 +21,7 @@ public void Init() _groups.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny())) + repo.Setup(e => e.Create(It.IsAny(), null)) .Returns(delegate(ProjectGroupResource p) { _groups.Add(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.Equal(1, _groups.Count); + 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.Equal(1, _groups.Count); + 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.Equal(1, _groups.Count); + 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..95e9f41 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,7 +32,7 @@ public void Init() _projects.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny())) + repo.Setup(e => e.Create(It.IsAny(), null)) .Returns(delegate(ProjectResource p) { _projects.Add(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.Equal(1, _projects.Count); + 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.Equal(1, _projects.Count); + 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.Equal(1, _projects.Count); + 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.Equal(1, _projects.Count); + 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..2d90344 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,7 +21,7 @@ public void Init() _sets.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny())) + repo.Setup(e => e.Create(It.IsAny(), null)) .Returns(delegate(LibraryVariableSetResource e) { _sets.Add(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.Equal(1, _sets.Count); + 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.Equal(1, _sets.Count); + 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.Equal(1, _sets.Count); + 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..a52c6a2 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..6a1701f 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,37 +67,37 @@ 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())) + .Setup(o => o.Channels.Create(It.IsAny(), null)) .Callback(ch => createdChannel = ch) .Returns(ch => ch); @@ -108,50 +107,50 @@ 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())) + .Setup(o => o.Channels.Create(It.IsAny(), null)) .Callback(ch => createdChannel = ch) .Returns(ch => ch); @@ -162,30 +161,30 @@ 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())) + .Setup(o => o.Channels.Create(It.IsAny(), null)) .Callback(ch => createdChannel = ch) .Returns(ch => ch); @@ -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..f39321d 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,7 +47,7 @@ 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( + octoRepo.Setup(o => o.Projects.Create(It.IsAny(), null)).Returns( delegate(ProjectResource p) { p.VariableSetId = "variablesets-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.Equal(0, variable.Scope[ScopeField.Action].Count); + 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.Equal(1, steps.Actions.Count); + 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..fef3166 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.Equal(1, actions.Count); + 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.Equal(1, actions.Count); + 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.Equal(0, actions.Count); } - [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.Equal(1, actions.Count); + 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.Equal(0, actions.Count); } } } diff --git a/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs b/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs index 7026da0..9cf0887 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.Equal(1, projects.Count); } - [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.Equal(0, projects.Count); } - [TestMethod] + [Fact] public void With_ProjectName() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus"); var projects = _ps.Invoke(); - Assert.AreEqual(1, projects.Count); + Assert.Equal(1, projects.Count); } - [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.Equal(0, projects.Count); } - [TestMethod] + [Fact] public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("DeploymentProcesses-1"); var projects = _ps.Invoke(); - Assert.AreEqual(1, projects.Count); + Assert.Equal(1, projects.Count); } - [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..455fee5 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.Equal(1, deployments.Count); } - [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.Equal(0, deployments.Count); } - [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.Equal(1, deployments.Count); } - [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.Equal(1, deployments.Count); } - [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..c722fac 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.Equal(1, environments.Count); + 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.Equal(0, environments.Count); } - [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.Equal(1, environments.Count); + 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.Equal(0, environments.Count); } - [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.Equal(1, environments.Count); + 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.Equal(0, environments.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/GetExternalFeedTests.cs b/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs index 8b64b34..d70e56b 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.Equal(1, feeds.Count); + 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.Equal(0, feeds.Count); } } } diff --git a/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs b/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs index b2f1884..13b454c 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.Equal(1, results.Count); + 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.Equal(0, results.Count); } } } diff --git a/Octopus-Cmdlets.Tests/GetMachineTests.cs b/Octopus-Cmdlets.Tests/GetMachineTests.cs index 39c3321..09e45c0 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.Equal(1, machines.Count); + 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.Equal(0, machines.Count); } - [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.Equal(1, machines.Count); + 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.Equal(0, machines.Count); } - [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.Equal(1, machines.Count); + Assert.Equal("dbserver-01", machines[0].Name); } } } diff --git a/Octopus-Cmdlets.Tests/GetProjectGroupTests.cs b/Octopus-Cmdlets.Tests/GetProjectGroupTests.cs index e4a8b80..f2f6325 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)); @@ -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.Equal(1, groups.Count); + 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.Equal(0, groups.Count); } - [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.Equal(1, groups.Count); + 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.Equal(0, groups.Count); } } } diff --git a/Octopus-Cmdlets.Tests/GetProjectTests.cs b/Octopus-Cmdlets.Tests/GetProjectTests.cs index d6aee8d..79772e8 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.Equal(1, projects.Count); + 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.Equal(0, projects.Count); } - [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.Equal(0, projects.Count); } - [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.Equal(1, projects.Count); + 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.Equal(0, projects.Count); } - [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..2bd3cad 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.Equal(1, releases.Count); + 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.Equal(0, releases.Count); } - [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.Equal(1, releases.Count); + 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.Equal(0, releases.Count); } } } diff --git a/Octopus-Cmdlets.Tests/GetStepTests.cs b/Octopus-Cmdlets.Tests/GetStepTests.cs index 7202979..86689c3 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,7 +44,7 @@ public void Init() .Throws(new OctopusResourceNotFoundException("Not Found")); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void No_Arguments() { // Execute cmdlet @@ -54,92 +52,92 @@ public void No_Arguments() _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.Equal(0, steps.Count); } - [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.Equal(0, steps.Count); } - [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.Equal(0, steps.Count); } - [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.Equal(1, steps.Count); + 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.Equal(1, steps.Count); + Assert.Equal("Test Step 2", steps[0].Name); } - [TestMethod] + [Fact] public void With_ProcessIdAndName() { // Execute cmdlet @@ -148,24 +146,24 @@ 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.Equal(1, steps.Count); + 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); + Assert.Equal(1, steps.Count); + Assert.Equal("Test Step 2", steps[0].Name); } - [TestMethod, ExpectedException(typeof(ParameterBindingException))] + [Fact] public void With_KitchenSink() { // Execute cmdlet diff --git a/Octopus-Cmdlets.Tests/GetVariableSetTests.cs b/Octopus-Cmdlets.Tests/GetVariableSetTests.cs index c8ed176..494fbd9 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.Equal(1, variables.Count); + 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.Equal(0, variables.Count); } - [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.Equal(1, variables.Count); + 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.Equal(1, variables.Count); + 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.Equal(0, variables.Count); } - [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..1ffc46e 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.Equal(1, variables.Count); + 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.Equal(1, _ps.Streams.Warning.Count); + 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.Equal(1, variables.Count); + 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.Equal(1, variables.Count); + 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.Equal(1, _ps.Streams.Warning.Count); + 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..798b59f 100644 --- a/Octopus-Cmdlets.Tests/Octopus-Cmdlets.Tests.csproj +++ b/Octopus-Cmdlets.Tests/Octopus-Cmdlets.Tests.csproj @@ -13,17 +13,12 @@ - - - - - - - - + + + - - + + diff --git a/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs b/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs index 226a157..17da239 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)); @@ -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.False(_envs.Contains(_env)); } - [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.Equal(1, _ps.Streams.Warning.Count); + 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.False(_envs.Contains(_env)); } - [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.Equal(1, _ps.Streams.Warning.Count); + 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.False(_envs.Contains(_env)); } - [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.False(_envs.Contains(_env)); } - [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..fd76a73 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)); @@ -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.False(_groups.Contains(_group)); } - [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.Equal(1, _ps.Streams.Warning.Count); + 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.False(_groups.Contains(_group)); } - [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.Equal(1, _ps.Streams.Warning.Count); + 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.False(_groups.Contains(_group)); } - [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.False(_groups.Contains(_group)); } - [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..80b92bc 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)); @@ -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.False(_projects.Contains(_project)); } - [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.Equal(1, _ps.Streams.Warning.Count); + 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.False(_projects.Contains(_project)); } - [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.Equal(1, _ps.Streams.Warning.Count); + 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.False(_projects.Contains(_project)); } - [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.False(_projects.Contains(_project)); } - [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..7771a9d 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)); @@ -55,123 +53,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.False(_sets.Contains(_set)); } - [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.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", "LibraryVariableSets-2"); _ps.Invoke(); - Assert.AreEqual(2, _sets.Count); - Assert.IsFalse(_sets.Contains(_set)); + Assert.Equal(2, _sets.Count); + Assert.False(_sets.Contains(_set)); } - [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.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("Name", "Azure"); _ps.Invoke(); - Assert.AreEqual(2, _sets.Count); - Assert.IsFalse(_sets.Contains(_set)); + Assert.Equal(2, _sets.Count); + Assert.False(_sets.Contains(_set)); } - [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.Equal(1, _ps.Streams.Warning.Count); + 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.False(_sets.Contains(_set)); } - [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 +177,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..5375dd9 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.Equal(1, _ps.Streams.Warning.Count); + 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.Equal(1, _ps.Streams.Warning.Count); + 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..6273f5d 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.Equal(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.Equal(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..825eba9 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.Equal(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.Equal(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..3384b3c 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/AddFeed.cs b/Octopus-Cmdlets/AddNugetFeed.cs similarity index 59% rename from Octopus-Cmdlets/AddFeed.cs rename to Octopus-Cmdlets/AddNugetFeed.cs index 7c5f5e5..1c62804 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 -Uri "\\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. @@ -47,16 +47,22 @@ public class AddFeed : PSCmdlet Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] - public string Name { get; set; } + public string FeedUri { get; set; } - /// - /// The URI of the feed to create. - /// - [Parameter( - Position = 1, - Mandatory = false, - ValueFromPipelineByPropertyName = true)] - public string Uri { 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 +79,14 @@ 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/default.ps1 b/psakefile.ps1 similarity index 100% rename from default.ps1 rename to psakefile.ps1 From d763340ecf76ae19e194eb83aa747d311d7e31b7 Mon Sep 17 00:00:00 2001 From: Colin Svingen Date: Tue, 25 Sep 2018 16:28:12 -0400 Subject: [PATCH 2/3] Cleans up unit tests --- Octopus-Cmdlets.Tests/AddEnvironmentTests.cs | 10 ++-- .../AddLibraryVariableTests.cs | 2 +- Octopus-Cmdlets.Tests/AddMachineTests.cs | 8 +-- Octopus-Cmdlets.Tests/AddNugetFeedTests.cs | 54 ++++++++++--------- Octopus-Cmdlets.Tests/AddProjectGroupTests.cs | 10 ++-- Octopus-Cmdlets.Tests/AddProjectTests.cs | 16 +++--- Octopus-Cmdlets.Tests/AddVariableSetTests.cs | 10 ++-- Octopus-Cmdlets.Tests/AddVariableTests.cs | 2 +- Octopus-Cmdlets.Tests/CopyChannelTests.cs | 22 ++++---- Octopus-Cmdlets.Tests/CopyProjectTests.cs | 12 ++--- Octopus-Cmdlets.Tests/GetActionTests.cs | 10 ++-- .../GetDeploymentProcessTests.cs | 10 ++-- Octopus-Cmdlets.Tests/GetDeploymentTests.cs | 8 +-- Octopus-Cmdlets.Tests/GetEnvironmentTests.cs | 12 ++--- Octopus-Cmdlets.Tests/GetExternalFeedTests.cs | 4 +- Octopus-Cmdlets.Tests/GetMachineRoleTests.cs | 4 +- Octopus-Cmdlets.Tests/GetMachineTests.cs | 10 ++-- Octopus-Cmdlets.Tests/GetProjectGroupTests.cs | 10 ++-- Octopus-Cmdlets.Tests/GetProjectTests.cs | 10 ++-- Octopus-Cmdlets.Tests/GetReleaseTests.cs | 10 ++-- Octopus-Cmdlets.Tests/GetStepTests.cs | 28 +++------- Octopus-Cmdlets.Tests/GetVariableSetTests.cs | 10 ++-- Octopus-Cmdlets.Tests/GetVariableTests.cs | 10 ++-- .../Octopus-Cmdlets.Tests.csproj | 7 +-- .../RemoveEnvironmentTests.cs | 14 ++--- .../RemoveProjectGroupTests.cs | 14 ++--- Octopus-Cmdlets.Tests/RemoveProjectTests.cs | 14 ++--- .../RemoveVariableSetTests.cs | 17 +++--- Octopus-Cmdlets.Tests/RemoveVariableTests.cs | 4 +- .../UpdateLibraryVariableTests.cs | 4 +- Octopus-Cmdlets.Tests/UpdateVariableTests.cs | 4 +- Octopus-Cmdlets.Tests/UseVariableSetTests.cs | 4 +- Octopus-Cmdlets/AddEnvironment.cs | 2 +- Octopus-Cmdlets/AddNugetFeed.cs | 12 ++++- README.md | 11 +--- Version.cs | 4 +- 36 files changed, 193 insertions(+), 200 deletions(-) diff --git a/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs b/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs index f3ac41c..e8d8bde 100644 --- a/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs +++ b/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs @@ -21,8 +21,8 @@ public AddEnvironmentTests() _envs.Clear(); var envRepo = new Mock(); - envRepo.Setup(e => e.Create(It.IsAny(), null)) - .Returns(delegate(EnvironmentResource e) + envRepo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((EnvironmentResource e, object o) => { _envs.Add(e); return e; @@ -38,7 +38,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev"); _ps.Invoke(); - Assert.Equal(1, _envs.Count); + Assert.Single(_envs); Assert.Equal("Octopus_Dev", _envs[0].Name); } @@ -59,7 +59,7 @@ public void With_Name_And_Description() AddParameter("Description", "Octopus Development environment"); _ps.Invoke(); - Assert.Equal(1, _envs.Count); + Assert.Single(_envs); Assert.Equal("Octopus_Dev", _envs[0].Name); Assert.Equal("Octopus Development environment", _envs[0].Description); } @@ -73,7 +73,7 @@ public void With_Arguments() .AddArgument("Octopus Development environment"); _ps.Invoke(); - Assert.Equal(1, _envs.Count); + Assert.Single(_envs); Assert.Equal("Octopus_Dev", _envs[0].Name); Assert.Equal("Octopus Development environment", _envs[0].Description); } diff --git a/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs b/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs index 11021e5..8a6e0af 100644 --- a/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs +++ b/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs @@ -74,7 +74,7 @@ public void With_Invalid_VariableSet() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("VariableSet", "Gibberish").AddParameter("Name", "Test"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] diff --git a/Octopus-Cmdlets.Tests/AddMachineTests.cs b/Octopus-Cmdlets.Tests/AddMachineTests.cs index 8c382b8..07d9a0f 100644 --- a/Octopus-Cmdlets.Tests/AddMachineTests.cs +++ b/Octopus-Cmdlets.Tests/AddMachineTests.cs @@ -28,8 +28,8 @@ public AddMachineTests() _machines.Clear(); var machineRepo = new Mock(); - machineRepo.Setup(m => m.Create(It.IsAny(), null)) - .Returns(delegate(MachineResource m) + machineRepo.Setup(m => m.Create(It.IsAny(), It.IsAny())) + .Returns((MachineResource m, object o) => { _machines.Add(m); return m; @@ -49,7 +49,7 @@ public void With_EnvName() .AddParameter("Endpoint", new ListeningTentacleEndpointResource { Uri = "https://server.domain:port/", Thumbprint = "ThisIsMyThumbprint" }); _ps.Invoke(); - Assert.Equal(1, _machines.Count); + 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); @@ -69,7 +69,7 @@ public void With_EnvId() .AddParameter("Endpoint", new ListeningTentacleEndpointResource { Uri = "https://server.domain:port/", Thumbprint = "ThisIsMyThumbprint" }); _ps.Invoke(); - Assert.Equal(1, _machines.Count); + 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); diff --git a/Octopus-Cmdlets.Tests/AddNugetFeedTests.cs b/Octopus-Cmdlets.Tests/AddNugetFeedTests.cs index e8bba32..0e63ab4 100644 --- a/Octopus-Cmdlets.Tests/AddNugetFeedTests.cs +++ b/Octopus-Cmdlets.Tests/AddNugetFeedTests.cs @@ -11,7 +11,7 @@ public class AddNugetFeedTests { private const string CmdletName = "Add-OctoNugetFeed"; private PowerShell _ps; - private readonly List _feeds = new List(); + private readonly List _feeds = new List(); public AddNugetFeedTests() { @@ -21,8 +21,8 @@ public AddNugetFeedTests() _feeds.Clear(); var feedRepo = new Mock(); - feedRepo.Setup(e => e.Create(It.IsAny(), null)) - .Returns(delegate(FeedResource e) + feedRepo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((NuGetFeedResource e, object o) => { _feeds.Add(e); return e; @@ -38,7 +38,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev"); _ps.Invoke(); - Assert.Equal(1, _feeds.Count); + Assert.Single(_feeds); Assert.Equal("Octopus_Dev", _feeds[0].Name); } @@ -50,31 +50,33 @@ public void With_Uri() Assert.Throws(() => _ps.Invoke()); } - //[Fact] - //public void With_Name_And_Description() - //{ - // // Execute cmdlet - // _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus_Dev").AddParameter("Uri", "\\test"); - // _ps.Invoke(); + [Fact] + public void With_Name_And_Description() + { + // Execute cmdlet + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddNugetFeed.Name), "Octopus_Dev") + .AddParameter(nameof(AddNugetFeed.FeedUri), "\\test"); + _ps.Invoke(); - // Assert.Equal(1, _feeds.Count); - // Assert.Equal("Octopus_Dev", _feeds[0].Name); - // Assert.Equal("\\test", _feeds[0].FeedUri); - //} + Assert.Single(_feeds); + Assert.Equal("Octopus_Dev", _feeds[0].Name); + Assert.Equal("\\test", _feeds[0].FeedUri); + } - //[Fact] - //public void With_Arguements() - //{ - // // Execute cmdlet - // _ps.AddCommand(CmdletName) - // .AddArgument("Octopus_Dev") - // .AddArgument("\\test"); - // _ps.Invoke(); + [Fact] + public void With_Arguements() + { + // Execute cmdlet + _ps.AddCommand(CmdletName) + .AddArgument("Octopus_Dev") + .AddArgument("\\test"); + _ps.Invoke(); - // Assert.Equal(1, _feeds.Count); - // Assert.Equal("Octopus_Dev", _feeds[0].Name); - // Assert.Equal("\\test", _feeds[0].FeedUri); - //} + Assert.Single(_feeds); + Assert.Equal("Octopus_Dev", _feeds[0].Name); + Assert.Equal("\\test", _feeds[0].FeedUri); + } [Fact] public void No_Arguments() diff --git a/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs b/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs index dfc7d9b..a1c718f 100644 --- a/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs +++ b/Octopus-Cmdlets.Tests/AddProjectGroupTests.cs @@ -21,8 +21,8 @@ public AddProjectGroupTests() _groups.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny(), null)) - .Returns(delegate(ProjectGroupResource p) + repo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((ProjectGroupResource p, object o) => { _groups.Add(p); return p; @@ -38,7 +38,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus"); _ps.Invoke(); - Assert.Equal(1, _groups.Count); + Assert.Single(_groups); Assert.Equal("Octopus", _groups[0].Name); } @@ -49,7 +49,7 @@ public void With_Name_Parameter() _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus"); _ps.Invoke(); - Assert.Equal(1, _groups.Count); + Assert.Single(_groups); Assert.Equal("Octopus", _groups[0].Name); } @@ -70,7 +70,7 @@ public void With_Name_And_Description() .AddArgument("Octopus Development Group"); _ps.Invoke(); - Assert.Equal(1, _groups.Count); + Assert.Single(_groups); Assert.Equal("Octopus", _groups[0].Name); Assert.Equal("Octopus Development Group", _groups[0].Description); } diff --git a/Octopus-Cmdlets.Tests/AddProjectTests.cs b/Octopus-Cmdlets.Tests/AddProjectTests.cs index 95e9f41..c873e3d 100644 --- a/Octopus-Cmdlets.Tests/AddProjectTests.cs +++ b/Octopus-Cmdlets.Tests/AddProjectTests.cs @@ -32,8 +32,8 @@ public AddProjectTests() _projects.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny(), null)) - .Returns(delegate(ProjectResource p) + repo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((ProjectResource p, object o) => { _projects.Add(p); return p; @@ -55,7 +55,7 @@ public void With_Invalid_ProjectGroup() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Gibberish").AddParameter("Name", "Octopus"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] @@ -71,7 +71,7 @@ public void With_Invalid_ProjectGroupId() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("ProjectGroupId", "Gibberish").AddParameter("Name", "Octopus"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] @@ -81,7 +81,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Octopus").AddParameter("Name", "Octopus"); _ps.Invoke(); - Assert.Equal(1, _projects.Count); + Assert.Single(_projects); Assert.Equal("Octopus", _projects[0].Name); } @@ -92,7 +92,7 @@ public void ById_With_Name() _ps.AddCommand(CmdletName).AddParameter("ProjectGroupId", "projectgroups-1").AddParameter("Name", "Octopus"); _ps.Invoke(); - Assert.Equal(1, _projects.Count); + Assert.Single(_projects); Assert.Equal("Octopus", _projects[0].Name); } @@ -124,7 +124,7 @@ public void With_Name_And_Description() .AddParameter("Description", "Octopus Development Project"); _ps.Invoke(); - Assert.Equal(1, _projects.Count); + Assert.Single(_projects); Assert.Equal("Octopus", _projects[0].Name); Assert.Equal("projectgroups-1", _projects[0].ProjectGroupId); Assert.Equal("Octopus Development Project", _projects[0].Description); @@ -140,7 +140,7 @@ public void With_Arguments() .AddArgument("Octopus Development Project"); _ps.Invoke(); - Assert.Equal(1, _projects.Count); + Assert.Single(_projects); Assert.Equal("Octopus", _projects[0].Name); Assert.Equal("projectgroups-1", _projects[0].ProjectGroupId); Assert.Equal("Octopus Development Project", _projects[0].Description); diff --git a/Octopus-Cmdlets.Tests/AddVariableSetTests.cs b/Octopus-Cmdlets.Tests/AddVariableSetTests.cs index 2d90344..eb8dc78 100644 --- a/Octopus-Cmdlets.Tests/AddVariableSetTests.cs +++ b/Octopus-Cmdlets.Tests/AddVariableSetTests.cs @@ -21,8 +21,8 @@ public AddVariableSetTests() _sets.Clear(); var repo = new Mock(); - repo.Setup(e => e.Create(It.IsAny(), null)) - .Returns(delegate(LibraryVariableSetResource e) + repo.Setup(e => e.Create(It.IsAny(), It.IsAny())) + .Returns((LibraryVariableSetResource e, object o) => { _sets.Add(e); return e; @@ -38,7 +38,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus"); _ps.Invoke(); - Assert.Equal(1, _sets.Count); + Assert.Single(_sets); Assert.Equal("Octopus", _sets[0].Name); } @@ -59,7 +59,7 @@ public void With_Name_And_Description() .AddParameter("Description", "VariableSet"); _ps.Invoke(); - Assert.Equal(1, _sets.Count); + Assert.Single(_sets); Assert.Equal("Octopus", _sets[0].Name); Assert.Equal("VariableSet", _sets[0].Description); } @@ -73,7 +73,7 @@ public void With_Arguments() .AddArgument("VariableSet"); _ps.Invoke(); - Assert.Equal(1, _sets.Count); + Assert.Single(_sets); Assert.Equal("Octopus", _sets[0].Name); Assert.Equal("VariableSet", _sets[0].Description); } diff --git a/Octopus-Cmdlets.Tests/AddVariableTests.cs b/Octopus-Cmdlets.Tests/AddVariableTests.cs index a52c6a2..5f27b4b 100644 --- a/Octopus-Cmdlets.Tests/AddVariableTests.cs +++ b/Octopus-Cmdlets.Tests/AddVariableTests.cs @@ -66,7 +66,7 @@ public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish").AddParameter("Name", "Test"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] diff --git a/Octopus-Cmdlets.Tests/CopyChannelTests.cs b/Octopus-Cmdlets.Tests/CopyChannelTests.cs index 6a1701f..b53354d 100644 --- a/Octopus-Cmdlets.Tests/CopyChannelTests.cs +++ b/Octopus-Cmdlets.Tests/CopyChannelTests.cs @@ -97,9 +97,9 @@ public void With_Project_And_Name() ChannelResource createdChannel = null; _octoRepo - .Setup(o => o.Channels.Create(It.IsAny(), null)) - .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) @@ -131,7 +131,7 @@ public void With_Invalid_Project() _ps.AddCommand(CmdletName) .AddParameter("Project", "Gibberish") .AddParameter("Name", "Priority"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] @@ -141,7 +141,7 @@ public void With_Project_And_Invalid_Name() _ps.AddCommand(CmdletName) .AddParameter("Project", "Octopus") .AddParameter("Name", "Default"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] @@ -150,9 +150,9 @@ public void With_Destination() ChannelResource createdChannel = null; _octoRepo - .Setup(o => o.Channels.Create(It.IsAny(), null)) - .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) @@ -184,9 +184,9 @@ public void With_Arguments() ChannelResource createdChannel = null; _octoRepo - .Setup(o => o.Channels.Create(It.IsAny(), null)) - .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) diff --git a/Octopus-Cmdlets.Tests/CopyProjectTests.cs b/Octopus-Cmdlets.Tests/CopyProjectTests.cs index f39321d..9bb76f7 100644 --- a/Octopus-Cmdlets.Tests/CopyProjectTests.cs +++ b/Octopus-Cmdlets.Tests/CopyProjectTests.cs @@ -47,8 +47,8 @@ public CopyProjectTests() 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(), null)).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"; @@ -112,13 +112,13 @@ public void With_All() var variable = _copyVariables.Variables.FirstOrDefault(x => x.Name == "Name" && x.Value == "Value"); Assert.NotNull(variable); Assert.True(variable.Scope.ContainsKey(ScopeField.Action)); - Assert.Equal(0, variable.Scope[ScopeField.Action].Count); + 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.NotNull(steps); - Assert.Equal(1, steps.Actions.Count); + Assert.Single(steps.Actions); Assert.Equal("Action", steps.Actions[0].Name); Assert.Equal("environments-1", steps.Actions[0].Environments.First()); } @@ -131,7 +131,7 @@ public void With_Invalid_Group() .AddParameter("Name", "Source") .AddParameter("Destination", "Copy") .AddParameter("ProjectGroup", "Gibberish"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] @@ -142,7 +142,7 @@ public void With_Invalid_Project() .AddParameter("Name", "Gibberish") .AddParameter("Destination", "Copy") .AddParameter("ProjectGroup", "Octopus"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] diff --git a/Octopus-Cmdlets.Tests/GetActionTests.cs b/Octopus-Cmdlets.Tests/GetActionTests.cs index fef3166..fa556f9 100644 --- a/Octopus-Cmdlets.Tests/GetActionTests.cs +++ b/Octopus-Cmdlets.Tests/GetActionTests.cs @@ -68,7 +68,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Do Stuff"); var actions = _ps.Invoke(); - Assert.Equal(1, actions.Count); + Assert.Single(actions); Assert.Equal("Do Stuff", actions[0].Name); } @@ -79,7 +79,7 @@ public void With_Name_Parameter() _ps.AddCommand(CmdletName).AddArgument("Octopus").AddParameter("Name", "Do Stuff"); var actions = _ps.Invoke(); - Assert.Equal(1, actions.Count); + Assert.Single(actions); Assert.Equal("Do Stuff", actions[0].Name); } @@ -90,7 +90,7 @@ public void With_Invalid_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Gibberish"); var actions = _ps.Invoke(); - Assert.Equal(0, actions.Count); + Assert.Empty(actions); } [Fact] @@ -100,7 +100,7 @@ public void With_Id() _ps.AddCommand(CmdletName).AddArgument("Octopus").AddParameter("Id", "Globally unique identifier"); var actions = _ps.Invoke(); - Assert.Equal(1, actions.Count); + Assert.Single(actions); Assert.Equal("Do Stuff", actions[0].Name); } @@ -111,7 +111,7 @@ public void With_Invalid_Id() _ps.AddCommand(CmdletName).AddArgument("Octopus").AddParameter("Id", "Gibberish"); var actions = _ps.Invoke(); - Assert.Equal(0, actions.Count); + Assert.Empty(actions); } } } diff --git a/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs b/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs index 9cf0887..d3342a3 100644 --- a/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs +++ b/Octopus-Cmdlets.Tests/GetDeploymentProcessTests.cs @@ -49,7 +49,7 @@ public void With_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "DeploymentProcesses-1"); var projects = _ps.Invoke(); - Assert.Equal(1, projects.Count); + Assert.Single(projects); } [Fact] @@ -59,7 +59,7 @@ public void With_Invalid_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); var projects = _ps.Invoke(); - Assert.Equal(0, projects.Count); + Assert.Empty(projects); } [Fact] @@ -69,7 +69,7 @@ public void With_ProjectName() _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus"); var projects = _ps.Invoke(); - Assert.Equal(1, projects.Count); + Assert.Single(projects); } [Fact] @@ -79,7 +79,7 @@ public void With_Invalid_ProjectName() _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish"); var projects = _ps.Invoke(); - Assert.Equal(0, projects.Count); + Assert.Empty(projects); } [Fact] @@ -89,7 +89,7 @@ public void With_Arguments() _ps.AddCommand(CmdletName).AddArgument("DeploymentProcesses-1"); var projects = _ps.Invoke(); - Assert.Equal(1, projects.Count); + Assert.Single(projects); } diff --git a/Octopus-Cmdlets.Tests/GetDeploymentTests.cs b/Octopus-Cmdlets.Tests/GetDeploymentTests.cs index 455fee5..09fc13c 100644 --- a/Octopus-Cmdlets.Tests/GetDeploymentTests.cs +++ b/Octopus-Cmdlets.Tests/GetDeploymentTests.cs @@ -61,7 +61,7 @@ public void With_Project_And_Release() _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Release", "1.0.0"); var deployments = _ps.Invoke(); - Assert.Equal(1, deployments.Count); + Assert.Single(deployments); } [Fact] @@ -79,7 +79,7 @@ public void With_Project_And_Invalid_Release() _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Release", "Gibberish"); var deployments = _ps.Invoke(); - Assert.Equal(0, deployments.Count); + Assert.Empty(deployments); } [Fact] @@ -97,7 +97,7 @@ public void With_ReleaseId() _ps.AddCommand(CmdletName).AddParameter("ReleaseId", "Releases-1"); var deployments = _ps.Invoke(); - Assert.Equal(1, deployments.Count); + Assert.Single(deployments); } [Fact] @@ -107,7 +107,7 @@ public void With_Arguments() _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("1.0.0"); var deployments = _ps.Invoke(); - Assert.Equal(1, deployments.Count); + Assert.Single(deployments); } diff --git a/Octopus-Cmdlets.Tests/GetEnvironmentTests.cs b/Octopus-Cmdlets.Tests/GetEnvironmentTests.cs index c722fac..fe5fd41 100644 --- a/Octopus-Cmdlets.Tests/GetEnvironmentTests.cs +++ b/Octopus-Cmdlets.Tests/GetEnvironmentTests.cs @@ -44,7 +44,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus"); var environments = _ps.Invoke(); - Assert.Equal(1, environments.Count); + Assert.Single(environments); Assert.Equal("Octopus", environments[0].Name); } @@ -55,7 +55,7 @@ public void With_Invalid_Name() _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var environments = _ps.Invoke(); - Assert.Equal(0, environments.Count); + Assert.Empty(environments); } [Fact] @@ -65,7 +65,7 @@ public void With_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "environments-1"); var environments = _ps.Invoke(); - Assert.Equal(1, environments.Count); + Assert.Single(environments); Assert.Equal("Octopus", environments[0].Name); } @@ -76,7 +76,7 @@ public void With_Invalid_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); var environments = _ps.Invoke(); - Assert.Equal(0, environments.Count); + Assert.Empty(environments); } [Fact] @@ -86,7 +86,7 @@ public void With_ScopeValue() _ps.AddCommand(CmdletName).AddParameter("ScopeValue", new ScopeValue("environments-1")); var environments = _ps.Invoke(); - Assert.Equal(1, environments.Count); + Assert.Single(environments); Assert.Equal("Octopus", environments[0].Name); } @@ -97,7 +97,7 @@ public void With_Invalid_ScopeValue() _ps.AddCommand(CmdletName).AddParameter("ScopeValue", new ScopeValue("Gibberish")); var environments = _ps.Invoke(); - Assert.Equal(0, environments.Count); + Assert.Empty(environments); } [Fact] diff --git a/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs b/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs index d70e56b..9bc2037 100644 --- a/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs +++ b/Octopus-Cmdlets.Tests/GetExternalFeedTests.cs @@ -55,7 +55,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus"); var feeds = _ps.Invoke(); - Assert.Equal(1, feeds.Count); + Assert.Single(feeds); Assert.Equal("Octopus", feeds[0].Name); } @@ -66,7 +66,7 @@ public void With_Invalid_Name() _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var feeds = _ps.Invoke(); - Assert.Equal(0, feeds.Count); + Assert.Empty(feeds); } } } diff --git a/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs b/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs index 13b454c..087b4a9 100644 --- a/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs +++ b/Octopus-Cmdlets.Tests/GetMachineRoleTests.cs @@ -46,7 +46,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddArgument("WebServer"); var results = _ps.Invoke(); - Assert.Equal(1, results.Count); + Assert.Single(results); Assert.Equal("WebServer", results[0]); } @@ -57,7 +57,7 @@ public void With_Invalid_Name() _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var results = _ps.Invoke(); - Assert.Equal(0, results.Count); + Assert.Empty(results); } } } diff --git a/Octopus-Cmdlets.Tests/GetMachineTests.cs b/Octopus-Cmdlets.Tests/GetMachineTests.cs index 09e45c0..a3909af 100644 --- a/Octopus-Cmdlets.Tests/GetMachineTests.cs +++ b/Octopus-Cmdlets.Tests/GetMachineTests.cs @@ -50,7 +50,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddParameter("Name", new[] {"dbserver-01"}); var machines = _ps.Invoke(); - Assert.Equal(1, machines.Count); + Assert.Single(machines); Assert.Equal("dbserver-01", machines[0].Name); } @@ -61,7 +61,7 @@ public void With_Invalid_Name() _ps.AddCommand(CmdletName).AddParameter("Name", new[] { "Gibberish" }); var machines = _ps.Invoke(); - Assert.Equal(0, machines.Count); + Assert.Empty(machines); } [Fact] @@ -71,7 +71,7 @@ public void With_Id() _ps.AddCommand(CmdletName).AddParameter("Id", new[] { "Machines-1" }); var machines = _ps.Invoke(); - Assert.Equal(1, machines.Count); + Assert.Single(machines); Assert.Equal("dbserver-01", machines[0].Name); } @@ -82,7 +82,7 @@ public void With_Invalid_Id() _ps.AddCommand(CmdletName).AddParameter("Id", new[] { "Gibberish" }); var machines = _ps.Invoke(); - Assert.Equal(0, machines.Count); + Assert.Empty(machines); } [Fact] @@ -102,7 +102,7 @@ public void With_Arguments() _ps.AddCommand(CmdletName).AddArgument(new[] { "dbserver-01" }); var machines = _ps.Invoke(); - Assert.Equal(1, machines.Count); + 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 f2f6325..09de2ff 100644 --- a/Octopus-Cmdlets.Tests/GetProjectGroupTests.cs +++ b/Octopus-Cmdlets.Tests/GetProjectGroupTests.cs @@ -44,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, @@ -75,7 +75,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus"); var groups = _ps.Invoke(); - Assert.Equal(1, groups.Count); + Assert.Single(groups); Assert.Equal("Octopus", groups[0].Name); } @@ -86,7 +86,7 @@ public void With_Invalid_Name() _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var groups = _ps.Invoke(); - Assert.Equal(0, groups.Count); + Assert.Empty(groups); } [Fact] @@ -96,7 +96,7 @@ public void With_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "projectgroups-1"); var groups = _ps.Invoke(); - Assert.Equal(1, groups.Count); + Assert.Single(groups); Assert.Equal("Octopus", groups[0].Name); } @@ -107,7 +107,7 @@ public void With_Invalid_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "gibberish"); var groups = _ps.Invoke(); - Assert.Equal(0, groups.Count); + Assert.Empty(groups); } } } diff --git a/Octopus-Cmdlets.Tests/GetProjectTests.cs b/Octopus-Cmdlets.Tests/GetProjectTests.cs index 79772e8..470d556 100644 --- a/Octopus-Cmdlets.Tests/GetProjectTests.cs +++ b/Octopus-Cmdlets.Tests/GetProjectTests.cs @@ -75,7 +75,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus"); var projects = _ps.Invoke(); - Assert.Equal(1, projects.Count); + Assert.Single(projects); Assert.Equal("Octopus", projects[0].Name); } @@ -86,7 +86,7 @@ public void With_Invalid_Name() _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var projects = _ps.Invoke(); - Assert.Equal(0, projects.Count); + Assert.Empty(projects); } [Fact] @@ -108,7 +108,7 @@ public void With_Invalid_Group() _ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Gibberish"); var projects = _ps.Invoke(); - Assert.Equal(0, projects.Count); + Assert.Empty(projects); } [Fact] @@ -118,7 +118,7 @@ public void With_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "projects-1"); var projects = _ps.Invoke(); - Assert.Equal(1, projects.Count); + Assert.Single(projects); Assert.Equal("Octopus", projects[0].Name); } @@ -129,7 +129,7 @@ public void With_Invalid_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "projects-5000"); var projects = _ps.Invoke(); - Assert.Equal(0, projects.Count); + Assert.Empty(projects); } [Fact] diff --git a/Octopus-Cmdlets.Tests/GetReleaseTests.cs b/Octopus-Cmdlets.Tests/GetReleaseTests.cs index 2bd3cad..f58eeab 100644 --- a/Octopus-Cmdlets.Tests/GetReleaseTests.cs +++ b/Octopus-Cmdlets.Tests/GetReleaseTests.cs @@ -64,7 +64,7 @@ public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] @@ -92,7 +92,7 @@ public void With_Project_And_Version() _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Version", new[] {"1.0.0"}); var releases = _ps.Invoke(); - Assert.Equal(1, releases.Count); + Assert.Single(releases); Assert.Equal("1.0.0", releases[0].Version); } @@ -103,7 +103,7 @@ public void With_Project_And_Invalid_Version() _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Version", new[] { "Gibberish" }); var releases = _ps.Invoke(); - Assert.Equal(0, releases.Count); + Assert.Empty(releases); } [Fact] @@ -113,7 +113,7 @@ public void With_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "releases-1"); var releases = _ps.Invoke(); - Assert.Equal(1, releases.Count); + Assert.Single(releases); Assert.Equal("1.0.0", releases[0].Version); } @@ -124,7 +124,7 @@ public void With_Invalid_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); var releases = _ps.Invoke(); - Assert.Equal(0, releases.Count); + Assert.Empty(releases); } } } diff --git a/Octopus-Cmdlets.Tests/GetStepTests.cs b/Octopus-Cmdlets.Tests/GetStepTests.cs index 86689c3..eb0be51 100644 --- a/Octopus-Cmdlets.Tests/GetStepTests.cs +++ b/Octopus-Cmdlets.Tests/GetStepTests.cs @@ -49,7 +49,7 @@ public void No_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName); - _ps.Invoke(); + Assert.Throws(() => _ps.Invoke()); } [Fact] @@ -70,7 +70,7 @@ public void With_Invalid_ProjectName() _ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish"); var steps = _ps.Invoke(); - Assert.Equal(0, steps.Count); + Assert.Empty(steps); } [Fact] @@ -91,7 +91,7 @@ public void With_Invalid_ProjectId() _ps.AddCommand(CmdletName).AddParameter("ProjectId", "Gibberish"); var steps = _ps.Invoke(); - Assert.Equal(0, steps.Count); + Assert.Empty(steps); } [Fact] @@ -112,7 +112,7 @@ public void With_Invalid_ProcessId() _ps.AddCommand(CmdletName).AddParameter("DeploymentProcessId", "Gibberish"); var steps = _ps.Invoke(); - Assert.Equal(0, steps.Count); + Assert.Empty(steps); } [Fact] @@ -122,7 +122,7 @@ public void With_ProjectAndName() _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Name", "Test Step 2"); var steps = _ps.Invoke(); - Assert.Equal(1, steps.Count); + Assert.Single(steps); Assert.Equal("Test Step 2", steps[0].Name); } @@ -133,7 +133,7 @@ public void With_ProjectIdAndName() _ps.AddCommand(CmdletName).AddParameter("ProjectId", "projects-1").AddParameter("Name", "Test Step 2"); var steps = _ps.Invoke(); - Assert.Equal(1, steps.Count); + Assert.Single(steps); Assert.Equal("Test Step 2", steps[0].Name); } @@ -146,7 +146,7 @@ public void With_ProcessIdAndName() .AddParameter("Name", "Test Step 2"); var steps = _ps.Invoke(); - Assert.Equal(1, steps.Count); + Assert.Single(steps); Assert.Equal("Test Step 2", steps[0].Name); } @@ -158,20 +158,8 @@ public void With_Arguments() _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Test Step 2"); var steps = _ps.Invoke(); - Assert.Equal(1, steps.Count); + Assert.Single(steps); Assert.Equal("Test Step 2", steps[0].Name); } - - - [Fact] - public void With_KitchenSink() - { - // Execute cmdlet - _ps.AddCommand(CmdletName) - .AddParameter("Project", "Gibberish") - .AddParameter("ProjectId", "Gibberish") - .AddParameter("DeploymentProcessId", "Gibberish"); - _ps.Invoke(); - } } } diff --git a/Octopus-Cmdlets.Tests/GetVariableSetTests.cs b/Octopus-Cmdlets.Tests/GetVariableSetTests.cs index 494fbd9..c640161 100644 --- a/Octopus-Cmdlets.Tests/GetVariableSetTests.cs +++ b/Octopus-Cmdlets.Tests/GetVariableSetTests.cs @@ -62,7 +62,7 @@ public void With_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus"); var variables = _ps.Invoke(); - Assert.Equal(1, variables.Count); + Assert.Single(variables); Assert.Equal("Octopus", variables[0].Name); } @@ -73,7 +73,7 @@ public void With_Invalid_Name() _ps.AddCommand(CmdletName).AddArgument("Gibberish"); var variables = _ps.Invoke(); - Assert.Equal(0, variables.Count); + Assert.Empty(variables); } [Fact] @@ -83,7 +83,7 @@ public void By_Name_With_Name() _ps.AddCommand(CmdletName).AddParameter("Name", "Octopus"); var variables = _ps.Invoke(); - Assert.Equal(1, variables.Count); + Assert.Single(variables); Assert.Equal("Octopus", variables[0].Name); } @@ -94,7 +94,7 @@ public void With_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "LibraryVariableSets-1"); var variables = _ps.Invoke(); - Assert.Equal(1, variables.Count); + Assert.Single(variables); Assert.Equal("Octopus", variables[0].Name); } @@ -105,7 +105,7 @@ public void With_Invalid_Id() _ps.AddCommand(CmdletName).AddParameter("Id", "Gibberish"); var variables = _ps.Invoke(); - Assert.Equal(0, variables.Count); + Assert.Empty(variables); } [Fact] diff --git a/Octopus-Cmdlets.Tests/GetVariableTests.cs b/Octopus-Cmdlets.Tests/GetVariableTests.cs index 1ffc46e..c151430 100644 --- a/Octopus-Cmdlets.Tests/GetVariableTests.cs +++ b/Octopus-Cmdlets.Tests/GetVariableTests.cs @@ -90,7 +90,7 @@ public void By_Project_With_Name() _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Deploy"); var variables = _ps.Invoke(); - Assert.Equal(1, variables.Count); + Assert.Single(variables); Assert.Equal("To Production", variables[0].Value); } @@ -119,7 +119,7 @@ public void With_Invalid_VariableSet() _ps.AddCommand(CmdletName).AddParameter("VariableSet", "Gibberish").AddArgument("Deploy"); _ps.Invoke(); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("Library variable set 'Gibberish' was not found.", _ps.Streams.Warning[0].ToString()); } @@ -130,7 +130,7 @@ public void By_VariableSet_With_Name() _ps.AddCommand(CmdletName).AddParameter("VariableSet", "Octopus").AddArgument("Deploy"); var variables = _ps.Invoke(); - Assert.Equal(1, variables.Count); + Assert.Single(variables); Assert.Equal("To Production", variables[0].Value); } @@ -151,7 +151,7 @@ public void By_VariableSetId_With_Name() _ps.AddCommand(CmdletName).AddParameter("VariableSetId", "LibraryVariableSets-1").AddArgument("Deploy"); var variables = _ps.Invoke(); - Assert.Equal(1, variables.Count); + Assert.Single(variables); Assert.Equal("To Production", variables[0].Value); } @@ -162,7 +162,7 @@ public void With_Invalid_VariableSetId() _ps.AddCommand(CmdletName).AddParameter("VariableSetId", "Gibberish").AddArgument("Deploy"); _ps.Invoke(); - Assert.Equal(1, _ps.Streams.Warning.Count); + 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 798b59f..6728caa 100644 --- a/Octopus-Cmdlets.Tests/Octopus-Cmdlets.Tests.csproj +++ b/Octopus-Cmdlets.Tests/Octopus-Cmdlets.Tests.csproj @@ -17,12 +17,13 @@ - - + + + - \ No newline at end of file + diff --git a/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs b/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs index 17da239..443fde7 100644 --- a/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveEnvironmentTests.cs @@ -32,7 +32,7 @@ public RemoveEnvironmentTests() _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); @@ -88,7 +88,7 @@ public void With_Id() _ps.Invoke(); Assert.Equal(2, _envs.Count); - Assert.False(_envs.Contains(_env)); + Assert.DoesNotContain(_env, _envs); } [Fact] @@ -99,7 +99,7 @@ public void With_Invalid_Id() _ps.Invoke(); Assert.Equal(3, _envs.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("An environment with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -111,7 +111,7 @@ public void With_Name() _ps.Invoke(); Assert.Equal(2, _envs.Count); - Assert.False(_envs.Contains(_env)); + Assert.DoesNotContain(_env, _envs); } [Fact] @@ -122,7 +122,7 @@ public void With_Invalid_Name() _ps.Invoke(); Assert.Equal(3, _envs.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("The environment 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -134,7 +134,7 @@ public void With_Valid_And_Invalid_Names() _ps.Invoke(); Assert.Equal(2, _envs.Count); - Assert.False(_envs.Contains(_env)); + Assert.DoesNotContain(_env, _envs); } [Fact] @@ -145,7 +145,7 @@ public void With_Arguments() _ps.Invoke(); Assert.Equal(2, _envs.Count); - Assert.False(_envs.Contains(_env)); + Assert.DoesNotContain(_env, _envs); } [Fact] diff --git a/Octopus-Cmdlets.Tests/RemoveProjectGroupTests.cs b/Octopus-Cmdlets.Tests/RemoveProjectGroupTests.cs index fd76a73..e498855 100644 --- a/Octopus-Cmdlets.Tests/RemoveProjectGroupTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveProjectGroupTests.cs @@ -32,7 +32,7 @@ public RemoveProjectGroupTests() _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); @@ -88,7 +88,7 @@ public void With_Id() _ps.Invoke(); Assert.Equal(2, _groups.Count); - Assert.False(_groups.Contains(_group)); + Assert.DoesNotContain(_group, _groups); } [Fact] @@ -99,7 +99,7 @@ public void With_Invalid_Id() _ps.Invoke(); Assert.Equal(3, _groups.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("A project group with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -111,7 +111,7 @@ public void With_Name() _ps.Invoke(); Assert.Equal(2, _groups.Count); - Assert.False(_groups.Contains(_group)); + Assert.DoesNotContain(_group, _groups); } [Fact] @@ -122,7 +122,7 @@ public void With_Invalid_Name() _ps.Invoke(); Assert.Equal(3, _groups.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("The project group 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -134,7 +134,7 @@ public void With_Valid_And_Invalid_Names() _ps.Invoke(); Assert.Equal(2, _groups.Count); - Assert.False(_groups.Contains(_group)); + Assert.DoesNotContain(_group, _groups); } [Fact] @@ -145,7 +145,7 @@ public void With_Arguments() _ps.Invoke(); Assert.Equal(2, _groups.Count); - Assert.False(_groups.Contains(_group)); + Assert.DoesNotContain(_group, _groups); } [Fact] diff --git a/Octopus-Cmdlets.Tests/RemoveProjectTests.cs b/Octopus-Cmdlets.Tests/RemoveProjectTests.cs index 80b92bc..a8fab40 100644 --- a/Octopus-Cmdlets.Tests/RemoveProjectTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveProjectTests.cs @@ -32,7 +32,7 @@ public RemoveProjectTests() _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); @@ -88,7 +88,7 @@ public void With_Id() _ps.Invoke(); Assert.Equal(2, _projects.Count); - Assert.False(_projects.Contains(_project)); + Assert.DoesNotContain(_project, _projects); } [Fact] @@ -99,7 +99,7 @@ public void With_Invalid_Id() _ps.Invoke(); Assert.Equal(3, _projects.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("A project with the id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -111,7 +111,7 @@ public void With_Name() _ps.Invoke(); Assert.Equal(2, _projects.Count); - Assert.False(_projects.Contains(_project)); + Assert.DoesNotContain(_project, _projects); } [Fact] @@ -122,7 +122,7 @@ public void With_Invalid_Name() _ps.Invoke(); Assert.Equal(3, _projects.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("The project 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -134,7 +134,7 @@ public void With_Valid_And_Invalid_Names() _ps.Invoke(); Assert.Equal(2, _projects.Count); - Assert.False(_projects.Contains(_project)); + Assert.DoesNotContain(_project, _projects); } [Fact] @@ -145,7 +145,7 @@ public void With_Arguments() _ps.Invoke(); Assert.Equal(2, _projects.Count); - Assert.False(_projects.Contains(_project)); + Assert.DoesNotContain(_project, _projects); } [Fact] diff --git a/Octopus-Cmdlets.Tests/RemoveVariableSetTests.cs b/Octopus-Cmdlets.Tests/RemoveVariableSetTests.cs index 7771a9d..e152db9 100644 --- a/Octopus-Cmdlets.Tests/RemoveVariableSetTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveVariableSetTests.cs @@ -33,7 +33,8 @@ public RemoveVariableSetTests() _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); @@ -69,7 +70,7 @@ public void With_Object() _ps.Invoke(); Assert.Equal(2, _sets.Count); - Assert.False(_sets.Contains(_set)); + Assert.DoesNotContain(_set, _sets); } [Fact] @@ -80,7 +81,7 @@ public void With_Invalid_Object() _ps.Invoke(); Assert.Equal(3, _sets.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("The library variable set '' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -92,7 +93,7 @@ public void With_Id() _ps.Invoke(); Assert.Equal(2, _sets.Count); - Assert.False(_sets.Contains(_set)); + Assert.DoesNotContain(_set, _sets); } [Fact] @@ -103,7 +104,7 @@ public void With_Invalid_Id() _ps.Invoke(); Assert.Equal(3, _sets.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("The library variable set with id 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -115,7 +116,7 @@ public void With_Name() _ps.Invoke(); Assert.Equal(2, _sets.Count); - Assert.False(_sets.Contains(_set)); + Assert.DoesNotContain(_set, _sets); } [Fact] @@ -126,7 +127,7 @@ public void With_Invalid_Name() _ps.Invoke(); Assert.Equal(3, _sets.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("The library variable set 'Gibberish' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -138,7 +139,7 @@ public void With_Arguments() _ps.Invoke(); Assert.Equal(2, _sets.Count); - Assert.False(_sets.Contains(_set)); + Assert.DoesNotContain(_set, _sets); } [Fact] diff --git a/Octopus-Cmdlets.Tests/RemoveVariableTests.cs b/Octopus-Cmdlets.Tests/RemoveVariableTests.cs index 5375dd9..a0b6484 100644 --- a/Octopus-Cmdlets.Tests/RemoveVariableTests.cs +++ b/Octopus-Cmdlets.Tests/RemoveVariableTests.cs @@ -62,7 +62,7 @@ public void With_Invalid_Object() _ps.Invoke(); Assert.Equal(3, _variableSet.Variables.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("Variable '' in project 'Octopus' does not exist.", _ps.Streams.Warning[0].ToString()); } @@ -108,7 +108,7 @@ public void With_Invalid_Name() _ps.Invoke(); Assert.Equal(3, _variableSet.Variables.Count); - Assert.Equal(1, _ps.Streams.Warning.Count); + Assert.Single(_ps.Streams.Warning); Assert.Equal("Variable 'Gibberish' in project 'Octopus' does not exist.", _ps.Streams.Warning[0].ToString()); } diff --git a/Octopus-Cmdlets.Tests/UpdateLibraryVariableTests.cs b/Octopus-Cmdlets.Tests/UpdateLibraryVariableTests.cs index 6273f5d..60b3269 100644 --- a/Octopus-Cmdlets.Tests/UpdateLibraryVariableTests.cs +++ b/Octopus-Cmdlets.Tests/UpdateLibraryVariableTests.cs @@ -116,7 +116,7 @@ public void With_Sensitive() _ps.AddCommand(CmdletName).AddParameter("VariableSet", "ConnectionStrings").AddParameter("Id", "variables-1").AddParameter("Sensitive", true); _ps.Invoke(); - Assert.Equal(true, _variableSet.Variables[0].IsSensitive); + Assert.True(_variableSet.Variables[0].IsSensitive); } [Fact] @@ -163,7 +163,7 @@ public void With_All() Assert.Equal(1, _variableSet.Variables.Count); Assert.Equal("NewName", _variableSet.Variables[0].Name); Assert.Equal("New Test Value", _variableSet.Variables[0].Value); - Assert.Equal(true, _variableSet.Variables[0].IsSensitive); + 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()); diff --git a/Octopus-Cmdlets.Tests/UpdateVariableTests.cs b/Octopus-Cmdlets.Tests/UpdateVariableTests.cs index 825eba9..c6be7a9 100644 --- a/Octopus-Cmdlets.Tests/UpdateVariableTests.cs +++ b/Octopus-Cmdlets.Tests/UpdateVariableTests.cs @@ -108,7 +108,7 @@ public void With_Sensitive() _ps.AddCommand(CmdletName).AddParameter("Project", "Octopus").AddParameter("Id", "variables-1").AddParameter("Sensitive", true); _ps.Invoke(); - Assert.Equal(true, _variableSet.Variables[0].IsSensitive); + Assert.True(_variableSet.Variables[0].IsSensitive); } [Fact] @@ -155,7 +155,7 @@ public void With_All() Assert.Equal(1, _variableSet.Variables.Count); Assert.Equal("NewName", _variableSet.Variables[0].Name); Assert.Equal("New Test Value", _variableSet.Variables[0].Value); - Assert.Equal(true, _variableSet.Variables[0].IsSensitive); + 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()); diff --git a/Octopus-Cmdlets.Tests/UseVariableSetTests.cs b/Octopus-Cmdlets.Tests/UseVariableSetTests.cs index 3384b3c..4de21d9 100644 --- a/Octopus-Cmdlets.Tests/UseVariableSetTests.cs +++ b/Octopus-Cmdlets.Tests/UseVariableSetTests.cs @@ -58,7 +58,7 @@ public void With_Invalid_Project() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Gibberish").AddArgument("ConnectionStrings"); - Assert.Throws(() => _ps.Invoke()); + Assert.Throws(() => _ps.Invoke()); } [Fact] @@ -76,7 +76,7 @@ public void With_Name() { // Execute cmdlet _ps.AddCommand(CmdletName).AddArgument("Octopus").AddArgument("Gibberish"); - Assert.Throws(() => _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/AddNugetFeed.cs b/Octopus-Cmdlets/AddNugetFeed.cs index 1c62804..506cc5c 100644 --- a/Octopus-Cmdlets/AddNugetFeed.cs +++ b/Octopus-Cmdlets/AddNugetFeed.cs @@ -31,7 +31,7 @@ namespace Octopus_Cmdlets /// /// /// - /// PS C:\>add-octonugetfeed -Name DEV -Uri "\\test" + /// PS C:\>add-octonugetfeed -Name DEV -FeedUri "\\test" /// /// Add a new feed named 'DEV' pointing to the path '\\test'. /// @@ -47,6 +47,15 @@ public class AddNugetFeed : PSCmdlet Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] + public string Name { get; set; } + + /// + /// The URI of the feed to create. + /// + [Parameter( + Position = 1, + Mandatory = false, + ValueFromPipelineByPropertyName = true)] public string FeedUri { get; set; } [Parameter] @@ -81,6 +90,7 @@ protected override void ProcessRecord() { _octopus.Feeds.Create(new NuGetFeedResource { + Name = Name, FeedUri = FeedUri, Username = Username, Password = Password, 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 From 444be320ff62d62c3d6a550c9873b9fe7dd80b33 Mon Sep 17 00:00:00 2001 From: Colin Svingen Date: Tue, 25 Sep 2018 16:37:03 -0400 Subject: [PATCH 3/3] Adds nameof() to some of the tests --- Octopus-Cmdlets.Tests/AddEnvironmentTests.cs | 10 ++++--- .../AddLibraryVariableTests.cs | 26 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs b/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs index e8d8bde..d709bff 100644 --- a/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs +++ b/Octopus-Cmdlets.Tests/AddEnvironmentTests.cs @@ -35,7 +35,8 @@ public AddEnvironmentTests() 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.Single(_envs); @@ -46,7 +47,8 @@ public void With_Name() public void With_Description() { // Execute cmdlet - _ps.AddCommand(CmdletName).AddParameter("Description", "Octopus Development environment"); + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddEnvironment.Description), "Octopus Development environment"); Assert.Throws(() => _ps.Invoke()); } @@ -55,8 +57,8 @@ 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.Single(_envs); diff --git a/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs b/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs index 8a6e0af..c81f866 100644 --- a/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs +++ b/Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs @@ -62,7 +62,9 @@ public void No_Arguments() 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.Equal(1, _variableSet.Variables.Count); @@ -73,7 +75,9 @@ public void With_Name() public void With_Invalid_VariableSet() { // Execute cmdlet - _ps.AddCommand(CmdletName).AddParameter("VariableSet", "Gibberish").AddParameter("Name", "Test"); + _ps.AddCommand(CmdletName) + .AddParameter(nameof(AddLibraryVariable.VariableSet), "Gibberish") + .AddParameter(nameof(AddLibraryVariable.Name), "Test"); Assert.Throws(() => _ps.Invoke()); } @@ -82,13 +86,13 @@ 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.Equal(1, _variableSet.Variables.Count); @@ -101,8 +105,8 @@ 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.Equal(1, _variableSet.Variables.Count);