-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for searching reference by id, type/id, or url. (#5)
Added support for searching reference by id, type/id, or url.
- Loading branch information
Showing
59 changed files
with
1,063 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
src/Microsoft.Health.Fhir.Api.UnitTests/Features/Context/FhirContextMiddlewareTests.cs
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
...Microsoft.Health.Fhir.Api.UnitTests/Features/Context/FhirRequestContextMiddlewareTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Health.Fhir.Api.Features.Context; | ||
using Microsoft.Health.Fhir.Core.Features.Context; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Api.UnitTests.Features.Context | ||
{ | ||
public class FhirRequestContextMiddlewareTests | ||
{ | ||
[Fact] | ||
public async Task GivenAnHttpRequest_WhenExecutingFhirRequestContextMiddleware_ThenCorrectRequestTypeShouldBeSet() | ||
{ | ||
IFhirRequestContext fhirRequestContext = await SetupAsync(CreateHttpContext()); | ||
|
||
Assert.NotNull(fhirRequestContext.RequestType); | ||
|
||
Assert.Equal(ValueSets.AuditEventType.RestFulOperation.System, fhirRequestContext.RequestType.System); | ||
Assert.Equal(ValueSets.AuditEventType.RestFulOperation.Code, fhirRequestContext.RequestType.Code); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAnHttpRequest_WhenExecutingFhirRequestContextMiddleware_ThenCorrectUriShouldBeSet() | ||
{ | ||
IFhirRequestContext fhirRequestContext = await SetupAsync(CreateHttpContext()); | ||
|
||
Assert.Equal(new Uri("https://localhost:30/stu3/Observation?code=123"), fhirRequestContext.Uri); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAnHttpRequest_WhenExecutingFhirRequestContextMiddleware_ThenCorrectBaseUriShouldBeSet() | ||
{ | ||
IFhirRequestContext fhirRequestContext = await SetupAsync(CreateHttpContext()); | ||
|
||
Assert.Equal(new Uri("https://localhost:30/stu3"), fhirRequestContext.BaseUri); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAnHttpContextWithPrincipal_WhenExecutingFhirRequestContextMiddleware_ThenPrincipalShouldBeSet() | ||
{ | ||
HttpContext httpContext = CreateHttpContext(); | ||
|
||
var principal = new ClaimsPrincipal(); | ||
|
||
httpContext.User = principal; | ||
|
||
IFhirRequestContext fhirRequestContext = await SetupAsync(httpContext); | ||
|
||
Assert.Same(principal, fhirRequestContext.Principal); | ||
} | ||
|
||
private async Task<IFhirRequestContext> SetupAsync(HttpContext httpContext) | ||
{ | ||
var fhirRequestContextAccessor = Substitute.For<IFhirRequestContextAccessor>(); | ||
var fhirContextMiddlware = new FhirRequestContextMiddleware(next: (innerHttpContext) => Task.CompletedTask); | ||
string Provider() => Guid.NewGuid().ToString(); | ||
|
||
await fhirContextMiddlware.Invoke(httpContext, fhirRequestContextAccessor, Provider); | ||
|
||
Assert.NotNull(fhirRequestContextAccessor.FhirRequestContext); | ||
|
||
return fhirRequestContextAccessor.FhirRequestContext; | ||
} | ||
|
||
private HttpContext CreateHttpContext() | ||
{ | ||
HttpContext httpContext = new DefaultHttpContext(); | ||
|
||
httpContext.Request.Method = "GET"; | ||
httpContext.Request.Scheme = "https"; | ||
httpContext.Request.Host = new HostString("localhost", 30); | ||
httpContext.Request.PathBase = new PathString("/stu3"); | ||
httpContext.Request.Path = new PathString("/Observation"); | ||
httpContext.Request.QueryString = new QueryString("?code=123"); | ||
|
||
return httpContext; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.