protected override ILookupTemplate <IFhirTemplate> BuildCollectionTemplate(JArray templateCollection, ICollection <TemplateError> errors) { EnsureArg.IsNotNull(templateCollection, nameof(templateCollection)); EnsureArg.IsNotNull(errors, nameof(errors)); var lookupTemplate = new FhirLookupTemplate(); foreach (var token in templateCollection) { try { var container = token.ToObject <TemplateContainer>(); var createdTemplate = TemplateFactories.Evaluate(container); lookupTemplate.RegisterTemplate(createdTemplate); } catch (InvalidTemplateException ex) { errors.Add(new TemplateError(ex.Message)); } catch (JsonSerializationException ex) { errors.Add(new TemplateError(ex.Message)); } } return(lookupTemplate); }
protected override ILookupTemplate<IFhirTemplate> BuildCollectionTemplate(JArray templateCollection) { var lookupTemplate = new FhirLookupTemplate(); foreach (var token in templateCollection) { var container = token.ToObject<TemplateContainer>(); var createdTemplate = TemplateFactories.Evaluate(container); lookupTemplate.RegisterTemplate(createdTemplate); } return lookupTemplate; }
public void GivenDuplicateTemplates_WhenRegisterTemplate_InvalidOperationExceptionThrown_Test() { var template = new FhirLookupTemplate(); var templateA = Substitute.For <IFhirTemplate>(); templateA.TypeName.Returns("test"); var templateB = Substitute.For <IFhirTemplate>(); templateB.TypeName.Returns("test"); template.RegisterTemplate(templateA); Assert.Throws <InvalidTemplateException>(() => template.RegisterTemplate(templateB)); }
public void GivenUnregisteredTemplate_WhenGetTemplate_TemplateNotFoundExceptionThrown_Test() { var template = new FhirLookupTemplate(); var templateA = Substitute.For <IFhirTemplate>(); templateA.TypeName.Returns("a"); var templateB = Substitute.For <IFhirTemplate>(); templateB.TypeName.Returns("b"); template.RegisterTemplate(templateA); template.RegisterTemplate(templateB); Assert.Throws <TemplateNotFoundException>(() => template.GetTemplate("c")); }
public void GivenRegisteredTemplate_WhenGetTemplate_TemplateReturned_Test() { var template = new FhirLookupTemplate(); var templateA = Substitute.For <IFhirTemplate>(); templateA.TypeName.Returns("a"); var templateB = Substitute.For <IFhirTemplate>(); templateB.TypeName.Returns("b"); template.RegisterTemplate(templateA); template.RegisterTemplate(templateB); var returnTemplate = template.GetTemplate("a"); Assert.Equal(templateA, returnTemplate); returnTemplate = template.GetTemplate("b"); Assert.Equal(templateB, returnTemplate); }
protected override ILookupTemplate <IFhirTemplate> BuildCollectionTemplate(JArray templateCollection, ICollection <TemplateError> errors) { EnsureArg.IsNotNull(templateCollection, nameof(templateCollection)); EnsureArg.IsNotNull(errors, nameof(errors)); var lookupTemplate = new FhirLookupTemplate(); foreach (var token in templateCollection) { try { var container = token.ToObject <TemplateContainer>(); var createdTemplate = TemplateFactories.Evaluate(container); lookupTemplate.RegisterTemplate(createdTemplate); } catch (InvalidTemplateException ex) { errors.Add(new TemplateError(ex.Message, ex.GetLineInfo)); } catch (JsonSerializationException ex) { errors.Add(new TemplateError(ex.Message, new LineInfo() { LineNumber = ex.LineNumber, LinePosition = ex.LinePosition })); } catch (AggregateException ex) { foreach (var error in ex.ConvertExceptionToTemplateErrors()) { errors.Add(error); } } } return(lookupTemplate); }