public void Can_be_ceated_without_graph()
        {
            // when
            var triple = new EntityQuad(_entityId, _validSubject, _validPredicate, _validObject);

            // then
            Assert.That(triple.Graph, Is.Null);
        }
        public void Can_be_ceated_without_graph()
        {
            // when 
            var triple = new EntityQuad(_entityId, _validSubject, _validPredicate, _validObject);

            // then
            Assert.That(triple.Graph, Is.Null);
        }
        public void Created_triple_should_expose_its_terms()
        {
            // when
            var triple = new EntityQuad(_entityId, _validSubject, _validPredicate, _validObject, _graph);

            // then
            Assert.That(triple.Subject, Is.SameAs(_validSubject));
            Assert.That(triple.Predicate, Is.SameAs(_validPredicate));
            Assert.That(triple.Object, Is.SameAs(_validObject));
        }
        public void Created_triple_should_expose_its_terms()
        {
            // when
            var triple = new EntityQuad(_entityId, _validSubject, _validPredicate, _validObject, _graph);

            // then
            Assert.That(triple.Subject, Is.SameAs(_validSubject));
            Assert.That(triple.Predicate, Is.SameAs(_validPredicate));
            Assert.That(triple.Object, Is.SameAs(_validObject));
        }
        public void Triples_should_be_equal_when_id_and_nodes_are_equal()
        {
            // given
            IComparable triple = new EntityQuad(
                new EntityId(new Uri("urn:some:entity")),
                Node.ForUri(new Uri("urn:some:subject")),
                Node.ForUri(new Uri("urn:some:predicate")),
                Node.ForLiteral("10"));
            var otherTriple = new EntityQuad(
                new EntityId(new Uri("urn:some:entity")),
                Node.ForUri(new Uri("urn:some:subject")),
                Node.ForUri(new Uri("urn:some:predicate")),
                Node.ForLiteral("10"));

            // then
            Assert.That(triple.CompareTo(otherTriple), Is.EqualTo(0));
        }
        public void Triples_should_be_equal_when_id_and_nodes_are_equal()
        {
            // given
            IComparable triple = new EntityQuad(
                new EntityId(new Uri("urn:some:entity")),
                Node.ForUri(new Uri("urn:some:subject")),
                Node.ForUri(new Uri("urn:some:predicate")),
                Node.ForLiteral("10"));
            var otherTriple = new EntityQuad(
                new EntityId(new Uri("urn:some:entity")),
                Node.ForUri(new Uri("urn:some:subject")),
                Node.ForUri(new Uri("urn:some:predicate")),
                Node.ForLiteral("10"));

            // then
            Assert.That(triple.CompareTo(otherTriple), Is.EqualTo(0));
        }
Beispiel #7
0
        public void Replacing_triples_should_track_graph_change()
        {
            // given
            LoadEntities("TriplesWithLiteralSubjects.trig");
            var property = Node.ForUri(Foaf.givenName);
            var newValue = Node.ForLiteral("Tomek");

            // when
            _entityStore.ReplacePredicateValues(EntityId, property, () => new[] { newValue }, GraphUri, CultureInfo.InvariantCulture);

            // then
            _entityStore.Quads.Where(q => q.Graph.Uri == GraphUri).Should().HaveCount(6);
            var expectedAddedQuad   = new EntityQuad(EntityId, Node.FromEntityId(EntityId), property, newValue).InGraph(GraphUri);
            var expectedRemovedQuad = new EntityQuad(EntityId, Node.FromEntityId(EntityId), property, Node.ForLiteral("Tomasz")).InGraph(GraphUri);

            _changesTracker.Verify(
                c => c.Add(It.Is <GraphUpdate>(gu => gu.AddedQuads.Contains(expectedAddedQuad) && gu.RemovedQuads.Contains(expectedRemovedQuad))));
        }
Beispiel #8
0
 internal static bool PredicateIs(this EntityQuad quad, IEntityContext context, Uri type)
 {
     return((quad.Predicate.IsUri) && (!quad.Predicate.Uri.AbsoluteUri.StartsWith(EntityConverter.Hydra.AbsoluteUri)) &&
            (context.Load <IEntity>(new EntityId(quad.Predicate.Uri)).GetTypes().Any(currentType => AbsoluteUriComparer.Default.Equals(currentType.Uri, type))));
 }
        private void PrepareLists(EntityQuad list, IEnumerable<EntityQuad> quads, bool useNativeTypes)
        {
            Node localSubject = list.Subject;
            int anotherPropertyInList = quads.Count(q => q.Subject == localSubject && q.Predicate != RdfType);
            var firstValues = quads.Where(q => (q.Subject == localSubject && q.Predicate == RdfFirst)).Select(q => q.Object);
            Node firstValue = firstValues.First();
            Node restValue = list.Object;
            _listInGraph.AddFirst(ReturnListProperties(firstValue, useNativeTypes));
            _nodesInList.Add(localSubject);

            IEnumerable<EntityQuad> quad = quads.Where(q => (q.Subject.IsBlank && q.Predicate == RdfRest && q.Object == localSubject));
            if (anotherPropertyInList > 2 || firstValues.Count() > 1)
            {
                if (_listInGraph.Count() > 1)
                {
                    _listInGraph.First.Remove();
                    _nodesInList = _nodesInList.Where(n => n != localSubject).ToList();
                }

                _listInGraph.AddFirst(restValue.ToString());
            }
            else
                if (quad.Count() == 1)
                {
                    PrepareLists(quad.First(), quads, useNativeTypes);
                }
                else
                {
                    IEnumerable<EntityQuad> firstQuad = quads.Where(q => (q.Subject.IsBlank && q.Predicate == RdfFirst && q.Object == localSubject));
                    if (firstQuad.Count() == 1)
                    {
                        _listInGraph.First.Remove();
                        _nodesInList = _nodesInList.Where(n => n != localSubject).ToList();
                        _listInGraph.AddFirst((restValue.IsBlank && firstValue.IsBlank) ? localSubject.ToString() : restValue.ToString());
                    }
                    else
                    {
                        _listInGraph.AddFirst(localSubject.ToString());
                    }
                }
        }
        private void AddUnique(IDictionary<EntityId, IList<EntityQuad>> dictionary, EntityQuad item)
        {
            IList<EntityQuad> list = null;
            if (!dictionary.TryGetValue(item.EntityId, out list))
            {
                dictionary[item.EntityId] = list = new List<EntityQuad>();
            }

            AddUnique(list, item);
        }
 private void AddUnique(ICollection<EntityQuad> collection, EntityQuad item)
 {
     if (!collection.Contains(item))
     {
         collection.Add(item);
     }
 }
 private void DeleteQuad(EntityId parentEntityId, EntityQuad quad)
 {
     if (quad.Object.IsBlank)
     {
         if (!_entitiesReconstructed.ContainsKey(parentEntityId))
         {
             ReconstructEntity(parentEntityId);
         }
     }
     else
     {
         AddUnique(_quadsRemoved, quad);
     }
 }
        public void Creating_entity_should_populate_changeset_with_entity_type()
        {
            // given
            Mappings.Add(new DefaultGraphPersonMapping());
            var entityUri = new Uri("http://magi/people/Tomasz");
            var entityId = new EntityId(entityUri);

            // then
            EntityContext.Create<IPerson>(entityId);

            // then
            Assert.That(EntityContext.HasChanges);
            var newTriple = new EntityQuad(
                entityId,
                Node.ForUri(entityUri),
                Node.ForUri(Rdf.type),
                Node.ForUri(Foaf.Person),
                Node.ForUri(new Uri("http://data.magi/people/Tomasz")));
            EntityContext.Store.Changes.QuadsAdded.Should().Contain(newTriple);
        }
        public void ReplacePredicateValues(EntityId entityId, Node propertyUri, Func<IEnumerable<Node>> getNewValues, Uri graphUri)
        {
            _markedForDeletion = null;
            var subjectNode = Node.FromEntityId(entityId);
            RemoveTriples(entityId, subjectNode, propertyUri, graphUri);

            foreach (var valueNode in getNewValues())
            {
                var triple = new EntityQuad(entityId, subjectNode, propertyUri, valueNode).InGraph(graphUri);
                _entityQuads.Add(triple);
            }
        }
 // TODO: Make the GraphEquals method a bit less rigid.
 private bool GraphEquals(EntityQuad triple, Uri graph)
 {
     return (triple.Graph.Uri.AbsoluteUri == graph.AbsoluteUri) || ((triple.Subject.IsBlank) && (graph.AbsoluteUri.EndsWith(triple.Graph.Uri.AbsoluteUri)));
 }
        private void RemoveTriple(EntityQuad entityTriple)
        {
            _entityQuads.Remove(entityTriple);

            if (entityTriple.Object.IsBlank)
            {
                RemoveTriples(entityTriple.EntityId, entityTriple.Object);
            }
        }