Exemple #1
0
        public void TryGetValue_returns_dynamic_subject()
        {
            var d = new DynamicGraph();

            d.LoadFromString("<urn:s> <urn:p> <urn:o> .");

            var s = "urn:s";

            Assert.True(d.TryGetValue(s, out var value));
            Assert.Equal(value, d.CreateUriNode(UriFactory.Create(s)));
            Assert.IsType <DynamicNode>(value);
        }
        public void Ignores_URIs_for_QName_parsing()
        {
            var d = new DynamicGraph();

            d.LoadFromString(@"
<http://example.com/s> <http://example.com/p> <http://example.com/o> .
");

            var s = d.CreateUriNode(UriFactory.Create("http://example.com/s"));

            Assert.Equal(s, d["http://example.com/s"]);
        }
        public void Ignores_URNs_for_QName_parsing()
        {
            var d = new DynamicGraph();

            d.LoadFromString(@"
<urn:s> <urn:p> <urn:o> .
");

            var s = d.CreateUriNode(UriFactory.Create("urn:s"));

            Assert.Equal(s, d["urn:s"]);
        }
        public void Enumerates_pairs_with_subject_key_and_dynamic_subject_value()
        {
            var g = new DynamicGraph();

            g.LoadFromString(@"
<urn:s> <urn:s> <urn:s> . # 1 (subject)
<urn:s> <urn:s> <urn:p> .
<urn:s> <urn:s> <urn:o> .
<urn:s> <urn:p> <urn:s> .
<urn:s> <urn:p> <urn:p> .
<urn:s> <urn:p> <urn:o> .
<urn:s> <urn:o> <urn:s> .
<urn:s> <urn:o> <urn:p> .
<urn:s> <urn:o> <urn:o> .
<urn:p> <urn:s> <urn:s> . # 2 (subject)
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> . # 3 (subject)
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var s = UriFactory.Create("urn:s");
            var p = UriFactory.Create("urn:p");
            var o = UriFactory.Create("urn:o");

            using (var actual = g.Cast <KeyValuePair <Uri, object> >().GetEnumerator())
            {
                using (var expected = new[] { s, p, o }.Cast <Uri>().GetEnumerator())
                {
                    while (expected.MoveNext() | actual.MoveNext())
                    {
                        var keyNode = g.CreateUriNode(expected.Current);

                        Assert.Equal(new KeyValuePair <Uri, object>(expected.Current, keyNode), actual.Current);
                        Assert.IsType <DynamicNode>(actual.Current.Value);
                    }
                }
            }
        }
        public void Rejects_relative_URI_without_base()
        {
            var d = new DynamicGraph();

            d.LoadFromString(@"
<urn:s> <urn:p> <urn:o> .
");

            var s = d.CreateUriNode(UriFactory.Create("urn:s"));

            Assert.Throws <InvalidOperationException>(() =>
                                                      Assert.Equal(s, d["/s"]));
        }
Exemple #6
0
        public void Get_index_returns_dynamic_subject()
        {
            var d = new DynamicGraph();

            d.LoadFromString(@"
<urn:s> <urn:p> <urn:o> .
");

            var s = d.CreateUriNode(UriFactory.Create("urn:s"));

            Assert.Equal(s, d[s]);
            Assert.IsType <DynamicNode>(d[s]);
        }
Exemple #7
0
        public void Handles_get_member()
        {
            var g = new DynamicGraph(subjectBaseUri: new Uri("urn:"));

            g.LoadFromString(@"
<urn:s> <urn:p> <urn:o> .
");

            var     s = g.CreateUriNode(UriFactory.Create("urn:s"));
            dynamic d = g;

            Assert.Equal(s, d.s);
        }
        public void Expands_slash_URI_base()
        {
            var d = new DynamicGraph {
                BaseUri = UriFactory.Create("http://example.com/")
            };

            d.LoadFromString(@"
<http://example.com/s> <http://example.com/p> <http://example.com/o> .
");

            var s = d.CreateUriNode(UriFactory.Create("http://example.com/s"));

            Assert.Equal(s, d["s"]);
        }
        public void Expands_QNames()
        {
            var d = new DynamicGraph();

            d.LoadFromString(@"
@prefix u: <urn:> .

u:s u:p u:o .
");

            var s = d.CreateUriNode("u:s");

            Assert.Equal(s, d["u:s"]);
        }
        public void Get_index_returns_dynamic_subject()
        {
            var d = new DynamicGraph();

            d.LoadFromString("<urn:s> <urn:p> <urn:o> .");

            var s = UriFactory.Create("urn:s");

            var expected = d.CreateUriNode(s);
            var actual   = d[s];

            Assert.Equal(expected, actual);
            Assert.IsType <DynamicNode>(actual);
        }
Exemple #11
0
        public void Contains_fails_unknown_key_type()
        {
            var g = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:"));

            g.LoadFromString(@"
<urn:s> <urn:p> <urn:o> .
");
            var s = g.CreateUriNode(UriFactory.Create("urn:s"));
            var predicateAndObjects = new Dictionary <object, object>
            {
                { 0, "o" }
            };

            Assert.Throws <InvalidOperationException>(() =>
                                                      g.Contains(s, predicateAndObjects));
        }
Exemple #12
0
        public void Handles_set_member()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
<urn:s> <urn:p> ""o"" .
");

            var g = new DynamicGraph(subjectBaseUri: new Uri("urn:"));

            g.LoadFromString(@"
<urn:s> <urn:p> <urn:o> .
");

            var     s = g.CreateUriNode(UriFactory.Create("urn:s"));
            dynamic d = g;

            d.s = new { p = "o" };

            Assert.Equal <IGraph>(expected, g);
        }
Exemple #13
0
        public void Set_index_overwrites_by_subject()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
<urn:s> <urn:s> ""s"" .
<urn:s> <urn:s> ""p"" .
<urn:s> <urn:s> ""o"" .
<urn:s> <urn:p> ""s"" .
<urn:s> <urn:p> ""p"" .
<urn:s> <urn:p> ""o"" .
<urn:s> <urn:o> ""s"" .
<urn:s> <urn:o> ""p"" .
<urn:s> <urn:o> ""o"" .
<urn:p> <urn:s> <urn:s> .
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> .
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var d = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:"));

            d.LoadFromString(@"
<urn:s> <urn:s> <urn:s> .
<urn:s> <urn:s> <urn:p> .
<urn:s> <urn:s> <urn:o> .
<urn:s> <urn:p> <urn:s> .
<urn:s> <urn:p> <urn:p> .
<urn:s> <urn:p> <urn:o> .
<urn:s> <urn:o> <urn:s> .
<urn:s> <urn:o> <urn:p> .
<urn:s> <urn:o> <urn:o> .
<urn:p> <urn:s> <urn:s> .
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> .
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var s = d.CreateUriNode(UriFactory.Create("urn:s"));

            d[s] = new
            {
                s = new[] { "s", "p", "o" },
                p = new[] { "s", "p", "o" },
                o = new[] { "s", "p", "o" },
            };

            Assert.Equal <IGraph>(expected, d);
        }
        public void Copies_pairs_with_subject_key_and_dynamic_subject_value()
        {
            var g = new DynamicGraph();

            g.LoadFromString(@"
<urn:s> <urn:s> <urn:s> . # 1 (subject)
<urn:s> <urn:s> <urn:p> .
<urn:s> <urn:s> <urn:o> .
<urn:s> <urn:p> <urn:s> .
<urn:s> <urn:p> <urn:p> .
<urn:s> <urn:p> <urn:o> .
<urn:s> <urn:o> <urn:s> .
<urn:s> <urn:o> <urn:p> .
<urn:s> <urn:o> <urn:o> .
<urn:p> <urn:s> <urn:s> . # 2 (subject)
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> . # 3 (subject)
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var s = UriFactory.Create("urn:s");
            var p = UriFactory.Create("urn:p");
            var o = UriFactory.Create("urn:o");

            var array = new KeyValuePair <Uri, object> [5];

            void isEmpty(KeyValuePair <Uri, object> expected)
            {
                Assert.Equal(default(KeyValuePair <Uri, object>), expected);
            }

            Action <KeyValuePair <Uri, object> > isKVWith(Uri expectedKey)
            {
                return(actual =>
                {
                    var expectedNode = g.CreateUriNode(expectedKey);

                    Assert.Equal(new KeyValuePair <Uri, object>(expectedKey, expectedNode), actual);
                    Assert.IsType <DynamicNode>(actual.Value);
                });
            }

            (g as IDictionary <Uri, object>).CopyTo(array, 1);

            Assert.Collection(
                array,
                isEmpty,
                isKVWith(s),
                isKVWith(p),
                isKVWith(o),
                isEmpty);
        }
Exemple #15
0
        public void Remove_po_handles_pairs()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
<urn:s> <urn:s> <urn:s> .
<urn:s> <urn:s> <urn:p> .
<urn:s> <urn:s> <urn:o> .
<urn:s> <urn:p> <urn:s> .
<urn:s> <urn:p> <urn:p> .
# <urn:s> <urn:p> <urn:o> .
<urn:s> <urn:o> <urn:s> .
<urn:s> <urn:o> <urn:p> .
<urn:s> <urn:o> <urn:o> .
<urn:p> <urn:s> <urn:s> .
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> .
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var g = new DynamicGraph(predicateBaseUri: new Uri("urn:"));

            g.LoadFromString(@"
<urn:s> <urn:s> <urn:s> .
<urn:s> <urn:s> <urn:p> .
<urn:s> <urn:s> <urn:o> .
<urn:s> <urn:p> <urn:s> .
<urn:s> <urn:p> <urn:p> .
<urn:s> <urn:p> <urn:o> . # should retract
<urn:s> <urn:o> <urn:s> .
<urn:s> <urn:o> <urn:p> .
<urn:s> <urn:o> <urn:o> .
<urn:p> <urn:s> <urn:s> .
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> .
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var s = g.CreateUriNode(UriFactory.Create("urn:s"));
            var p = g.CreateUriNode(UriFactory.Create("urn:p"));
            var o = g.CreateUriNode(UriFactory.Create("urn:o"));
            var d = (IDictionary <INode, object>)g;

            d.Remove(new KeyValuePair <INode, object>(s, new { p = o }));

            Assert.Equal <IGraph>(expected, g);
        }
Exemple #16
0
        public void Remove_po_handles_dictionaries()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
# <urn:s> <urn:s> <urn:s> .
<urn:s> <urn:s> <urn:p> .
<urn:s> <urn:s> <urn:o> .
<urn:s> <urn:p> <urn:s> .
# <urn:s> <urn:p> <urn:p> .
<urn:s> <urn:p> <urn:o> .
<urn:s> <urn:o> <urn:s> .
<urn:s> <urn:o> <urn:p> .
# <urn:s> <urn:o> <urn:o> .
<urn:p> <urn:s> <urn:s> .
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> .
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var actual = new DynamicGraph();

            actual.LoadFromString(@"
<urn:s> <urn:s> <urn:s> . # should retract
<urn:s> <urn:s> <urn:p> .
<urn:s> <urn:s> <urn:o> .
<urn:s> <urn:p> <urn:s> .
<urn:s> <urn:p> <urn:p> . # should retract
<urn:s> <urn:p> <urn:o> .
<urn:s> <urn:o> <urn:s> .
<urn:s> <urn:o> <urn:p> .
<urn:s> <urn:o> <urn:o> . # should retract
<urn:p> <urn:s> <urn:s> .
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> .
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var s = actual.CreateUriNode(UriFactory.Create("urn:s"));
            var p = actual.CreateUriNode(UriFactory.Create("urn:p"));
            var o = actual.CreateUriNode(UriFactory.Create("urn:o"));
            var predicateAndObjects = new Dictionary <object, object>
            {
                { s, s },
                { p.Uri, p },
                { o.Uri.AbsoluteUri, o }
            };

            actual.Remove(s, predicateAndObjects);

            Assert.Equal <IGraph>(expected, actual);
        }
Exemple #17
0
        public void Set_index_with_null_value_retracts_by_subject()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
# <urn:s> <urn:s> <urn:s> .
# <urn:s> <urn:s> <urn:p> .
# <urn:s> <urn:s> <urn:o> .
# <urn:s> <urn:p> <urn:s> .
# <urn:s> <urn:p> <urn:p> .
# <urn:s> <urn:p> <urn:o> .
# <urn:s> <urn:o> <urn:s> .
# <urn:s> <urn:o> <urn:p> .
# <urn:s> <urn:o> <urn:o> .
<urn:p> <urn:s> <urn:s> .
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> .
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var d = new DynamicGraph();

            d.LoadFromString(@"
<urn:s> <urn:s> <urn:s> . # should retract
<urn:s> <urn:s> <urn:p> . # should retract
<urn:s> <urn:s> <urn:o> . # should retract
<urn:s> <urn:p> <urn:s> . # should retract
<urn:s> <urn:p> <urn:p> . # should retract
<urn:s> <urn:p> <urn:o> . # should retract
<urn:s> <urn:o> <urn:s> . # should retract
<urn:s> <urn:o> <urn:p> . # should retract
<urn:s> <urn:o> <urn:o> . # should retract
<urn:p> <urn:s> <urn:s> .
<urn:p> <urn:s> <urn:p> .
<urn:p> <urn:s> <urn:o> .
<urn:p> <urn:p> <urn:s> .
<urn:p> <urn:p> <urn:p> .
<urn:p> <urn:p> <urn:o> .
<urn:p> <urn:o> <urn:s> .
<urn:p> <urn:o> <urn:p> .
<urn:p> <urn:o> <urn:o> .
<urn:o> <urn:s> <urn:s> .
<urn:o> <urn:s> <urn:p> .
<urn:o> <urn:s> <urn:o> .
<urn:o> <urn:p> <urn:s> .
<urn:o> <urn:p> <urn:p> .
<urn:o> <urn:p> <urn:o> .
<urn:o> <urn:o> <urn:s> .
<urn:o> <urn:o> <urn:p> .
<urn:o> <urn:o> <urn:o> .
");

            var s = d.CreateUriNode(UriFactory.Create("urn:s"));

            d[s] = null;

            Assert.Equal <IGraph>(expected, d);
        }