Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,46 @@ await _mediator.Received(valid && getResource ? 1 : 0).Send<GetResourceResponse>
Arg.Any<CancellationToken>());
}

[Fact]
public async Task GivenParametersWithNullParameterCollection_WhenValidating_ThenShouldNotThrowNullReferenceException()
{
var parameters = new Parameters();
parameters.Parameter = null;

// Should not throw NullReferenceException; ProcessResource should handle gracefully
await _controller.Validate(parameters, null);
}

[Fact]
public async Task GivenParametersWithMissingResourceParameter_WhenValidating_ThenShouldNotThrowNullReferenceException()
{
var parameters = new Parameters();
parameters.Parameter.Add(
new Parameters.ParameterComponent()
{
Name = "otherParam",
Value = new FhirString("test"),
});

// Should not throw NullReferenceException; ProcessResource should handle gracefully
await _controller.Validate(parameters, null);
}

[Fact]
public async Task GivenParametersWithNullResourceParameter_WhenValidating_ThenShouldNotThrowNullReferenceException()
{
var parameters = new Parameters();
parameters.Parameter.Add(
new Parameters.ParameterComponent()
{
Name = "resource",
Resource = null,
});

// Should not throw NullReferenceException; ProcessResource should handle gracefully
await _controller.Validate(parameters, null);
}

private ICollection<OperationOutcomeIssue> CreateIssues(int count)
{
var issues = new List<OperationOutcomeIssue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public async Task<IActionResult> Validate([FromBody] Resource resource, [FromQue

private static void ProcessResource(ref Resource resource, ref string profile)
{
if (resource.TypeName == KnownResourceTypes.Parameters)
if (resource?.TypeName == KnownResourceTypes.Parameters)
{
var parameterResource = (Parameters)resource;
var profileFromParameters = parameterResource.Parameter.Find(param => param.Name.Equals("profile", StringComparison.OrdinalIgnoreCase));
var profileFromParameters = parameterResource.Parameter?.Find(param => param.Name.Equals("profile", StringComparison.OrdinalIgnoreCase));
if (profileFromParameters != null)
{
if (profile != null)
Expand All @@ -71,7 +71,11 @@ private static void ProcessResource(ref Resource resource, ref string profile)
}
}

resource = parameterResource.Parameter.Find(param => param.Name.Equals("resource", StringComparison.OrdinalIgnoreCase)).Resource;
var resourceParam = parameterResource.Parameter?.Find(param => param.Name.Equals("resource", StringComparison.OrdinalIgnoreCase));
if (resourceParam?.Resource != null)
{
resource = resourceParam.Resource;
}
}
}

Expand Down
Loading