예제 #1
0
        public void CrUD_Nodes()
        {
            using (GraphContext ctx = Fixture.GetService <GlobalTestContext>())
            {
                Symbol s    = new Symbol();
                Book   book = new Book()
                {
                    Name = "Prova"
                };

                book = ctx.Add(book);

                book.Index = 1;

                Assert.Equal(
                    0,
                    ctx.Runner.ExecuteQuery <IOgmEntity>($"MATCH {new Node(s, type: typeof(Book), props: new { Name = "Prova" }.ToPropDictionary()).BuildForQuery()} RETURN {s}")
                    .Count()
                    );

                ctx.SaveChanges();

                Assert.Equal(
                    1,
                    ctx.Runner.ExecuteQuery <IOgmEntity>($"MATCH {new Node(s, type: typeof(Book), props: new { Name = "Prova" }.ToPropDictionary()).BuildForQuery()} RETURN {s}")
                    .Count()
                    );

                book.Name = "Prova 2";

                ctx.SaveChanges();
                Assert.Equal(
                    0,
                    ctx.Runner.ExecuteQuery <IOgmEntity>($"MATCH {new Node(s, type: typeof(Book), props: new { Name = "Prova" }.ToPropDictionary()).BuildForQuery()} RETURN {s}")
                    .Count()
                    );
                Assert.Equal(
                    1,
                    ctx.Runner.ExecuteQuery <IOgmEntity>($"MATCH {new Node(s, type: typeof(Book), props: new { Name = "Prova 2" }.ToPropDictionary()).BuildForQuery()} RETURN {s}")
                    .Count()
                    );

                ctx.Remove(book);

                ctx.SaveChanges();
                Assert.Equal(
                    0,
                    ctx.Runner.ExecuteQuery <IOgmEntity>($"MATCH {new Node(s, type: typeof(Book), props: new { Name = "Prova 2" }.ToPropDictionary()).BuildForQuery()} RETURN {s}")
                    .Count()
                    );
            }
        }
예제 #2
0
        public void Complex_Graph()
        {
            TestEntityManager testManager = new TestEntityManager();

            using (GraphContext ctx = GetContext(testManager))
            {
                Book orgBook;
                Book book = new Book()
                {
                    Name = "Prova"
                };
                orgBook = book;

                book = ctx.Add(book);

                book.Index = 1;

                Assert.Empty(testManager.CreatedNodes);

                ctx.SaveChanges();

                Assert.Equal(1, testManager.CreatedNodes.Count);
                Assert.Equal("Prova", testManager.CreatedNodes[0].Item1.GetPropValue("Name"));

                Chapter chapter1 = new Chapter()
                {
                    Name = "Capitolo 1"
                };
                Chapter chapter2 = new Chapter()
                {
                    Name = "Capitolo 2"
                };

                book.Chapters.Add(chapter1);
                Assert.Equal(book, chapter1.Book);

                ctx.SaveChanges();

                Assert.Equal(1, testManager.ConnectionMerge.Count(p => p.Item1.Source == book));

                chapter2.Book = book;
                Assert.Equal(2, book.Chapters.Count());
                Assert.True(book.Chapters.Contains(chapter2));

                ctx.SaveChanges();

                Assert.Equal(2, testManager.ConnectionMerge.Count(p => p.Item1.Source == book));
            }
        }
예제 #3
0
        public void CrUD_Nodes()
        {
            TestEntityManager testManager = new TestEntityManager();

            using (GraphContext ctx = GetContext(testManager))
            {
                Symbol s = new Symbol();
                Book   orgBook;
                Book   book = new Book()
                {
                    Name = "Prova"
                };
                orgBook = book;

                book = ctx.Add(book);

                book.Index = 1;

                Assert.Empty(testManager.CreatedNodes);

                ctx.SaveChanges();

                Assert.Equal(1, testManager.CreatedNodes.Count);
                Assert.Equal("Prova", testManager.CreatedNodes[0].Item1.GetPropValue("Name"));

                book.Name = "Prova 2";

                ctx.SaveChanges();

                Assert.Empty(testManager.CreatedNodes);
                Assert.Equal(1, testManager.UpdatedNodes.Count);
                Assert.Equal("Prova 2", testManager.UpdatedNodes[0].Item1.GetPropValue("Name"));
                Assert.True(testManager.UpdatedNodes[0].Item2.Count() > 0 && !testManager.UpdatedNodes[0].Item2.Contains("Name"));

                ctx.Remove(book);

                ctx.SaveChanges();

                Assert.Empty(testManager.CreatedNodes);
                Assert.Empty(testManager.UpdatedNodes);
                Assert.Equal(1, testManager.DeletedNodes.Count);

                Assert.Equal(orgBook, testManager.DeletedNodes[0]);
            }
        }
예제 #4
0
        public void InsertionAndDeletion()
        {
            IGraphContext context = new GraphContext();
            var           query   = context.Select <RdfPropertyWithRange>();

            int i = 0;

            foreach (var item in query)
            {
                i++;
            }

            Assert.Equal(181, i);

            var prop = new RdfPropertyWithRange("http://example.org/exampleprop");

            prop.Range = new RdfClass("http://example.org/exampleclass");

            context.Add(prop);

            i = 0;
            foreach (var item in query)
            {
                i++;
            }

            Assert.Equal(183, i);

            var graph = new LabelledTreeNode <object, Term>(prop);

            graph.AddChild(new Rdfs("range"), new RdfClass("http://example.org/exampleclass"));

            context.Remove(graph);

            i = 0;
            foreach (var item in query)
            {
                i++;
            }

            Assert.Equal(181, i);
        }