Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijeet Thacker committed Jun 6, 2019
1 parent 2b45a72 commit f707061
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 34 deletions.
9 changes: 0 additions & 9 deletions src/Microsoft.Health.Fhir.Core/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Microsoft.Health.Fhir.Core/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@
<data name="SearchParameterDefinitionInvalidResource" xml:space="preserve">
<value>bundle.entry[{0}].resource is not a SearchParameter resource.</value>
</data>
<data name="SearchParameterKeyRequired" xml:space="preserve">
<value>For search parameters key is required</value>
</data>
<data name="SearchParameterNotSupported" xml:space="preserve">
<value>The search parameter '{0}' is not supported for resource type '{1}'.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ public SearchOptions Create(string compartmentType, string compartmentId, string
{
// TODO: We need to handle format parameter.
}
else if (string.IsNullOrWhiteSpace(query.Item1))
{
throw new RequestNotValidException(Core.Resources.SearchParameterKeyRequired);
}
else if (string.IsNullOrWhiteSpace(query.Item2))
else if (string.IsNullOrWhiteSpace(query.Item1) || string.IsNullOrWhiteSpace(query.Item2))
{
// Query parameter with empty value is not supported.
unsupportedSearchParameters.Add(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Linq;
using Hl7.Fhir.Model;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Health.Fhir.Core.Exceptions;
using Microsoft.Health.Fhir.Core.Extensions;
using Microsoft.Health.Fhir.Core.Features.Definition;
using Microsoft.Health.Fhir.Core.Features.Search;
Expand Down Expand Up @@ -224,38 +223,81 @@ public void GivenASearchParamWithEmptyValue_WhenCreated_ThenSearchParamShouldBeA
}

[Fact]
public void GivenASearchParamWithEmptyKey_WhenCreated_ThenExceptionThrown()
public void GivenASearchParameterWithEmptyKey_WhenCreated_ThenSearchParameterShouldBeAddedToUnsupportedList()
{
const ResourceType resourceType = ResourceType.Patient;

var queryParameters = new[]
{
Tuple.Create(string.Empty, "city"),
};

RequestNotValidException exception = Assert.Throws<RequestNotValidException>(() =>
CreateSearchOptions(
resourceType: resourceType.ToString(),
queryParameters: queryParameters));
Assert.Same(Core.Resources.SearchParameterKeyRequired, exception.Message);
SearchOptions options = CreateSearchOptions(ResourceType.Patient.ToString(), queryParameters: queryParameters);
Assert.NotNull(options);
Assert.Equal(queryParameters.Take(1), options.UnsupportedSearchParams);
}

[Fact]
public void GivenMultipleSearchParamsWithEmptyKey_WhenCreated_ThenExceptionThrown()
public void GivenSearchParametersWithEmptyKey_WhenCreated_ThenSearchParameterShouldBeAddedToUnsupportedList()
{
const ResourceType resourceType = ResourceType.Patient;

var queryParameters = new[]
{
Tuple.Create("patient", "city"),
Tuple.Create(string.Empty, "anotherCity"),
};

RequestNotValidException exception = Assert.Throws<RequestNotValidException>(() =>
CreateSearchOptions(
resourceType: resourceType.ToString(),
queryParameters: queryParameters));
Assert.Same(Core.Resources.SearchParameterKeyRequired, exception.Message);
SearchOptions options = CreateSearchOptions(ResourceType.Patient.ToString(), queryParameters);
Assert.NotNull(options);
Assert.Equal(1, options.UnsupportedSearchParams.Count);
Assert.Equal(queryParameters.Skip(1).Take(1), options.UnsupportedSearchParams);
}

[Fact]
public void GivenSearchParametersWithEmptyKeyEmptyValue_WhenCreated_ThenSearchParameterShouldBeAddedToUnsupportedList()
{
var queryParameters = new[]
{
Tuple.Create(" ", "city"),
Tuple.Create(string.Empty, string.Empty),
};

SearchOptions options = CreateSearchOptions(ResourceType.Patient.ToString(), queryParameters);
Assert.NotNull(options);
Assert.NotNull(options.UnsupportedSearchParams);
Assert.Equal(2, options.UnsupportedSearchParams.Count);
Assert.Equal(queryParameters.Take(1), options.UnsupportedSearchParams.Take(1));
Assert.Equal(queryParameters.Skip(1).Take(1), options.UnsupportedSearchParams.Skip(1).Take(1));
}

[Fact]
public void GivenSearchParametersWithEmptyKeyEmptyValueWithAnotherValidParameter_WhenCreated_ThenSearchParameterShouldBeAddedToUnsupportedList()
{
var queryParameters = new[]
{
Tuple.Create("patient", "city"),
Tuple.Create(string.Empty, string.Empty),
};

SearchOptions options = CreateSearchOptions(ResourceType.Patient.ToString(), queryParameters);
Assert.NotNull(options);
Assert.NotNull(options.UnsupportedSearchParams);
Assert.Equal(1, options.UnsupportedSearchParams.Count);
Assert.Equal(queryParameters.Skip(1).Take(1), options.UnsupportedSearchParams);
}

[Fact]
public void GivenSearchParametersWithEmptyKeyEmptyValueWithAnotherInvalidParameter_WhenCreated_ThenSearchParameterShouldBeAddedToUnsupportedList()
{
var queryParameters = new[]
{
Tuple.Create(string.Empty, "city"),
Tuple.Create(string.Empty, string.Empty),
};

SearchOptions options = CreateSearchOptions(ResourceType.Patient.ToString(), queryParameters);
Assert.NotNull(options);
Assert.NotNull(options.UnsupportedSearchParams);
Assert.Equal(2, options.UnsupportedSearchParams.Count);
Assert.Equal(queryParameters.Take(1), options.UnsupportedSearchParams.Take(1));
Assert.Equal(queryParameters.Skip(1).Take(1), options.UnsupportedSearchParams.Skip(1).Take(1));
}

[Fact]
Expand Down

0 comments on commit f707061

Please sign in to comment.