예제 #1
0
        public void Should_be_mergable_with_update()
        {
            // when
            var reconstruct = new GraphReconstruct(EntityId, GraphId, new EntityQuad[0]);
            var update      = new GraphUpdate(EntityId, GraphId, new EntityQuad[0], new EntityQuad[0]);

            // then
            reconstruct.CanMergeWith(update).Should().BeTrue();
        }
예제 #2
0
        public void Should_remove_duplicate_added_quads()
        {
            // given
            var addedQuads = new[] { AQuad, AQuad, AQuad, AQuad };

            // when
            var update = new GraphUpdate(EntityId, GraphId, new EntityQuad[0], addedQuads);

            // then
            update.AddedQuads.Should().HaveCount(1);
            update.RemovedQuads.Should().BeEmpty();
        }
        public void Should_create_correct_command_for_graph_update_in_case_of_an_created_blank_node()
        {
            // given
            var update = new GraphUpdate(EntityId, EntityGraph, new EntityQuad[0], new[] { BQuad });

            // when
            var commands = _commandFactory.CreateCommands(update).ToList();

            // then
            commands.Should().HaveCount(1);
            commands[0].Should().BeOfType <InsertDataCommand>();
        }
예제 #4
0
        public void Should_ignore_empty_changes()
        {
            // given
            var change = new GraphUpdate(Entity, GraphA, new EntityQuad[0], new EntityQuad[0]);

            // when
            _changes.Add(change);

            // then
            _changes.HasChanges.Should().BeFalse();
            _changes.Should().HaveCount(0);
        }
예제 #5
0
        public override void UpdateGraph(Node node, GraphUpdate.UpdateType type)
        {
            GraphUpdate update = new GraphUpdate()
            {
                updatetype = type, node = node
            };

            _waitingGraphUpdates.Enqueue(new GraphUpdate()
            {
                updatetype = type, node = node
            });
        }
예제 #6
0
        public void Should_be_mergeable_with_another()
        {
            // given
            var removedQuads = new[] { AQuad };
            var addedQuads   = new[] { AQuad, BQuad };

            // when
            var update = new GraphUpdate(EntityId, GraphId, removedQuads, addedQuads);
            var other  = new GraphUpdate(EntityId, GraphId, removedQuads, addedQuads);

            // then
            update.CanMergeWith(other).Should().BeTrue();
        }
예제 #7
0
        public void Should_cancel_out_quads_both_delete_and_added()
        {
            // given
            var removedQuads = new[] { AQuad };
            var addedQuads   = new[] { AQuad, BQuad };

            // when
            var update = new GraphUpdate(EntityId, GraphId, removedQuads, addedQuads);

            // then
            update.AddedQuads.Single().Should().Be(BQuad);
            update.RemovedQuads.Should().BeEmpty();
        }
예제 #8
0
        private DatasetChange CreateChangeForUpdate(EntityId entityId, EntityId graphUri, IEntityQuad[] removedQuads, IEntityQuad[] addedQuads)
        {
            var update = new GraphUpdate(entityId, graphUri, removedQuads, addedQuads);

            if (update.RemovedQuads.Any(q => q.Subject.IsBlank || q.Object.IsBlank))
            {
                var graphQuads = from entityQuad in GetEntityQuads(entityId is BlankId ? ((BlankId)entityId).RootEntityId : entityId)
                                 where entityQuad.Graph.Equals(Node.FromEntityId(graphUri))
                                 select entityQuad;
                return(new GraphReconstruct(entityId, graphUri, graphQuads));
            }

            return(update);
        }
예제 #9
0
        public void Merging_should_combine_two_updates()
        {
            // given
            var removedQuads = new[] { AQuad };
            var addedQuads   = new[] { CQuad, BQuad };
            var update       = new GraphUpdate(EntityId, GraphId, removedQuads, new EntityQuad[0]);
            var other        = new GraphUpdate(EntityId, GraphId, removedQuads, addedQuads);

            // when
            var merged = (GraphUpdate)update.MergeWith(other);

            // then
            merged.AddedQuads.Should().Contain((IEnumerable)addedQuads);
            merged.RemovedQuads.Should().Contain((IEnumerable)removedQuads);
        }
        public void Should_create_correct_command_for_graph_update_in_case_of_a_deleted_blank_node()
        {
            // given
            var update = new GraphUpdate(EntityId, EntityGraph, new[] { AQuad }, new EntityQuad[0]);

            // when
            var commands = _commandFactory.CreateCommands(update).ToList();

            // then
            commands.Should().HaveCount(2);
            commands[0].Should().BeOfType <DeleteCommand>();
            commands[1].Should().BeOfType <InsertDataCommand>();
            commands[1].AffectsGraph(new Uri(EntityGraph)).Should().BeFalse();
            commands[1].AffectsGraph(MetaGraphUri).Should().BeTrue();
        }
        public void Should_create_modify_command_for_GraphUpdate()
        {
            // given
            var update = new GraphUpdate(EntityId, EntityGraph, new[] { AQuad }, new[] { BQuad });

            // when
            var commands = _commandFactory.CreateCommands(update).ToList();

            // then
            commands.Should().HaveCount(2);
            commands[0].Should().BeOfType <DeleteCommand>();
            commands[0].AffectsSingleGraph.Should().BeTrue();
            commands[0].AffectsGraph(new Uri(EntityGraph)).Should().BeTrue();
            commands[1].Should().BeOfType <InsertDataCommand>();
        }
예제 #12
0
        public void Merging_should_combine_recreate_graph_with_update()
        {
            // given
            var newGraph     = new[] { AQuad, CQuad };
            var removedQuads = new[] { AQuad };
            var addedQuads   = new[] { CQuad, BQuad };
            var update       = new GraphReconstruct(EntityId, GraphId, newGraph);
            var other        = new GraphUpdate(EntityId, GraphId, removedQuads, addedQuads);

            // when
            var merged = (GraphReconstruct)update.MergeWith(other);

            // then
            merged.AddedQuads.Should().Contain((IEnumerable)addedQuads);
        }
예제 #13
0
        private IEnumerable <SparqlUpdateCommand> CreateGraphUpdateCommand(GraphUpdate change)
        {
            INodeFactory factory        = new NodeFactory();
            var          removedTriples = ConvertTriples(change.RemovedQuads, factory).Replace("\\u", "\\\\u");
            var          addedTriples   = ConvertTriples(change.AddedQuads, factory).Replace("\\u", "\\\\u");

            var format      = change.Entity is BlankId ? InsterBlankEntityCommandText : ModifyEntityCommandText;
            var commandText = string.Format(format, removedTriples, addedTriples);
            var commands    = new SparqlParameterizedString(commandText);

            commands.SetUri("graph", change.Graph.Uri);

            if (!(change.Entity is BlankId))
            {
                commands.SetUri("metaGraph", MetaGraphUri);
                commands.SetUri("entity", change.Entity.Uri);
            }

            return(GetParsedCommands(commands));
        }