Skip to content

Commit

Permalink
Cleans up unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Swoogan committed Sep 25, 2018
1 parent eb19154 commit d763340
Show file tree
Hide file tree
Showing 36 changed files with 193 additions and 200 deletions.
10 changes: 5 additions & 5 deletions Octopus-Cmdlets.Tests/AddEnvironmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public AddEnvironmentTests()
_envs.Clear();

var envRepo = new Mock<IEnvironmentRepository>();
envRepo.Setup(e => e.Create(It.IsAny<EnvironmentResource>(), null))
.Returns(delegate(EnvironmentResource e)
envRepo.Setup(e => e.Create(It.IsAny<EnvironmentResource>(), It.IsAny<object>()))
.Returns((EnvironmentResource e, object o) =>
{
_envs.Add(e);
return e;
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Octopus-Cmdlets.Tests/AddLibraryVariableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void With_Invalid_VariableSet()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).AddParameter("VariableSet", "Gibberish").AddParameter("Name", "Test");
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
Assert.Throws<CmdletInvocationException>(() => _ps.Invoke());
}

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions Octopus-Cmdlets.Tests/AddMachineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public AddMachineTests()
_machines.Clear();

var machineRepo = new Mock<IMachineRepository>();
machineRepo.Setup(m => m.Create(It.IsAny<MachineResource>(), null))
.Returns(delegate(MachineResource m)
machineRepo.Setup(m => m.Create(It.IsAny<MachineResource>(), It.IsAny<object>()))
.Returns((MachineResource m, object o) =>
{
_machines.Add(m);
return m;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
54 changes: 28 additions & 26 deletions Octopus-Cmdlets.Tests/AddNugetFeedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AddNugetFeedTests
{
private const string CmdletName = "Add-OctoNugetFeed";
private PowerShell _ps;
private readonly List<FeedResource> _feeds = new List<FeedResource>();
private readonly List<NuGetFeedResource> _feeds = new List<NuGetFeedResource>();

public AddNugetFeedTests()
{
Expand All @@ -21,8 +21,8 @@ public AddNugetFeedTests()
_feeds.Clear();

var feedRepo = new Mock<IFeedRepository>();
feedRepo.Setup(e => e.Create(It.IsAny<FeedResource>(), null))
.Returns(delegate(FeedResource e)
feedRepo.Setup(e => e.Create(It.IsAny<NuGetFeedResource>(), It.IsAny<object>()))
.Returns((NuGetFeedResource e, object o) =>
{
_feeds.Add(e);
return e;
Expand All @@ -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);
}

Expand All @@ -50,31 +50,33 @@ public void With_Uri()
Assert.Throws<ParameterBindingException>(() => _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()
Expand Down
10 changes: 5 additions & 5 deletions Octopus-Cmdlets.Tests/AddProjectGroupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public AddProjectGroupTests()
_groups.Clear();

var repo = new Mock<IProjectGroupRepository>();
repo.Setup(e => e.Create(It.IsAny<ProjectGroupResource>(), null))
.Returns(delegate(ProjectGroupResource p)
repo.Setup(e => e.Create(It.IsAny<ProjectGroupResource>(), It.IsAny<object>()))
.Returns((ProjectGroupResource p, object o) =>
{
_groups.Add(p);
return p;
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down
16 changes: 8 additions & 8 deletions Octopus-Cmdlets.Tests/AddProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public AddProjectTests()
_projects.Clear();

var repo = new Mock<IProjectRepository>();
repo.Setup(e => e.Create(It.IsAny<ProjectResource>(), null))
.Returns(delegate(ProjectResource p)
repo.Setup(e => e.Create(It.IsAny<ProjectResource>(), It.IsAny<object>()))
.Returns((ProjectResource p, object o) =>
{
_projects.Add(p);
return p;
Expand All @@ -55,7 +55,7 @@ public void With_Invalid_ProjectGroup()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).AddParameter("ProjectGroup", "Gibberish").AddParameter("Name", "Octopus");
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
Assert.Throws<CmdletInvocationException>(() => _ps.Invoke());
}

[Fact]
Expand All @@ -71,7 +71,7 @@ public void With_Invalid_ProjectGroupId()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).AddParameter("ProjectGroupId", "Gibberish").AddParameter("Name", "Octopus");
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
Assert.Throws<CmdletInvocationException>(() => _ps.Invoke());
}

[Fact]
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions Octopus-Cmdlets.Tests/AddVariableSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public AddVariableSetTests()
_sets.Clear();

var repo = new Mock<ILibraryVariableSetRepository>();
repo.Setup(e => e.Create(It.IsAny<LibraryVariableSetResource>(), null))
.Returns(delegate(LibraryVariableSetResource e)
repo.Setup(e => e.Create(It.IsAny<LibraryVariableSetResource>(), It.IsAny<object>()))
.Returns((LibraryVariableSetResource e, object o) =>
{
_sets.Add(e);
return e;
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Octopus-Cmdlets.Tests/AddVariableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void With_Invalid_Project()
{
// Execute cmdlet
_ps.AddCommand(CmdletName).AddParameter("Project", "Gibberish").AddParameter("Name", "Test");
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
Assert.Throws<CmdletInvocationException>(() => _ps.Invoke());
}

[Fact]
Expand Down
22 changes: 11 additions & 11 deletions Octopus-Cmdlets.Tests/CopyChannelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public void With_Project_And_Name()
ChannelResource createdChannel = null;

_octoRepo
.Setup(o => o.Channels.Create(It.IsAny<ChannelResource>(), null))
.Callback<ChannelResource>(ch => createdChannel = ch)
.Returns<ChannelResource>(ch => ch);
.Setup(o => o.Channels.Create(It.IsAny<ChannelResource>(), It.IsAny<object>()))
.Callback<ChannelResource, object>((ch, o) => createdChannel = ch)
.Returns<ChannelResource, object>((ch, o) => ch);

// Execute cmdlet
_ps.AddCommand(CmdletName)
Expand Down Expand Up @@ -131,7 +131,7 @@ public void With_Invalid_Project()
_ps.AddCommand(CmdletName)
.AddParameter("Project", "Gibberish")
.AddParameter("Name", "Priority");
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
Assert.Throws<CmdletInvocationException>(() => _ps.Invoke());
}

[Fact]
Expand All @@ -141,7 +141,7 @@ public void With_Project_And_Invalid_Name()
_ps.AddCommand(CmdletName)
.AddParameter("Project", "Octopus")
.AddParameter("Name", "Default");
Assert.Throws<ParameterBindingException>(() => _ps.Invoke());
Assert.Throws<CmdletInvocationException>(() => _ps.Invoke());
}

[Fact]
Expand All @@ -150,9 +150,9 @@ public void With_Destination()
ChannelResource createdChannel = null;

_octoRepo
.Setup(o => o.Channels.Create(It.IsAny<ChannelResource>(), null))
.Callback<ChannelResource>(ch => createdChannel = ch)
.Returns<ChannelResource>(ch => ch);
.Setup(o => o.Channels.Create(It.IsAny<ChannelResource>(), It.IsAny<object>()))
.Callback<ChannelResource, object>((ch, o) => createdChannel = ch)
.Returns<ChannelResource, object>((ch, o) => ch);

// Execute cmdlet
_ps.AddCommand(CmdletName)
Expand Down Expand Up @@ -184,9 +184,9 @@ public void With_Arguments()
ChannelResource createdChannel = null;

_octoRepo
.Setup(o => o.Channels.Create(It.IsAny<ChannelResource>(), null))
.Callback<ChannelResource>(ch => createdChannel = ch)
.Returns<ChannelResource>(ch => ch);
.Setup(o => o.Channels.Create(It.IsAny<ChannelResource>(), It.IsAny<object>()))
.Callback<ChannelResource, object>((ch, o) => createdChannel = ch)
.Returns<ChannelResource, object>((ch, o) => ch);

// Execute cmdlet
_ps.AddCommand(CmdletName)
Expand Down
Loading

0 comments on commit d763340

Please sign in to comment.