Example #1
0
        public void TestGetMatchesWithDifferentTriplePatterns()
        {
            var c = new TripleCollection();

            c.AddRange(new [] { T1, T2, T3, T4, T5, T6 });
            Assert.AreEqual(1, c.GetMatches(new Triple {
                Subject = "http://example.org/s", Predicate = "http://example.org/p", Object = "http://example.org/o", Graph = Constants.DefaultGraphUri
            }).Count(),
                            "Expected 1 match with fully-specified pattern");
            Assert.AreEqual(2, c.GetMatches(new Triple {
                Subject = "http://example.org/s", Predicate = "http://example.org/p", Object = "http://example.org/o", Graph = null
            }).Count(),
                            "Expected two matches with graph wildcard.");
            // With Triple.Match an object wildcard matches literals and non-literals alike
            Assert.AreEqual(3, c.GetMatches(new Triple {
                Subject = "http://example.org/s", Predicate = "http://example.org/p", Object = null, Graph = Constants.DefaultGraphUri
            }).Count(),
                            "Expected 3 matches with object wildcard");
            Assert.AreEqual(2, c.GetMatches(new Triple {
                Subject = "http://example.org/s", Predicate = null, Object = "http://example.org/o", Graph = Constants.DefaultGraphUri
            }).Count(),
                            "Expected 2 matches with predicate wildcard");
            Assert.AreEqual(2, c.GetMatches(new Triple {
                Subject = null, Predicate = "http://example.org/p", Object = "http://example.org/o", Graph = Constants.DefaultGraphUri
            }).Count(),
                            "Expected 2 matches with subject wildcard");
        }
Example #2
0
        public void TestGetMatchesBySubject()
        {
            var c = new TripleCollection();

            c.AddRange(new[] { T1, T2, T3, T4, T5, T6 });
            Assert.AreEqual(5, c.GetMatches("http://example.org/s").Count());
            Assert.AreEqual(1, c.GetMatches("http://example.org/s1").Count());
        }
Example #3
0
        public void TestContainsSubject()
        {
            var c = new TripleCollection();

            c.AddRange(new[] { T1, T2, T3, T4, T5, T6 });
            Assert.IsTrue(c.ContainsSubject("http://example.org/s"));
            Assert.IsTrue(c.ContainsSubject("http://example.org/s1"));
            Assert.IsFalse(c.ContainsSubject("http://example.org/p"));
        }
Example #4
0
        public void TestRemoveByObjectDoesNotRemoveLiteralMatches()
        {
            var c = new TripleCollection();

            c.AddRange(new[] { T2, T3 });
            c.RemoveByObject("http://example.org/o");
            Assert.AreEqual(1, c.Count());
            Assert.IsTrue(c.Items.Any(x => x.Equals(T3)));
        }
Example #5
0
        public void TestRemoveBySubjectPredicateLiteralDoesNotRemoveUriMatches()
        {
            var c = new TripleCollection();

            c.AddRange(new[] { T2, T3 });
            c.RemoveBySubjectPredicateLiteral("http://example.org/s", "http://example.org/p", "http://example.org/o", RdfDatatypes.String, null);
            Assert.AreEqual(1, c.Count());
            Assert.IsTrue(c.Items.Any(x => x.Equals(T2)));
        }
Example #6
0
        public void TestAddRangeUpdatesCollection()
        {
            var c = new TripleCollection();

            c.AddRange(new [] { T1, T2, T3 });
            Assert.AreEqual(3, c.Count());
            Assert.IsTrue(c.Items.Any(x => x.Equals(T1)));
            Assert.IsTrue(c.Items.Any(x => x.Equals(T2)));
            Assert.IsTrue(c.Items.Any(x => x.Equals(T3)));
        }
Example #7
0
        public void TestRemoveBySubjectPredicateRemoveAllMatches()
        {
            var c = new TripleCollection();

            c.AddRange(new [] { T1, T5 });
            Assert.AreEqual(2, c.Count());
            c.RemoveBySubjectPredicate("http://example.org/s", "http://example.org/p1");
            Assert.AreEqual(1, c.Count());
            Assert.IsTrue(c.Items.Any(x => x.Equals(T1)));
        }
Example #8
0
        public void TestRemoveBySubjectRemovesAllMatches()
        {
            var c = new TripleCollection();

            c.AddRange(new [] { T1, T2, T3, T4 });
            Assert.AreEqual(4, c.Count());
            c.RemoveBySubject("http://example.org/s");
            Assert.AreEqual(1, c.Count());
            Assert.IsTrue(c.Items.Any(x => x.Equals(T4)));
        }
Example #9
0
        public void TestEnumerateSubjects()
        {
            var c = new TripleCollection();

            c.AddRange(new[] { T1, T2, T3, T4, T5, T6 });
            var subjects = c.Subjects.ToList();

            Assert.AreEqual(2, subjects.Count);
            Assert.Contains("http://example.org/s", subjects);
            Assert.Contains("http://example.org/s1", subjects);
        }
Example #10
0
        public void TestClearRemovesAllTriples()
        {
            var c = new TripleCollection();

            c.AddRange(new[] { T1, T2, T3, T4, T5, T6 });
            var triples = c.Items.ToList();

            Assert.AreEqual(6, triples.Count);
            c.Clear();
            Assert.AreEqual(0, c.Items.Count());
            triples = c.Items.ToList();
            Assert.AreEqual(0, triples.Count);
        }
Example #11
0
        public void TestEnumerateTriples()
        {
            var c = new TripleCollection();

            c.AddRange(new[] { T1, T2, T3, T4, T5, T6 });
            var triples = c.Items.ToList();

            Assert.AreEqual(6, triples.Count);
            Assert.Contains(T1, triples);
            Assert.Contains(T2, triples);
            Assert.Contains(T3, triples);
            Assert.Contains(T4, triples);
            Assert.Contains(T5, triples);
            Assert.Contains(T6, triples);
        }