Exemple #1
0
        public void TryGetValue_rejects_missing_key()
        {
            var d = new DynamicGraph();
            var s = "urn:s";

            Assert.False(d.TryGetValue(s, out var value));
        }
Exemple #2
0
        public void Remove_pair_ignores_missing_statements()
        {
            var d = new DynamicGraph() as IDictionary <string, object>;
            var s = "urn:s";

            Assert.False(d.Remove(new KeyValuePair <string, object>(s, null)));
        }
Exemple #3
0
        public void Add_requires_subject()
        {
            var d = new DynamicGraph();

            Assert.Throws <ArgumentNullException>(() =>
                                                  d.Add(null as INode, null));
        }
Exemple #4
0
        public void Contains_rejects_missing_key()
        {
            var d = new DynamicGraph() as IDictionary <string, object>;
            var s = "urn:s";

            Assert.False(d.Contains(new KeyValuePair <string, object>(s, 0)));
        }
Exemple #5
0
        public void Remove_po_handles_public_properties()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
<urn:s2> <urn:s1> ""o3"" .
<urn:s2> <urn:p3> <urn:s1> .
");

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

            actual.LoadFromString(@"
<urn:s1> <urn:p1> ""o1"" .
<urn:s1> <urn:p2> ""o2"" .
<urn:s2> <urn:s1> ""o3"" .
<urn:s2> <urn:p3> <urn:s1> .
");

            var s1 = actual.Nodes.First();
            var predicateAndObjects = new
            {
                p1 = "o1",
                p2 = "o2"
            };

            actual.Remove(s1, predicateAndObjects);

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

            d.LoadFromString(@"
<urn:s1> <urn:p1> <urn:o01> .
<urn:s1> <urn:p1> <urn:o02> .
<urn:s1> <urn:p2> <urn:o03> .
<urn:s1> <urn:p2> <urn:o04> .
<urn:s2> <urn:p3> <urn:o05> .
<urn:s2> <urn:p3> <urn:o06> .
<urn:s2> <urn:p4> <urn:o07> .
<urn:s2> <urn:p4> <urn:o08> .
_:s3 <urn:p5> <urn:o9> .
_:s3 <urn:p5> <urn:o10> .
_:s3 <urn:p6> <urn:o11> .
_:s3 <urn:p6> <urn:o12> .
");

            Assert.Equal(d.Nodes.UriNodes(), d.Values);

            foreach (var value in d.Values)
            {
                Assert.IsType <DynamicNode>(value);
            }
        }
Exemple #7
0
        public void Contains_rejects_null_value()
        {
            var d = new DynamicGraph();
            var s = d.CreateBlankNode();

            Assert.False(d.Contains(s, null));
        }
Exemple #8
0
        public void Contains_rejects_missing_subject()
        {
            var d = new DynamicGraph();
            var s = d.CreateBlankNode();

            Assert.False(d.Contains(s, 0));
        }
Exemple #9
0
        public void Add_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> .
");

            var d = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:"));
            var s = d.CreateUriNode(UriFactory.Create("urn:s"));
            var p = d.CreateUriNode(UriFactory.Create("urn:p"));
            var o = d.CreateUriNode(UriFactory.Create("urn:o"));

            var value = new
            {
                s = new[] { s, p, o },
                p = new[] { s, p, o },
                o = new[] { s, p, o }
            };

            ((IDictionary <INode, object>)d).Add(
                new KeyValuePair <INode, object>(s, value));

            Assert.Equal <IGraph>(expected, d);
        }
Exemple #10
0
        public void Get_index_requires_subject()
        {
            var d = new DynamicGraph();

            Assert.Throws <ArgumentNullException>(() =>
                                                  d[null as INode]);
        }
Exemple #11
0
        public void Add_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> .
");

            var d = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:"));
            var s = d.CreateUriNode(UriFactory.Create("urn:s"));
            var p = d.CreateUriNode(UriFactory.Create("urn:p"));
            var o = d.CreateUriNode(UriFactory.Create("urn:o"));
            var predicateAndObjects = new Dictionary <object, object>
            {
                { "s", new[] { s, p, o } },
                { new Uri("urn:p"), new[] { s, p, o } },
                { d.CreateUriNode(new Uri("urn:o")), new[] { s, p, o } }
            };

            d.Add(s, predicateAndObjects);

            Assert.Equal <IGraph>(expected, d);
        }
Exemple #12
0
        public void Remove_po_rejects_null_predicate_and_object()
        {
            var d = new DynamicGraph();
            var s = d.CreateBlankNode();

            Assert.False(d.Remove(s, null));
        }
        public void Rejects_invalid_URIs()
        {
            var d = new DynamicGraph();

            Assert.Throws <FormatException>(() =>
                                            d["http:///"]);
        }
        public void Remove_pair_handles_public_dictionaries()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
<urn:s2> <urn:s1> ""o3"" .
<urn:s2> <urn:p3> <urn:s1> .
");

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

            actual.LoadFromString(@"
<urn:s1> <urn:p1> ""o1"" .
<urn:s1> <urn:p2> ""o2"" .
<urn:s2> <urn:s1> ""o3"" .
<urn:s2> <urn:p3> <urn:s1> .
");

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

            var value = new Dictionary <object, object>
            {
                { "p1", "o1" },
                { "p2", "o2" }
            };

            ((IDictionary <Uri, object>)actual).Remove(new KeyValuePair <Uri, object>(s1, value));

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

            expected.LoadFromString(@"
<urn:s2> <urn:s1> ""o6"" .
<urn:s2> <urn:p3> <urn:s1> .
");

            var actual = new DynamicGraph();

            actual.LoadFromString(@"
<urn:s1> <urn:p1> ""o1"" .
<urn:s1> <urn:p1> ""o2"" .
<urn:s1> <urn:p2> ""o3"" .
<urn:s1> <urn:p2> ""o4"" .
<urn:s1> <urn:p2> ""o5"" .
<urn:s2> <urn:s1> ""o6"" .
<urn:s2> <urn:p3> <urn:s1> .
");

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

            actual[s1] = null;

            Assert.Equal <IGraph>(expected, actual);
        }
        public void Contains_rejects_null_value()
        {
            var d = new DynamicGraph() as IDictionary <Uri, object>;
            var s = UriFactory.Create("urn:s");

            Assert.False(d.Contains(new KeyValuePair <Uri, object>(s, null)));
        }
        public void Remove_retracts_by_subject()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
<urn:s2> <urn:s1> ""o5"" .
<urn:s2> <urn:p3> <urn:s1> .
");

            var actual = new DynamicGraph();

            actual.LoadFromString(@"
<urn:s1> <urn:p1> ""o1"" .
<urn:s1> <urn:p1> ""o2"" .
<urn:s1> <urn:p2> ""o3"" .
<urn:s1> <urn:p2> ""o4"" .
<urn:s2> <urn:s1> ""o5"" .
<urn:s2> <urn:p3> <urn:s1> .
");

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

            actual.Remove(s1);

            Assert.Equal <IGraph>(expected, actual);
        }
        public void Set_index_overwrites_by_subject()
        {
            var expected = new Graph();

            expected.LoadFromString(@"
<urn:s1> <urn:p1> ""o"" .
<urn:s2> <urn:s1> ""o6"" .
<urn:s2> <urn:p3> <urn:s1> .
");

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

            actual.LoadFromString(@"
<urn:s1> <urn:p1> ""o1"" .
<urn:s1> <urn:p1> ""o2"" .
<urn:s1> <urn:p2> ""o3"" .
<urn:s1> <urn:p2> ""o4"" .
<urn:s1> <urn:p2> ""o5"" .
<urn:s2> <urn:s1> ""o6"" .
<urn:s2> <urn:p3> <urn:s1> .
");

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

            actual[s1] = new { p1 = "o" };

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

            Assert.Throws <ArgumentNullException>(() =>
                                                  d.Remove(null as Uri));
        }
Exemple #20
0
        public void Add_handles_public_properties()
        {
            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> .
");

            var d = new DynamicGraph(predicateBaseUri: UriFactory.Create("urn:"));
            var s = d.CreateUriNode(UriFactory.Create("urn:s"));
            var p = d.CreateUriNode(UriFactory.Create("urn:p"));
            var o = d.CreateUriNode(UriFactory.Create("urn:o"));
            var predicateAndObjects = new
            {
                s = new[] { s, p, o },
                p = new[] { s, p, o },
                o = new[] { s, p, o },
            };

            d.Add(s, predicateAndObjects);

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

            Assert.Throws <ArgumentNullException>(() =>
                                                  d.Add(null as Uri, null));
        }
        public void Set_index_requires_key()
        {
            var d = new DynamicGraph();

            Assert.Throws <ArgumentNullException>(() =>
                                                  d[null as Uri] = null);
        }
        public void Remove_pair_requires_key()
        {
            var d = new DynamicGraph() as IDictionary <Uri, object>;

            var condition = d.Remove(new KeyValuePair <Uri, object>(null, null));

            Assert.False(condition);
        }
        public void Add_requires_value()
        {
            var d = new DynamicGraph();
            var s = UriFactory.Create("urn:s");

            Assert.Throws <ArgumentNullException>(() =>
                                                  d.Add(s, null));
        }
Exemple #25
0
        public void Remove_po_rejects_missing_statements()
        {
            var d = new DynamicGraph();
            var s = d.CreateBlankNode();
            var p = d.CreateBlankNode();

            Assert.False(d.Remove(s, p));
        }
Exemple #26
0
        public void Subject_base_uri_defaults_to_graph_base_uri()
        {
            var d = new DynamicGraph();

            d.BaseUri = UriFactory.Create("urn:");

            Assert.Equal(d.BaseUri, d.SubjectBaseUri);
        }
Exemple #27
0
        public void Add_requires_value()
        {
            var d = new DynamicGraph();
            var s = d.CreateBlankNode();

            Assert.Throws <ArgumentNullException>(() =>
                                                  d.Add(s, null));
        }
        public void Remove_pair_ignores_missing_statements()
        {
            var d = new DynamicGraph() as IDictionary <Uri, object>;
            var s = UriFactory.Create("urn:s");

            var condition = d.Remove(new KeyValuePair <Uri, object>(s, null));

            Assert.False(condition);
        }
        public void Contains_rejects_missing_key()
        {
            var d = new DynamicGraph() as IDictionary <Uri, object>;
            var s = UriFactory.Create("urn:s");

            var condition = d.Contains(new KeyValuePair <Uri, object>(s, 0));

            Assert.False(condition);
        }
        public void TryGetValue_rejects_missing_key()
        {
            var d = new DynamicGraph();
            var s = UriFactory.Create("urn:s");

            var condition = d.TryGetValue(s, out var value);

            Assert.False(condition);
        }