Пример #1
0
        public void it_should_match_uri()
        {
            var entityId = new EntityId((Uri)(BaseUri + EntryPoint).AddSegment(Guid.Empty.ToString()));

            Uri result = _selector.SelectGraph(entityId, null, null);

            result.Should().Be(entityId.Uri);
        }
Пример #2
0
        /// <inheritdoc />
        public IEntity Resolve(EntityId id)
        {
            if ((id is BlankId) || (!id.Uri.Scheme.ToLower().StartsWith("http")))
            {
                throw new ArgumentOutOfRangeException("id");
            }

            if (!_baseUris.Any(uri => id.Uri.AbsoluteUri.StartsWith(uri.AbsoluteUri)))
            {
                return(null);
            }

            if (_dereferencedResources.Contains(id.Uri.AbsoluteUri))
            {
                return(_entityContext.Value.Load <IEntity>(id));
            }

            Uri dereferencableUri = id.Uri.GetUriWithoutQuery();
            var graphUri          = _namedGraphSelector.SelectGraph(id, null, null);
            var graph             = _tripleStore.Graphs.FirstOrDefault(item => AbsoluteUriComparer.Default.Equals(item.BaseUri, graphUri));

            if (graph == null)
            {
                _tripleStore.Add(graph = new Graph()
                {
                    BaseUri = graphUri
                });
            }

            var resourceGraph = ObtainResourceData(dereferencableUri);

            AssertGraph(resourceGraph, graph);
            return(_entityContext.Value.Load <IEntity>(id));
        }
        public void Should_provide_graph_name_correctly(string resourceUri, bool isBlankId)
        {
            var id = new EntityId(new Uri(BaseUri));

            if (isBlankId)
            {
                id = new BlankId("bnode001", id);
            }

            var result = _graphSelector.SelectGraph(id, null, null);

            result.Should().Be(new Uri(BaseUri));
        }
        private void AssertEntityTypes(Entity entity, IEntityMapping entityMapping)
        {
            Uri graphName       = (_graphSelector != null ? _graphSelector.SelectGraph(entity.Id, _typedEntityMapping, _typesPropertyMapping) : null);
            var currentTypes    = _store.GetObjectsForPredicate(entity.Id, Vocabularies.Rdf.type, graphName);
            var additionalTypes = (from @class in entityMapping.Classes
                                   let additionalType = Model.Node.ForUri(@class.Uri)
                                                        where !currentTypes.Contains(additionalType)
                                                        select additionalType).ToList();

            if (additionalTypes.Count > 0)
            {
                _store.ReplacePredicateValues(
                    entity.Id,
                    Model.Node.ForUri(Vocabularies.Rdf.type),
                    () => currentTypes.Union(additionalTypes),
                    graphName,
                    entity.Context.CurrentCulture);
            }
        }