@@ -132,6 +132,165 @@ public async void GetList_ServiceException_ReturnProblem()
132132 Assert . StartsWith ( expectedInstance , ( ( ProblemDetails ) objectResult . Value ) . Instance ) ;
133133 }
134134
135+ [ Fact ]
136+ public async Task CreateAsync_ValidWorkflow_ReturnsWorkflowId ( )
137+ {
138+ var newWorkflow = new Workflow
139+ {
140+ Name = "Workflowname" ,
141+ Description = "Workflowdesc" ,
142+ Version = "1" ,
143+ InformaticsGateway = new InformaticsGateway
144+ {
145+ AeTitle = "aetitle" ,
146+ ExportDestinations = new [ ] { "test" }
147+ } ,
148+ Tasks = new TaskObject [ ]
149+ {
150+ new TaskObject {
151+ Id = Guid . NewGuid ( ) . ToString ( ) ,
152+ Type = "export" ,
153+ Description = "taskdesc" ,
154+ Args = new Dictionary < string , string >
155+ {
156+ { "test" , "test" }
157+ } ,
158+ Artifacts = new ArtifactMap
159+ {
160+ Input = new Artifact [ ]
161+ {
162+ new Artifact
163+ {
164+ Name = "test" ,
165+ Value = "{{ context.input.dicom }}"
166+ }
167+ }
168+ } ,
169+ ExportDestinations = new ExportDestination [ ] {
170+ new ExportDestination
171+ {
172+ Name = "test"
173+ }
174+ }
175+ }
176+ }
177+ } ;
178+
179+ var workflowId = Guid . NewGuid ( ) . ToString ( ) ;
180+
181+ var response = new CreateWorkflowResponse ( workflowId ) ;
182+
183+ _workflowService . Setup ( w => w . CreateAsync ( newWorkflow ) ) . ReturnsAsync ( workflowId ) ;
184+
185+ var result = await WorkflowsController . CreateAsync ( newWorkflow ) ;
186+
187+ var objectResult = Assert . IsType < ObjectResult > ( result ) ;
188+
189+ Assert . Equal ( 201 , objectResult . StatusCode ) ;
190+ objectResult . Value . Should ( ) . BeEquivalentTo ( response ) ;
191+ }
192+
193+ [ Fact ]
194+ public async Task CreateAsync_InvalidWorkflow_ReturnsBadRequest ( )
195+ {
196+ var newWorkflow = new Workflow
197+ {
198+ Name = "Workflowname" ,
199+ Description = "Workflowdesc" ,
200+ Version = "1" ,
201+ InformaticsGateway = new InformaticsGateway
202+ {
203+ AeTitle = "aetitle"
204+ } ,
205+ Tasks = new TaskObject [ ]
206+ {
207+ new TaskObject {
208+ Id = Guid . NewGuid ( ) . ToString ( ) ,
209+ Type = "type" ,
210+ Description = "taskdesc" ,
211+ Args = new Dictionary < string , string >
212+ {
213+ { "test" , "test" }
214+ }
215+ }
216+ }
217+ } ;
218+
219+ var workflowId = Guid . NewGuid ( ) . ToString ( ) ;
220+
221+ var response = new CreateWorkflowResponse ( workflowId ) ;
222+
223+ var result = await WorkflowsController . CreateAsync ( newWorkflow ) ;
224+
225+ var objectResult = Assert . IsType < ObjectResult > ( result ) ;
226+
227+ Assert . Equal ( 400 , objectResult . StatusCode ) ;
228+
229+ const string expectedInstance = "/workflows" ;
230+ Assert . StartsWith ( expectedInstance , ( ( ProblemDetails ) objectResult . Value ) . Instance ) ;
231+ }
232+
233+ [ Fact ]
234+ public async Task CreateAsync_InvalidWorkflow_ReturnsInternalServerError ( )
235+ {
236+ var newWorkflow = new Workflow
237+ {
238+ Name = "Workflowname" ,
239+ Description = "Workflowdesc" ,
240+ Version = "1" ,
241+ InformaticsGateway = new InformaticsGateway
242+ {
243+ AeTitle = "aetitle" ,
244+ ExportDestinations = new [ ] { "test" } ,
245+ DataOrigins = new string [ ] { "invalid_origin" }
246+ } ,
247+ Tasks = new TaskObject [ ]
248+ {
249+ new TaskObject {
250+ Id = Guid . NewGuid ( ) . ToString ( ) ,
251+ Type = "export" ,
252+ Description = "taskdesc" ,
253+ Args = new Dictionary < string , string >
254+ {
255+ { "test" , "test" }
256+ } ,
257+ Artifacts = new ArtifactMap
258+ {
259+ Input = new Artifact [ ]
260+ {
261+ new Artifact
262+ {
263+ Name = "test" ,
264+ Value = "{{ context.input.dicom }}"
265+ }
266+ }
267+ } ,
268+ ExportDestinations = new ExportDestination [ ] {
269+ new ExportDestination
270+ {
271+ Name = "test"
272+ }
273+ }
274+ }
275+ }
276+ } ;
277+
278+ _informaticsGatewayService . Setup ( x => x . OriginExists ( It . IsAny < string > ( ) ) )
279+ . ThrowsAsync ( new MonaiInternalServerException (
280+ $ "An error occured when checking if the origin '{ newWorkflow . InformaticsGateway . DataOrigins [ 0 ] } ' existed.",
281+ new Exception ( )
282+ ) ) ;
283+
284+ var result = await WorkflowsController . CreateAsync ( newWorkflow ) ;
285+
286+ var objectResult = Assert . IsType < ObjectResult > ( result ) ;
287+
288+ Assert . Equal ( 500 , objectResult . StatusCode ) ;
289+
290+ const string expectedInstance = "/workflows" ;
291+ Assert . StartsWith ( expectedInstance , ( ( ProblemDetails ) objectResult . Value ) . Instance ) ;
292+ }
293+
135294 [ Fact ]
136295 public async Task ValidateAsync_InvalidWorkflow_ReturnsBadRequest ( )
137296 {
@@ -501,7 +660,7 @@ public async Task ValidateAsync_InvalidWorkflow_ReturnsInternalServerError()
501660
502661 _informaticsGatewayService . Setup ( x => x . OriginExists ( It . IsAny < string > ( ) ) )
503662 . ThrowsAsync ( new MonaiInternalServerException (
504- $ "An error occured when cheking if the origin '{ newWorkflow . InformaticsGateway . DataOrigins [ 0 ] } ' existed.",
663+ $ "An error occured when checking if the origin '{ newWorkflow . InformaticsGateway . DataOrigins [ 0 ] } ' existed.",
505664 new Exception ( )
506665 ) ) ;
507666
@@ -809,7 +968,7 @@ public async Task UpdateAsync_InvalidWorkflow_ReturnsInternalServerException()
809968
810969 _informaticsGatewayService . Setup ( x => x . OriginExists ( It . IsAny < string > ( ) ) )
811970 . ThrowsAsync ( new MonaiInternalServerException (
812- $ "An error occured when cheking if the origin '{ newWorkflow . InformaticsGateway . DataOrigins [ 0 ] } ' existed.",
971+ $ "An error occured when checking if the origin '{ newWorkflow . InformaticsGateway . DataOrigins [ 0 ] } ' existed.",
813972 new Exception ( )
814973 ) ) ;
815974
0 commit comments