예제 #1
0
파일: ResourceRefs.cs 프로젝트: mh2727/leaf
        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;
        }
예제 #2
0
            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();
            }
예제 #3
0
파일: UrnTests.cs 프로젝트: uwrit/leaf
        public void Urn_TryParseUrn_Malformed_Err()
        {
            var val = "urn:leaf:";

            var ok = Urn.TryParse(val, out var urn);

            Assert.False(ok);
        }
예제 #4
0
파일: UrnTests.cs 프로젝트: uwrit/leaf
        public void Urn_TryParseUrn_ResourceMissing_Err()
        {
            var val = "urn:leaf:test:other_stuff";

            var ok = Urn.TryParse(val, out var urn);

            Assert.False(ok);
        }
예제 #5
0
            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");
            }
예제 #6
0
            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");
            }
예제 #7
0
파일: UrnTests.cs 프로젝트: uwrit/leaf
        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);
        }
예제 #8
0
파일: UrnTests.cs 프로젝트: uwrit/leaf
        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);
        }
예제 #10
0
        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>();
        }
예제 #11
0
 public void TryParseCorrectly()
 {
     Urn.TryParse("value", out _).Should().BeFalse();
     Urn.TryParse("urn:value", out _).Should().BeTrue();
 }
예제 #12
0
 public static bool IsUrn(this string value) => Urn.TryParse(value, out _);