Skip to content

Commit

Permalink
added extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsmits committed Jan 24, 2024
1 parent a349396 commit 4c9bbca
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Hl7.Fhir.Support.Poco.Tests/Rest/FhirClientMockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public async T.Task TestOperationResponseCodes()
{
var response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.Accepted,
StatusCode = HttpStatusCode.Created,
Content = new StringContent(@"{""resourceType"": ""Parameters"", ""parameter"": [ { ""name"": ""result"", ""valueString"": ""connected""}] }", Encoding.UTF8, "application/json"),
RequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://example.com/fhir/$ping")
};
Expand All @@ -362,11 +362,11 @@ public async T.Task TestOperationResponseCodes()
.AsClient();

var parameters = await client.OperationAsync(new Uri("http://example.com/fhir/$ping")) as Parameters;
client.LastResult?.Status.Should().Be("202");
client.LastResult?.Status.Should().Be("201");

response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.NotFound,
StatusCode = HttpStatusCode.Accepted,
Content = new StringContent(@"{""resourceType"": ""Parameters"", ""parameter"": [ { ""name"": ""result"", ""valueString"": ""connected""}] }", Encoding.UTF8, "application/json"),
RequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://example.com/fhir/$ping")
};
Expand All @@ -375,7 +375,22 @@ public async T.Task TestOperationResponseCodes()
.Send(response, h => h.RequestUri == new Uri("http://example.com/fhir/$ping"))
.AsClient();

var function = () => client2.OperationAsync(new Uri("http://example.com/fhir/$ping"));
parameters = await client2.OperationAsync(new Uri("http://example.com/fhir/$ping")) as Parameters;
client2.LastResult?.Status.Should().Be("202");


response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.NotFound,
Content = new StringContent(@"{""resourceType"": ""Parameters"", ""parameter"": [ { ""name"": ""result"", ""valueString"": ""connected""}] }", Encoding.UTF8, "application/json"),
RequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://example.com/fhir/$ping")
};

using var client3 = new MoqBuilder()
.Send(response, h => h.RequestUri == new Uri("http://example.com/fhir/$ping"))
.AsClient();

var function = () => client3.OperationAsync(new Uri("http://example.com/fhir/$ping"));
await function.Should().ThrowAsync<FhirOperationException>().WithMessage("Operation was unsuccessful because of a client error (NotFound). Body contains a Parameters.");

}
Expand Down

0 comments on commit 4c9bbca

Please sign in to comment.