1
1
using System . Collections . Generic ;
2
+ using System . Linq ;
2
3
using System . Runtime . CompilerServices ;
3
4
using System . Text ;
4
5
using ApprovalTests ;
@@ -23,12 +24,14 @@ public class OctopusDeployTests
23
24
private const string ReleaseId = "release-1" ;
24
25
private const string MachineId = "machine-1" ;
25
26
private const string TaskId = "task-1" ;
27
+ private const string ProjectId = "project-1" ;
28
+ private const string ProjectId2 = "project-2" ;
26
29
27
30
public OctopusDeployTests ( )
28
31
{
29
32
_container = new AutoSubstitute ( ) ;
30
33
_config = new ConfigSettings ( s => string . Format ( "%{0}%" , s ) , s => string . Format ( "c:\\ {0}" , s ) ) ;
31
- _container . Provide ( _config ) ;
34
+ _container . Provide < IConfigSettings > ( _config ) ;
32
35
_container . Provide ( MachineName ) ;
33
36
_sut = _container . Resolve < OctopusDeploy . Infrastructure . OctopusDeploy > ( ) ;
34
37
}
@@ -87,13 +90,15 @@ public void WhenDeletingMachine_ThenDeleteTheMachineFromOctopusServer()
87
90
public void WhenDeployingCurrentRelease_InvokeCorrectDeployments ( )
88
91
{
89
92
ArrangeDashboardData ( ) ;
90
- DeploymentResource createdDeployment = null ;
93
+ var createdDeployments = new List < DeploymentResource > ( ) ;
91
94
_container . Resolve < IOctopusRepository > ( ) . Deployments
92
95
. WhenForAnyArgs ( d => d . Create ( null ) )
93
- . Do ( a => createdDeployment = a . Arg < DeploymentResource > ( ) ) ;
96
+ . Do ( a => createdDeployments . Add ( a . Arg < DeploymentResource > ( ) ) ) ;
94
97
95
98
_sut . DeployAllCurrentReleasesToThisMachine ( ) ;
96
99
100
+ createdDeployments . Count . ShouldBe ( 1 ) ;
101
+ var createdDeployment = createdDeployments . Single ( ) ;
97
102
createdDeployment . ShouldNotBe ( null ) ;
98
103
createdDeployment . ReleaseId . ShouldBe ( ReleaseId ) ;
99
104
createdDeployment . EnvironmentId . ShouldBe ( EnvironmentId ) ;
@@ -106,12 +111,30 @@ private void ArrangeDashboardData()
106
111
var repo = _container . Resolve < IOctopusRepository > ( ) ;
107
112
repo . Machines . FindByName ( MachineName ) . Returns ( new MachineResource { Id = MachineId } ) ;
108
113
repo . Environments . FindByName ( _config . TentacleEnvironment ) . Returns ( new EnvironmentResource { Id = EnvironmentId } ) ;
114
+ var projects = new List < ProjectResource >
115
+ {
116
+ new ProjectResource { Id = ProjectId , DeploymentProcessId = "Deploy1" } ,
117
+ new ProjectResource { Id = ProjectId2 , DeploymentProcessId = "Deploy2" }
118
+ } ;
119
+ repo . Projects . FindAll ( ) . Returns ( projects ) ;
120
+ repo . DeploymentProcesses . Get ( projects [ 0 ] . DeploymentProcessId ) . Returns ( GetDeploymentProcessWithStepAgainstTarget ( _config . TentacleRole ) ) ;
121
+ repo . DeploymentProcesses . Get ( projects [ 1 ] . DeploymentProcessId ) . Returns ( GetDeploymentProcessWithStepAgainstTarget ( "random" ) ) ;
109
122
var dashboard = new DashboardResource { Items = new List < DashboardItemResource > ( ) } ;
110
123
dashboard . Items . Add ( new DashboardItemResource { EnvironmentId = "ignore" } ) ;
111
- dashboard . Items . Add ( new DashboardItemResource { EnvironmentId = EnvironmentId , ReleaseId = ReleaseId } ) ;
124
+ dashboard . Items . Add ( new DashboardItemResource { EnvironmentId = EnvironmentId , ReleaseId = ReleaseId , ProjectId = ProjectId } ) ;
125
+ dashboard . Items . Add ( new DashboardItemResource { EnvironmentId = EnvironmentId , ReleaseId = ReleaseId , ProjectId = ProjectId2 } ) ;
112
126
repo . Dashboards . GetDashboard ( ) . Returns ( dashboard ) ;
113
127
repo . Deployments . Create ( null ) . ReturnsForAnyArgs ( new DeploymentResource { TaskId = TaskId } ) ;
114
128
repo . Tasks . Get ( TaskId ) . Returns ( new TaskResource { State = TaskState . Success } ) ;
115
129
}
130
+
131
+ private DeploymentProcessResource GetDeploymentProcessWithStepAgainstTarget ( string target )
132
+ {
133
+ var deploymentProcess = new DeploymentProcessResource ( ) ;
134
+ var step = new DeploymentStepResource ( ) ;
135
+ step . Properties [ "Octopus.Action.TargetRoles" ] = target ;
136
+ deploymentProcess . Steps . Add ( step ) ;
137
+ return deploymentProcess ;
138
+ }
116
139
}
117
140
}
0 commit comments