Skip to content

Commit 019af02

Browse files
committed
Add unit test for Plug-ins client
Signed-off-by: Victor Chang <[email protected]>
1 parent 2e15d69 commit 019af02

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/Client/Test/AeTitleServiceTest.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,5 +460,64 @@ public async Task CEcho_ReturnsAProblem()
460460

461461
Assert.Equal($"HTTP Status: {problem.Status}. {problem.Detail}", result.Message);
462462
}
463+
464+
[Fact(DisplayName = "AET - Plugins")]
465+
public async Task Plugins()
466+
{
467+
var plugins = new Dictionary<string, string>
468+
{
469+
{"A","1" },
470+
{"B","2" },
471+
{"C","3" },
472+
};
473+
474+
var json = JsonSerializer.Serialize(plugins, Configuration.JsonSerializationOptions);
475+
476+
var rootUri = new Uri("http://localhost:5000");
477+
var uriPath = "config/monaiaetitle/plug-ins";
478+
479+
var httpResponse = new HttpResponseMessage
480+
{
481+
StatusCode = HttpStatusCode.OK,
482+
Content = new StringContent(json, Encoding.UTF8, "application/json")
483+
};
484+
485+
var httpClient = SetupHttpClientMock(rootUri, HttpMethod.Get, httpResponse);
486+
487+
var service = new AeTitleService<DestinationApplicationEntity>(uriPath, httpClient, _logger.Object);
488+
489+
var exception = await Record.ExceptionAsync(async () => await service.Plugins(CancellationToken.None));
490+
Assert.Null(exception);
491+
}
492+
493+
[Fact(DisplayName = "AET - Plugins returns a problem")]
494+
public async Task Plugins_ReturnsAProblem()
495+
{
496+
var problem = new ProblemDetails
497+
{
498+
Title = "Problem Title",
499+
Detail = "Problem Detail",
500+
Status = 500
501+
};
502+
503+
var json = JsonSerializer.Serialize(problem, Configuration.JsonSerializationOptions);
504+
505+
var rootUri = new Uri("http://localhost:5000");
506+
var uriPath = "config/destination";
507+
508+
var httpResponse = new HttpResponseMessage
509+
{
510+
StatusCode = HttpStatusCode.InternalServerError,
511+
Content = new StringContent(json, Encoding.UTF8, "application/json")
512+
};
513+
514+
var httpClient = SetupHttpClientMock(rootUri, HttpMethod.Get, httpResponse);
515+
516+
var service = new AeTitleService<DestinationApplicationEntity>(uriPath, httpClient, _logger.Object);
517+
518+
var result = await Assert.ThrowsAsync<ProblemException>(async () => await service.Plugins(CancellationToken.None));
519+
520+
Assert.Equal($"HTTP Status: {problem.Status}. {problem.Detail}", result.Message);
521+
}
463522
}
464523
}

0 commit comments

Comments
 (0)