Skip to content

Commit

Permalink
Add unit test for Plug-ins client
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Chang <[email protected]>
  • Loading branch information
mocsharp committed Aug 10, 2023
1 parent 2e15d69 commit 019af02
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/Client/Test/AeTitleServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,5 +460,64 @@ public async Task CEcho_ReturnsAProblem()

Assert.Equal($"HTTP Status: {problem.Status}. {problem.Detail}", result.Message);
}

[Fact(DisplayName = "AET - Plugins")]
public async Task Plugins()
{
var plugins = new Dictionary<string, string>
{
{"A","1" },
{"B","2" },
{"C","3" },
};

var json = JsonSerializer.Serialize(plugins, Configuration.JsonSerializationOptions);

var rootUri = new Uri("http://localhost:5000");
var uriPath = "config/monaiaetitle/plug-ins";

var httpResponse = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(json, Encoding.UTF8, "application/json")
};

var httpClient = SetupHttpClientMock(rootUri, HttpMethod.Get, httpResponse);

var service = new AeTitleService<DestinationApplicationEntity>(uriPath, httpClient, _logger.Object);

var exception = await Record.ExceptionAsync(async () => await service.Plugins(CancellationToken.None));
Assert.Null(exception);
}

[Fact(DisplayName = "AET - Plugins returns a problem")]
public async Task Plugins_ReturnsAProblem()
{
var problem = new ProblemDetails
{
Title = "Problem Title",
Detail = "Problem Detail",
Status = 500
};

var json = JsonSerializer.Serialize(problem, Configuration.JsonSerializationOptions);

var rootUri = new Uri("http://localhost:5000");
var uriPath = "config/destination";

var httpResponse = new HttpResponseMessage
{
StatusCode = HttpStatusCode.InternalServerError,
Content = new StringContent(json, Encoding.UTF8, "application/json")
};

var httpClient = SetupHttpClientMock(rootUri, HttpMethod.Get, httpResponse);

var service = new AeTitleService<DestinationApplicationEntity>(uriPath, httpClient, _logger.Object);

var result = await Assert.ThrowsAsync<ProblemException>(async () => await service.Plugins(CancellationToken.None));

Assert.Equal($"HTTP Status: {problem.Status}. {problem.Detail}", result.Message);
}
}
}

0 comments on commit 019af02

Please sign in to comment.