Exemple #1
0
        public void cloneReturnsTripleStoreContainingSameStatements()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode()));
            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred2"), new PlainLiteral("foo", "jp")));
            store.Add(new Statement(new UriRef("http://example.com/the-thing"), new UriRef("http://example.com/pred3"), new TypedLiteral("1", "http://example.com/types/numeric")));
            store.Add(new Statement(new UriRef("http://example.com/other-thing"), new UriRef("http://example.com/pred4"), new UriRef("http://example.com/the-thing")));

            TripleStore clone = (TripleStore)store.Clone();

            Assert.AreEqual(store.NodeCount, clone.NodeCount);
            Assert.AreEqual(store.ResourceCount, clone.ResourceCount);


            TripleStoreVerifier verifier = new TripleStoreVerifier();

            verifier.expect("_:a <http://example.com/pred> _:b .");
            verifier.expect("_:c <http://example.com/pred2> \"foo\"@jp .");
            verifier.expect("<http://example.com/the-thing> <http://example.com/pred3> \"1\"^^<http://example.com/types/numeric> .");
            verifier.expect("<http://example.com/other-thing> <http://example.com/pred4> <http://example.com/the-thing> .");

            Assert.IsTrue(verifier.verify(clone));

            clone.Clear();
            store.Clear();
        }
Exemple #2
0
        public void AddIncrementsNodeCountOnceForSubjectAndOnceForObject()
        {
            TripleStore store = MakeTripleStoreWithOneDummyStatement();

            Assert.AreEqual(3, store.NodeCount);
            store.Clear();
        }
Exemple #3
0
        public void AddStatementIncrementsStatementCount()
        {
            TripleStore store = MakeTripleStoreWithOneDummyStatement();

            Assert.AreEqual(1, store.StatementCount);
            store.Clear();
        }
Exemple #4
0
        public void NewInstanceIsEmpty()
        {
            TripleStore store = MakeNewTripleStore();

            Assert.IsTrue(store.IsEmpty());
            store.Clear();
        }
Exemple #5
0
        public void IsEmptyIsNotTrueIfStatementAdded()
        {
            TripleStore store = MakeTripleStoreWithOneDummyStatement();

            Assert.IsFalse(store.IsEmpty());
            store.Clear();
        }
Exemple #6
0
        public void GetStatementEnumerator()
        {
            Node theSubject      = new NodeStub("http://example.com/subj");
            Arc  thePredicate    = new UriRef("http://example.com/pred");
            Node theFirstObject  = new UriRef("http://example.com/obj1");
            Node theSecondObject = new UriRef("http://example.com/obj2");

            Statement   statement1 = new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj1"));
            Statement   statement2 = new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj2"));
            TripleStore store      = MakeNewTripleStore();

            store.Add(statement1);
            store.Add(statement2);

            ResourceStatement resStatement1 = new ResourceStatement(store.GetResourceDenotedBy(statement1.GetSubject()), store.GetResourceDenotedBy(statement1.GetPredicate()), store.GetResourceDenotedBy(statement1.GetObject()));
            ResourceStatement resStatement2 = new ResourceStatement(store.GetResourceDenotedBy(statement2.GetSubject()), store.GetResourceDenotedBy(statement2.GetPredicate()), store.GetResourceDenotedBy(statement2.GetObject()));
            IEnumerator       statementEnum = store.GetStatementEnumerator();

            Assert.IsTrue(statementEnum.MoveNext(), "Enumerator has first statement");

            ResourceStatement firstStatement = (ResourceStatement)statementEnum.Current;

            Assert.IsTrue(statementEnum.MoveNext(), "Enumerator has second statement");

            ResourceStatement secondStatement = (ResourceStatement)statementEnum.Current;

            Assert.IsFalse(statementEnum.MoveNext());
            Assert.IsTrue((firstStatement.Equals(resStatement1) && secondStatement.Equals(resStatement2)) || (firstStatement.Equals(resStatement2) && secondStatement.Equals(resStatement1)), "Statements have correct components");
            store.Clear();
        }
Exemple #7
0
        public void NodeCountZeroOnCreate()
        {
            TripleStore store = MakeNewTripleStore();

            Assert.AreEqual(0, store.NodeCount);
            store.Clear();
        }
Exemple #8
0
        public void IsEmptyAfterClear()
        {
            TripleStore store = MakeTripleStoreWithOneDummyStatement();

            store.Clear();
            Assert.IsTrue(store.IsEmpty());
        }
Exemple #9
0
        public void ClearMakesNodeCountZero()
        {
            TripleStore store = MakeTripleStoreWithOneDummyStatement();

            store.Clear();
            Assert.AreEqual(0, store.NodeCount);
        }
Exemple #10
0
        public void GetStatementEnumeratorIsEmptyForNewTripleStore()
        {
            TripleStore store         = MakeNewTripleStore();
            IEnumerator statementEnum = store.GetStatementEnumerator();

            Assert.IsFalse(statementEnum.MoveNext(), "Enumerator has no first statement");
            store.Clear();
        }
Exemple #11
0
        public void GetResourceDenotedByDoesNotChangeIsEmptyFlag()
        {
            TripleStore store = MakeNewTripleStore();

            store.GetResourceDenotedBy(new UriRef("http://example.com/uri"));
            Assert.IsTrue(store.IsEmpty());
            store.Clear();
        }
Exemple #12
0
        public void ClearMakesResourceCountZero()
        {
            TripleStore store = MakeNewTripleStore();

            AddDummyTriple(store);
            store.Clear();
            Assert.AreEqual(0, store.ResourceCount);
        }
Exemple #13
0
        public void cloneReturnsObjectOfSameType()
        {
            TripleStore store = MakeNewTripleStore();
            TripleStore clone = (TripleStore)store.Clone();

            Assert.AreEqual(store.GetType(), clone.GetType());
            clone.Clear();
            store.Clear();
        }
Exemple #14
0
        public void writeCallsWriterEndOutputOnce()
        {
            RdfWriterCounter writer = new RdfWriterCounter();
            TripleStore      store  = MakeNewTripleStore();

            store.Write(writer);

            Assert.AreEqual(1, writer.EndOutputCalled);
            store.Clear();
        }
Exemple #15
0
        public void Contains()
        {
            TripleStore store = MakeNewTripleStore();


            store.Add(new Statement(new UriRef("ex:subj"), new UriRef("ex:pred"), new UriRef("ex:obj")));

            Assert.IsTrue(store.Contains(new Statement(new UriRef("ex:subj"), new UriRef("ex:pred"), new UriRef("ex:obj"))));
            store.Clear();
        }
Exemple #16
0
        public void GetStatementEnumeratorReturnsResourceStatementInstances()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj1")));

            IEnumerator statementEnum = store.GetStatementEnumerator();

            Assert.IsTrue(statementEnum.MoveNext(), "Enumerator has first statement");
            Assert.IsTrue(statementEnum.Current is ResourceStatement, "Enumerator returns a ResourceStatement");
            store.Clear();
        }
Exemple #17
0
        public void AddResourceStatementIncrementsStatementCount()
        {
            TripleStore store = MakeNewTripleStore();

            Resource subjectResource   = store.GetResourceDenotedBy(new UriRef("http://example.com/subj"));
            Resource predicateResource = store.GetResourceDenotedBy(new UriRef("http://example.com/pred"));
            Resource objectResource    = store.GetResourceDenotedBy(new UriRef("http://example.com/obj"));

            store.Add(new ResourceStatement(subjectResource, predicateResource, objectResource));
            Assert.AreEqual(1, store.StatementCount);
            store.Clear();
        }
Exemple #18
0
        public void AddDoesNotAllowDuplicates()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj")));
            store.Add(new Statement(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj")));
            TripleStoreVerifier verifier = new TripleStoreVerifier();

            verifier.expect("<http://example.com/subj> <http://example.com/pred> <http://example.com/obj> .");

            Assert.IsTrue(verifier.verify(store));
            store.Clear();
        }
Exemple #19
0
        public void AddAllowsSingleQuotesInUriRefs()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new UriRef("ex:subj"), new UriRef("ex:pred"), new UriRef("ex:fo'o")));

            TripleStoreVerifier verifier = new TripleStoreVerifier();

            verifier.expect("<ex:subj> <ex:pred> <ex:fo'o> .");

            Assert.IsTrue(verifier.verify(store));
            store.Clear();
        }
Exemple #20
0
        public void AddAllowsSingleQuotesInLiteralLanguages()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new UriRef("ex:subj"), new UriRef("ex:pred"), new PlainLiteral("darby", "f'oo")));

            TripleStoreVerifier verifier = new TripleStoreVerifier();

            verifier.expect("<ex:subj> <ex:pred> \"darby\"@f'oo .");

            Assert.IsTrue(verifier.verify(store));
            store.Clear();
        }
Exemple #21
0
        public void AddAllowsSingleQuotesInTypedLiteralValues()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new UriRef("ex:subj"), new UriRef("ex:pred"), new TypedLiteral("d'arby", "ex:foo")));

            TripleStoreVerifier verifier = new TripleStoreVerifier();

            verifier.expect("<ex:subj> <ex:pred> \"d'arby\"^^<ex:foo> .");

            Assert.IsTrue(verifier.verify(store));
            store.Clear();
        }
Exemple #22
0
        public void AddDenotationMakesResourceAccesibleViaDenotee()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj")));

            Resource originalResource = store.GetResourceDenotedBy(new UriRef("http://example.com/subj"));

            store.AddDenotation(new UriRef("foo:bar"), originalResource);

            Assert.AreEqual(originalResource, store.GetResourceDenotedBy(new UriRef("foo:bar")));
            store.Clear();
        }
Exemple #23
0
        public void GetResourceDenotedByAlwaysReturnsSameResourceForSameGraphMember()
        {
            TripleStore store = MakeNewTripleStore();

            Assert.AreEqual(store.GetResourceDenotedBy(new UriRef("http://example.com/uri")), store.GetResourceDenotedBy(new UriRef("http://example.com/uri")), "UriRef");
            Assert.AreEqual(store.GetResourceDenotedBy(new PlainLiteral("squash")), store.GetResourceDenotedBy(new PlainLiteral("squash")), "Plain literal no language");
            Assert.AreEqual(store.GetResourceDenotedBy(new PlainLiteral("squash", "de")), store.GetResourceDenotedBy(new PlainLiteral("squash", "de")), "Plain literal with language");
            Assert.AreEqual(store.GetResourceDenotedBy(new TypedLiteral("squash", "http://example.com/type")), store.GetResourceDenotedBy(new TypedLiteral("squash", "http://example.com/type")), "Typed literal");

            BlankNode blank = new BlankNode();

            Assert.AreEqual(store.GetResourceDenotedBy(blank), store.GetResourceDenotedBy(blank), "Blank node");
            store.Clear();
        }
Exemple #24
0
        public void ResourcesPropertyContainsResourceInstances()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj1")));

            IList resources = store.Resources;

            Assert.AreEqual(3, resources.Count, "Should be 3 resources");
            Assert.IsTrue(resources[0] is Resource, "First resource is an instance of Resource class");
            Assert.IsTrue(resources[1] is Resource, "First resource is an instance of Resource class");
            Assert.IsTrue(resources[2] is Resource, "First resource is an instance of Resource class");
            store.Clear();
        }
Exemple #25
0
        public void AddStatementDistinguishesDifferentBlankNodeInstancesForObjects()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new UriRef("http://example.com/subj1"), new UriRef("http://example.com/pred"), new BlankNode()));
            store.Add(new Statement(new UriRef("http://example.com/subj1"), new UriRef("http://example.com/pred"), new BlankNode()));

            TripleStoreVerifier verifier = new TripleStoreVerifier();

            verifier.expect("<http://example.com/subj1> <http://example.com/pred> _:blank1 .");
            verifier.expect("<http://example.com/subj1> <http://example.com/pred> _:blank2 .");

            Assert.IsTrue(verifier.verify(store));
            store.Clear();
        }
Exemple #26
0
        public void NodeCountAlwaysEqualsResourceCountForUnsmushedTriples()
        {
            TripleStore store = MakeNewTripleStore();

            Assert.AreEqual(store.NodeCount, store.ResourceCount);

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode()));
            Assert.AreEqual(store.NodeCount, store.ResourceCount);

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode()));
            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode()));
            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode()));
            Assert.AreEqual(store.NodeCount, store.ResourceCount);
            store.Clear();
        }
Exemple #27
0
        public void RemoveNonExistentTripleDoesNotDecreaseNodeCountOrResourceCount()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode()));

            int NodeCountBefore     = store.NodeCount;
            int ResourceCountBefore = store.ResourceCount;

            store.Remove(new ResourceStatement(new Resource(), new Resource(), new Resource()));

            Assert.IsTrue(NodeCountBefore <= store.NodeCount, "Node count should not decrease");
            Assert.IsTrue(ResourceCountBefore <= store.ResourceCount, "Resource count should not decrease");
            store.Clear();
        }
Exemple #28
0
        public void AddTripleStoreWithCommonNodes()
        {
            UriRef node1 = new  UriRef("any:node1");
            UriRef node2 = new  UriRef("any:node2");
            UriRef node3 = new  UriRef("any:node3");
            UriRef node4 = new  UriRef("any:node4");
            UriRef node5 = new  UriRef("any:node5");
            UriRef node6 = new  UriRef("any:node6");

            UriRef predicate1 = new UriRef("any:predicate1");
            UriRef predicate2 = new UriRef("any:predicate2");
            UriRef predicate3 = new UriRef("any:predicate3");

            Statement statement1 = new Statement(node1, predicate1, node2);
            Statement statement2 = new Statement(node3, predicate2, node4);
            Statement statement3 = new Statement(node5, predicate3, node6);
            Statement statement4 = new Statement(node1, predicate2, node6);

            TripleStore firstStore = MakeNewTripleStore();

            firstStore.Add(statement1);

            TripleStore secondStore = MakeNewTripleStore();

            secondStore.Add(statement2);
            secondStore.Add(statement3);
            secondStore.Add(statement4);


            firstStore.Add(secondStore);
            TripleStoreVerifier verifierFirst = new TripleStoreVerifier();

            verifierFirst.expect("<any:node1> <any:predicate1> <any:node2> .");
            verifierFirst.expect("<any:node3> <any:predicate2> <any:node4> .");
            verifierFirst.expect("<any:node5> <any:predicate3> <any:node6> .");
            verifierFirst.expect("<any:node1> <any:predicate2> <any:node6> .");
            Assert.IsTrue(verifierFirst.verify(firstStore), "first knowledge base includes triples from second");

            TripleStoreVerifier verifierSecond = new TripleStoreVerifier();

            verifierSecond.expect("<any:node3> <any:predicate2> <any:node4> .");
            verifierSecond.expect("<any:node5> <any:predicate3> <any:node6> .");
            verifierSecond.expect("<any:node1> <any:predicate2> <any:node6> .");

            Assert.IsTrue(verifierSecond.verify(secondStore), "second knowledge base is unchanged");
            firstStore.Clear();
            secondStore.Clear();
        }
Exemple #29
0
        public void CloneReturnsIndependentTripleStore()
        {
            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode()));

            TripleStore clone = (TripleStore)store.Clone();
            int         cloneNodeCountBefore     = clone.NodeCount;
            int         cloneResourceCountBefore = clone.ResourceCount;

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode()));
            Assert.AreEqual(cloneNodeCountBefore, clone.NodeCount, "Clone node count is unchanged");
            Assert.AreEqual(cloneResourceCountBefore, clone.ResourceCount, "Clone resource count is unchanged");

            store.Clear();
            Assert.AreEqual(cloneNodeCountBefore, clone.NodeCount, "Clone node count is unchanged after Clearing original");
            Assert.AreEqual(cloneResourceCountBefore, clone.ResourceCount, "Clone resource count is unchanged after Clearing original");
        }
Exemple #30
0
        public void AddDistinguishesDifferentBlankNodeInstances()
        {
            Node theSubject      = new NodeStub("http://example.com/subj");
            Arc  thePredicate    = new UriRef("http://example.com/pred");
            Node theFirstObject  = new UriRef("http://example.com/obj1");
            Node theSecondObject = new UriRef("http://example.com/obj2");

            TripleStore store = MakeNewTripleStore();

            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj1")));
            store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj2")));

            TripleStoreVerifier verifier = new TripleStoreVerifier();

            verifier.expect("_:node1 <http://example.com/pred> <http://example.com/obj1> .");
            verifier.expect("_:node2 <http://example.com/pred> <http://example.com/obj2> .");

            Assert.IsTrue(verifier.verify(store));
            store.Clear();
        }