internal override ResourceElement GetPatchedResourceElement(ResourceWrapper resourceToPatch) { Resource resourcePoco; try { resourcePoco = resourceToPatch.RawResource .ToITypedElement(ModelInfoProvider.Instance) .ToPoco <Resource>(); } catch (Exception e) { throw new RequestNotValidException(string.Format(Core.Resources.PatchResourceError, e.Message)); } try { Resource patchedResource = new FhirPathPatchBuilder(resourcePoco, FhirPatchParameters).Apply(); return(patchedResource.ToResourceElement()); } catch (InvalidOperationException e) { // Invalid patch input throw new RequestNotValidException(e.Message); } catch (FormatException e) { // Invalid output POCO throw new RequestNotValidException(e.Message); } }
public void GivenAFhirPatchReplaceRequest_WhenGivenInvalidPath_ThenInvalidOperationExceptionIsThrown() { var patchParam = new Parameters().AddReplacePatchParameter("Patient.none", new FhirString("nothing")); var patchOperation = new FhirPathPatchBuilder(new Patient(), patchParam); Assert.Throws <InvalidOperationException>(patchOperation.Apply); }
public void GivenAFhirPatchInsertRequest_WhenInsertingInvalidPath_ThenInvalidOperationExceptionShouldBeThrown() { var patchParam = new Parameters().AddInsertPatchParameter("Patient.nothing", new FhirString("test"), 2); var builder = new FhirPathPatchBuilder(new Patient(), patchParam); Assert.Throws <InvalidOperationException>(builder.Apply); }
public void GivenAFhirPatchMoveRequest_WhenMovingOnUninitializedPath_ThenInvalidOperationExceptionIsThrown() { var patchParam = new Parameters().AddMovePatchParameter("Patient.identifier", 0, 0); var builder = new FhirPathPatchBuilder(new Patient(), patchParam); Assert.Throws <InvalidOperationException>(builder.Apply); }
public void GivenAFhirPatchInsertRequest_WhenInsertingToUninitializedList_ThenInvalidOperationExceptionShouldBeThrown() { var patchParam = new Parameters().AddInsertPatchParameter("Patient.identifier", new Identifier { System = "http://example.org", Value = "new value" }, 0); var builder = new FhirPathPatchBuilder(new Patient(), patchParam); Assert.Throws <InvalidOperationException>(builder.Apply); }
public void GivenAFhirPatchInsertRequest_WhenInsertingWithNegativeIndex_ThenInvalidOperationExceptionShouldBeThrown() { var patchParam = new Parameters().AddInsertPatchParameter("Patient.identifier", new Identifier { System = "http://example.org", Value = "value 3" }, -1); var patientResource = new Patient { Identifier = new List <Identifier> { new Identifier { System = "http://example.org", Value = "value 1" }, }, }; var builder = new FhirPathPatchBuilder(patientResource, patchParam); Assert.Throws <InvalidOperationException>(builder.Apply); }
public void GivenAFhirPatchMoveRequest_WhenMovingToInvalidIndex_ThenInvalidOperationExceptionIsThrown() { var patchParam = new Parameters().AddMovePatchParameter("Patient.identifier", 0, 3); var patientResource = new Patient { Identifier = new List <Identifier> { new Identifier { System = "http://example.org", Value = "value 1" }, new Identifier { System = "http://example.org", Value = "value 2" }, new Identifier { System = "http://example.org", Value = "value 3" }, }, }; var builder = new FhirPathPatchBuilder(patientResource, patchParam); Assert.Throws <InvalidOperationException>(builder.Apply); }