public ResourceRefs(IEnumerable <ResourceRef> refs) { var concepts = new List <ConceptRef>(); var queries = new List <QueryRef>(); foreach (var res in refs) { if (!res.UseUniversalId()) { concepts.Add(new ConceptRef(res.Id.Value.ToString())); continue; } if (!Urn.TryParse(res.UniversalId, out var urn)) { throw new FormatException($"{res.UniversalId} is not mapped to an embeddable resource"); } switch (urn) { case ConceptUrn concept: concepts.Add(new ConceptRef { UniversalId = concept, Id = res.Id }); break; case QueryUrn query: queries.Add(new QueryRef { UniversalId = query, Id = res.Id }); break; } } Concepts = concepts; Queries = queries; }
public void Should_return_error_when_given_an_invalid_string(string value) { var success = Urn.TryParse(value, out var urn); success.Should().BeFalse(); urn.Should().BeNull(); }
public void Urn_TryParseUrn_Malformed_Err() { var val = "urn:leaf:"; var ok = Urn.TryParse(val, out var urn); Assert.False(ok); }
public void Urn_TryParseUrn_ResourceMissing_Err() { var val = "urn:leaf:test:other_stuff"; var ok = Urn.TryParse(val, out var urn); Assert.False(ok); }
public void Should_return_successfully_parse_URN_with_namespace_specific_string_only() { var success = Urn.TryParse("urn:ns:val", out var urn); success.Should().BeTrue(); urn.Nid.Should().Be("ns"); urn.Nss.Should().Be("val"); }
public void Should_return_successfully_parse_full_URN() { var success = Urn.TryParse("urn:ns:val", out var urn); success.Should().BeTrue(); urn.Nid.Should().Be("ns"); urn.Nss.Should().Be("val"); }
public void Urn_TryParseUrn_QueryUrn_Ok() { var val = $"urn:leaf:query:{Guid.NewGuid()}:12318742"; var ok = Urn.TryParse(val, out var urn); Assert.True(ok); Assert.IsType <QueryUrn>(urn); }
public void Urn_TryParseUrn_ConceptUrn_Ok() { var val = "urn:leaf:concept:diag:codeset=ICD9+code=123.42"; var ok = Urn.TryParse(val, out var urn); Assert.True(ok); Assert.IsType <ConceptUrn>(urn); }
protected override ImmutableArray <ValidationError> DoValidate(string type, string?value) { if (value is null) { return(new[] { new ValidationError("Value is null") }.ToImmutableArray()); } if (string.IsNullOrWhiteSpace(value)) { return(new[] { new ValidationError("Value is not a valid URN, current value only contains white-spaces") } .ToImmutableArray()); } if (!Urn.TryParse(value, out _)) { return(new[] { new ValidationError($"'{value}' is not a valid URN") }.ToImmutableArray()); } return(ImmutableArray <ValidationError> .Empty); }
public ConceptDatasetQueryDTO(string queryId, string conceptId) { var res = new ResourceRef(); if (Urn.TryParse(conceptId, out var urn)) { res.UniversalId = urn.Value; } else { res.Id = new Guid(conceptId); } var panel = new PanelDTO { SubPanels = new List <SubPanelDTO> { new SubPanelDTO { PanelItems = new List <PanelItemDTO> { new PanelItemDTO { Resource = res } } } } }; QueryId = queryId; Panels = new List <PanelDTO> { panel }; PanelFilters = new List <PanelFilterDTO>(); }
public void TryParseCorrectly() { Urn.TryParse("value", out _).Should().BeFalse(); Urn.TryParse("urn:value", out _).Should().BeTrue(); }
public static bool IsUrn(this string value) => Urn.TryParse(value, out _);