11using System . Collections . Generic ;
2+ using System . Linq ;
23using System . Runtime . CompilerServices ;
34using System . Text ;
45using ApprovalTests ;
@@ -23,12 +24,14 @@ public class OctopusDeployTests
2324 private const string ReleaseId = "release-1" ;
2425 private const string MachineId = "machine-1" ;
2526 private const string TaskId = "task-1" ;
27+ private const string ProjectId = "project-1" ;
28+ private const string ProjectId2 = "project-2" ;
2629
2730 public OctopusDeployTests ( )
2831 {
2932 _container = new AutoSubstitute ( ) ;
3033 _config = new ConfigSettings ( s => string . Format ( "%{0}%" , s ) , s => string . Format ( "c:\\ {0}" , s ) ) ;
31- _container . Provide ( _config ) ;
34+ _container . Provide < IConfigSettings > ( _config ) ;
3235 _container . Provide ( MachineName ) ;
3336 _sut = _container . Resolve < OctopusDeploy . Infrastructure . OctopusDeploy > ( ) ;
3437 }
@@ -87,13 +90,15 @@ public void WhenDeletingMachine_ThenDeleteTheMachineFromOctopusServer()
8790 public void WhenDeployingCurrentRelease_InvokeCorrectDeployments ( )
8891 {
8992 ArrangeDashboardData ( ) ;
90- DeploymentResource createdDeployment = null ;
93+ var createdDeployments = new List < DeploymentResource > ( ) ;
9194 _container . Resolve < IOctopusRepository > ( ) . Deployments
9295 . WhenForAnyArgs ( d => d . Create ( null ) )
93- . Do ( a => createdDeployment = a . Arg < DeploymentResource > ( ) ) ;
96+ . Do ( a => createdDeployments . Add ( a . Arg < DeploymentResource > ( ) ) ) ;
9497
9598 _sut . DeployAllCurrentReleasesToThisMachine ( ) ;
9699
100+ createdDeployments . Count . ShouldBe ( 1 ) ;
101+ var createdDeployment = createdDeployments . Single ( ) ;
97102 createdDeployment . ShouldNotBe ( null ) ;
98103 createdDeployment . ReleaseId . ShouldBe ( ReleaseId ) ;
99104 createdDeployment . EnvironmentId . ShouldBe ( EnvironmentId ) ;
@@ -106,12 +111,30 @@ private void ArrangeDashboardData()
106111 var repo = _container . Resolve < IOctopusRepository > ( ) ;
107112 repo . Machines . FindByName ( MachineName ) . Returns ( new MachineResource { Id = MachineId } ) ;
108113 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" ) ) ;
109122 var dashboard = new DashboardResource { Items = new List < DashboardItemResource > ( ) } ;
110123 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 } ) ;
112126 repo . Dashboards . GetDashboard ( ) . Returns ( dashboard ) ;
113127 repo . Deployments . Create ( null ) . ReturnsForAnyArgs ( new DeploymentResource { TaskId = TaskId } ) ;
114128 repo . Tasks . Get ( TaskId ) . Returns ( new TaskResource { State = TaskState . Success } ) ;
115129 }
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+ }
116139 }
117140}
0 commit comments