Skip to content

Commit

Permalink
Merge pull request #37 from MRCollective/fix-tests
Browse files Browse the repository at this point in the history
Fixing tests
  • Loading branch information
robdmoore committed Mar 6, 2016
2 parents 1b93909 + d1d11db commit a7fee44
Showing 1 changed file with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using ApprovalTests;
Expand All @@ -23,12 +24,14 @@ public class OctopusDeployTests
private const string ReleaseId = "release-1";
private const string MachineId = "machine-1";
private const string TaskId = "task-1";
private const string ProjectId = "project-1";
private const string ProjectId2 = "project-2";

public OctopusDeployTests()
{
_container = new AutoSubstitute();
_config = new ConfigSettings(s => string.Format("%{0}%", s), s => string.Format("c:\\{0}", s));
_container.Provide(_config);
_container.Provide<IConfigSettings>(_config);
_container.Provide(MachineName);
_sut = _container.Resolve<OctopusDeploy.Infrastructure.OctopusDeploy>();
}
Expand Down Expand Up @@ -87,13 +90,15 @@ public void WhenDeletingMachine_ThenDeleteTheMachineFromOctopusServer()
public void WhenDeployingCurrentRelease_InvokeCorrectDeployments()
{
ArrangeDashboardData();
DeploymentResource createdDeployment = null;
var createdDeployments = new List<DeploymentResource>();
_container.Resolve<IOctopusRepository>().Deployments
.WhenForAnyArgs(d => d.Create(null))
.Do(a => createdDeployment = a.Arg<DeploymentResource>());
.Do(a => createdDeployments.Add(a.Arg<DeploymentResource>()));

_sut.DeployAllCurrentReleasesToThisMachine();

createdDeployments.Count.ShouldBe(1);
var createdDeployment = createdDeployments.Single();
createdDeployment.ShouldNotBe(null);
createdDeployment.ReleaseId.ShouldBe(ReleaseId);
createdDeployment.EnvironmentId.ShouldBe(EnvironmentId);
Expand All @@ -106,12 +111,30 @@ private void ArrangeDashboardData()
var repo = _container.Resolve<IOctopusRepository>();
repo.Machines.FindByName(MachineName).Returns(new MachineResource {Id = MachineId});
repo.Environments.FindByName(_config.TentacleEnvironment).Returns(new EnvironmentResource {Id = EnvironmentId});
var projects = new List<ProjectResource>
{
new ProjectResource{ Id = ProjectId, DeploymentProcessId = "Deploy1"},
new ProjectResource{ Id = ProjectId2, DeploymentProcessId = "Deploy2"}
};
repo.Projects.FindAll().Returns(projects);
repo.DeploymentProcesses.Get(projects[0].DeploymentProcessId).Returns(GetDeploymentProcessWithStepAgainstTarget(_config.TentacleRole));
repo.DeploymentProcesses.Get(projects[1].DeploymentProcessId).Returns(GetDeploymentProcessWithStepAgainstTarget("random"));
var dashboard = new DashboardResource {Items = new List<DashboardItemResource>()};
dashboard.Items.Add(new DashboardItemResource {EnvironmentId = "ignore"});
dashboard.Items.Add(new DashboardItemResource {EnvironmentId = EnvironmentId, ReleaseId = ReleaseId});
dashboard.Items.Add(new DashboardItemResource {EnvironmentId = EnvironmentId, ReleaseId = ReleaseId, ProjectId = ProjectId });
dashboard.Items.Add(new DashboardItemResource {EnvironmentId = EnvironmentId, ReleaseId = ReleaseId, ProjectId = ProjectId2 });
repo.Dashboards.GetDashboard().Returns(dashboard);
repo.Deployments.Create(null).ReturnsForAnyArgs(new DeploymentResource { TaskId = TaskId });
repo.Tasks.Get(TaskId).Returns(new TaskResource { State = TaskState.Success });
}

private DeploymentProcessResource GetDeploymentProcessWithStepAgainstTarget(string target)
{
var deploymentProcess = new DeploymentProcessResource();
var step = new DeploymentStepResource();
step.Properties["Octopus.Action.TargetRoles"] = target;
deploymentProcess.Steps.Add(step);
return deploymentProcess;
}
}
}

0 comments on commit a7fee44

Please sign in to comment.