Ejemplo n.º 1
0
        public async Task ShouldReturnEmptyVertices()
        {
            var query = new InternalGraphQuery()
            {
                NetworkId = _fake.Network.Id,
            };
            var result = await _handler.Execute(query);

            var expected = new PropertyGraphModel()
            {
                Vertices = new List <PropertyVertexModel>()
                {
                    new PropertyVertexModel()
                    {
                        Id = _fake.AdminVertex.Id
                    },
                    new PropertyVertexModel()
                    {
                        Id = _fake.OtherVertex.Id
                    },
                },
                Edges = new List <PropertyEdgeModel>()
            };

            PropertyGraphAssertions.AssertGraphsEqual(expected, result.Snapshot());
        }
Ejemplo n.º 2
0
        public async Task ShouldReturnVerticesWithPropsAndIgnoreRedundantSchema()
        {
            _repo.Db.VertexProperties.Add(new VertexProperty()
            {
                VertexId  = _fake.AdminVertex.Id,
                Created   = _fake.Clock.TimeStamp,
                Id        = Guid.NewGuid(),
                JsonValue = "\"Jan\"",
                SchemaUri = "first_name"
            });

            _repo.Db.SaveChanges();

            _graphSchema.VertexSchema.Add(new GraphProfileSectionModel()
            {
                Name        = "Wizytowka",
                Uri         = "wizytowka",
                PropsSchema = new List <GraphPropertySchemaModel>()
                {
                    new GraphPropertySchemaModel()
                    {
                        Name = "First name",
                        Uri  = "first_name"
                    },
                    new GraphPropertySchemaModel()
                    {
                        Name = "Last name",
                        Uri  = "last_name"
                    }
                }
            });

            var query = new InternalGraphQuery()
            {
                NetworkId = _fake.Network.Id,
            };
            var result = await _handler.Execute(query);

            var expected = new PropertyGraphModel()
            {
                Vertices = new List <PropertyVertexModel>()
                {
                    new PropertyVertexModel()
                    {
                        Id    = _fake.AdminVertex.Id,
                        Props = new Dictionary <string, object>()
                        {
                            { "First name", "Jan" }
                        }
                    },
                    new PropertyVertexModel()
                    {
                        Id = _fake.OtherVertex.Id
                    },
                },
                Edges = new List <PropertyEdgeModel>()
            };

            PropertyGraphAssertions.AssertGraphsEqual(expected, result.Snapshot());
        }
Ejemplo n.º 3
0
        public async Task ShouldSkipEdgesOutsideSchema()
        {
            var edge = new Edge()
            {
                Id             = Guid.NewGuid(),
                SourceVertexId = _fake.AdminVertex.Id,
                TargetVertexId = _fake.OtherVertex.Id,
                Created        = DateTime.Now,
                SchemaUri      = "wiedza"
            };

            _repo.Db.Edges.Add(edge);

            _repo.Db.SaveChanges();

            _graphSchema.EdgeSchema.Add(new GraphRelationshipSchemaModel()
            {
                Name        = "Współpraca",
                Uri         = "wspolpraca",
                PropsSchema = new List <GraphPropertySchemaModel>()
                {
                    new GraphPropertySchemaModel()
                    {
                        Name = "Value",
                        Uri  = "wspolpraca/value"
                    }
                }
            });
            var query = new InternalGraphQuery()
            {
                NetworkId = _fake.Network.Id,
            };
            var result = await _handler.Execute(query);

            var expected = new PropertyGraphModel()
            {
                Vertices = new List <PropertyVertexModel>()
                {
                    new PropertyVertexModel()
                    {
                        Id = _fake.AdminVertex.Id
                    },
                    new PropertyVertexModel()
                    {
                        Id = _fake.OtherVertex.Id
                    },
                },
                Edges = new List <PropertyEdgeModel>()
            };

            PropertyGraphAssertions.AssertGraphsEqual(expected, result.Snapshot());
        }
Ejemplo n.º 4
0
        public async Task ShouldReturnEdgePropsFirstFoundInSchema()
        {
            var edge = new Edge()
            {
                Id             = Guid.NewGuid(),
                SourceVertexId = _fake.AdminVertex.Id,
                TargetVertexId = _fake.OtherVertex.Id,
                Created        = DateTime.Now,
                SchemaUri      = "wspolpraca"
            };

            _repo.Db.Edges.Add(edge);

            _repo.Db.EdgeProperties.Add(new EdgeProperty()
            {
                Id        = Guid.NewGuid(),
                EdgeId    = edge.Id,
                SchemaUri = "survey/wspolpraca/value",
                JsonValue = "5",
                Created   = DateTime.Now,
                Deleted   = null
            });

            _repo.Db.EdgeProperties.Add(new EdgeProperty()
            {
                Id        = Guid.NewGuid(),
                EdgeId    = edge.Id,
                SchemaUri = "connector/wspolpraca/value",
                JsonValue = "0",
                Created   = DateTime.Now,
                Deleted   = null
            });

            _repo.Db.SaveChanges();

            _graphSchema.EdgeSchema.Add(new GraphRelationshipSchemaModel()
            {
                Name        = "Współpraca",
                Uri         = "wspolpraca",
                PropsSchema = new List <GraphPropertySchemaModel>()
                {
                    new GraphPropertySchemaModel()
                    {
                        Name = "Value",
                        Uri  = "survey/wspolpraca/value"
                    },
                    new GraphPropertySchemaModel()
                    {
                        Name = "Value",
                        Uri  = "connector/wspolpraca/value"
                    }
                }
            });
            var query = new InternalGraphQuery()
            {
                NetworkId = _fake.Network.Id,
            };
            var result = await _handler.Execute(query);

            var expected = new PropertyGraphModel()
            {
                Vertices = new List <PropertyVertexModel>()
                {
                    new PropertyVertexModel()
                    {
                        Id = _fake.AdminVertex.Id
                    },
                    new PropertyVertexModel()
                    {
                        Id = _fake.OtherVertex.Id
                    },
                },
                Edges = new List <PropertyEdgeModel>()
                {
                    new PropertyEdgeModel()
                    {
                        Name   = "Współpraca",
                        Source = 0,
                        Target = 1,
                        Props  = new Dictionary <string, object>()
                        {
                            { "Value", 5 }
                        }
                    }
                }
            };

            PropertyGraphAssertions.AssertGraphsEqual(expected, result.Snapshot());

            _graphSchema.EdgeSchema[0].PropsSchema = new List <GraphPropertySchemaModel>()
            {
                new GraphPropertySchemaModel()
                {
                    Name = "Value",
                    Uri  = "connector/wspolpraca/value"
                },
                new GraphPropertySchemaModel()
                {
                    Name = "Value",
                    Uri  = "survey/wspolpraca/value"
                }
            };

            expected.Edges.First().Props = new Dictionary <string, object>()
            {
                { "Value", 0 }
            };
        }
Ejemplo n.º 5
0
        public async Task ShouldExtractNameFromVertexPropsOutsideSchema()
        {
            _repo.Db.VertexProperties.Add(new VertexProperty()
            {
                VertexId  = _fake.AdminVertex.Id,
                Created   = _fake.Clock.TimeStamp,
                Id        = Guid.NewGuid(),
                JsonValue = "\"Jan\"",
                SchemaUri = "first_name"
            });

            _repo.Db.VertexProperties.Add(new VertexProperty()
            {
                VertexId  = _fake.AdminVertex.Id,
                Created   = _fake.Clock.TimeStamp,
                Id        = Guid.NewGuid(),
                JsonValue = "\"Kowalski\"",
                SchemaUri = "Last name"
            });

            _repo.Db.VertexProperties.Add(new VertexProperty()
            {
                VertexId  = _fake.AdminVertex.Id,
                Created   = _fake.Clock.TimeStamp,
                Id        = Guid.NewGuid(),
                JsonValue = "\"Marketing\"",
                SchemaUri = "e8fc9157-c17e-49d8-b62b-1a0c6000955d/Dział"
            });

            _repo.Db.SaveChanges();

            _graphSchema.VertexSchema.Add(new GraphProfileSectionModel()
            {
                Name        = "Wizytowka",
                Uri         = "wizytowka",
                PropsSchema = new List <GraphPropertySchemaModel>()
                {
                    new GraphPropertySchemaModel()
                    {
                        Name = "First name",
                        Uri  = "first_name"
                    }
                }
            });

            var query = new InternalGraphQuery()
            {
                NetworkId = _fake.Network.Id,
            };
            var result = await _handler.Execute(query);

            var expected = new PropertyGraphModel()
            {
                Vertices = new List <PropertyVertexModel>()
                {
                    new PropertyVertexModel()
                    {
                        Id    = _fake.AdminVertex.Id,
                        Props = new Dictionary <string, object>()
                        {
                            { "First name", "Jan" },
                            { "Last name", "Kowalski" },
                            { "Dział", "Marketing" }
                        }
                    },
                    new PropertyVertexModel()
                    {
                        Id = _fake.OtherVertex.Id
                    },
                },
                Edges = new List <PropertyEdgeModel>()
            };

            PropertyGraphAssertions.AssertGraphsEqual(expected, result.Snapshot());
        }